mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-17 18:50:11 +02:00
Move requests code out of common.py, closes #114
This commit is contained in:
parent
3bc0d43786
commit
04e6f2ebfd
@ -34,6 +34,7 @@ from distutils.version import LooseVersion
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import common
|
import common
|
||||||
|
import net
|
||||||
import metadata
|
import metadata
|
||||||
import scanner
|
import scanner
|
||||||
from common import FDroidException, BuildException, VCSException, FDroidPopen, SdkToolsPopen
|
from common import FDroidException, BuildException, VCSException, FDroidPopen, SdkToolsPopen
|
||||||
@ -1093,7 +1094,7 @@ def main():
|
|||||||
logging.info("...retrieving " + url)
|
logging.info("...retrieving " + url)
|
||||||
of = "{0}_{1}.apk.binary".format(app['id'], thisbuild['vercode'])
|
of = "{0}_{1}.apk.binary".format(app['id'], thisbuild['vercode'])
|
||||||
of = os.path.join(output_dir, of)
|
of = os.path.join(output_dir, of)
|
||||||
common.download_file(url, local_filename=of)
|
net.download_file(url, local_filename=of)
|
||||||
|
|
||||||
build_succeeded.append(app)
|
build_succeeded.append(app)
|
||||||
wikilog = "Build succeeded"
|
wikilog = "Build succeeded"
|
||||||
|
@ -17,12 +17,14 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# common.py is imported by all modules, so do not import third-party
|
||||||
|
# libraries here as they will become a requirement for all commands.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import glob
|
import glob
|
||||||
import requests
|
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
@ -1916,20 +1918,6 @@ def string_is_integer(string):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def download_file(url, local_filename=None, dldir='tmp'):
|
|
||||||
filename = url.split('/')[-1]
|
|
||||||
if local_filename is None:
|
|
||||||
local_filename = os.path.join(dldir, filename)
|
|
||||||
# the stream=True parameter keeps memory usage low
|
|
||||||
r = requests.get(url, stream=True)
|
|
||||||
with open(local_filename, 'wb') as f:
|
|
||||||
for chunk in r.iter_content(chunk_size=1024):
|
|
||||||
if chunk: # filter out keep-alive new chunks
|
|
||||||
f.write(chunk)
|
|
||||||
f.flush()
|
|
||||||
return local_filename
|
|
||||||
|
|
||||||
|
|
||||||
def get_per_app_repos():
|
def get_per_app_repos():
|
||||||
'''per-app repos are dirs named with the packageName of a single app'''
|
'''per-app repos are dirs named with the packageName of a single app'''
|
||||||
|
|
||||||
|
35
fdroidserver/net.py
Normal file
35
fdroidserver/net.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# net.py - part of the FDroid server tools
|
||||||
|
# Copyright (C) 2015 Hans-Christoph Steiner <hans@eds.org>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(url, local_filename=None, dldir='tmp'):
|
||||||
|
filename = url.split('/')[-1]
|
||||||
|
if local_filename is None:
|
||||||
|
local_filename = os.path.join(dldir, filename)
|
||||||
|
# the stream=True parameter keeps memory usage low
|
||||||
|
r = requests.get(url, stream=True)
|
||||||
|
with open(local_filename, 'wb') as f:
|
||||||
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
|
if chunk: # filter out keep-alive new chunks
|
||||||
|
f.write(chunk)
|
||||||
|
f.flush()
|
||||||
|
return local_filename
|
@ -24,6 +24,7 @@ from optparse import OptionParser
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import common
|
import common
|
||||||
|
import net
|
||||||
from common import FDroidException
|
from common import FDroidException
|
||||||
|
|
||||||
options = None
|
options = None
|
||||||
@ -78,7 +79,7 @@ def main():
|
|||||||
os.remove(remoteapk)
|
os.remove(remoteapk)
|
||||||
url = 'https://f-droid.org/repo/' + apkfilename
|
url = 'https://f-droid.org/repo/' + apkfilename
|
||||||
logging.info("...retrieving " + url)
|
logging.info("...retrieving " + url)
|
||||||
common.download_file(url, dldir=tmp_dir)
|
net.download_file(url, dldir=tmp_dir)
|
||||||
|
|
||||||
compare_result = common.compare_apks(
|
compare_result = common.compare_apks(
|
||||||
os.path.join(unsigned_dir, apkfilename),
|
os.path.join(unsigned_dir, apkfilename),
|
||||||
|
Loading…
Reference in New Issue
Block a user