1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-08-17 20:00:10 +02:00

Move requests code out of common.py, closes #114

This commit is contained in:
Daniel Martí 2015-08-31 17:05:08 -07:00
parent 3bc0d43786
commit 04e6f2ebfd
4 changed files with 42 additions and 17 deletions

View File

@ -34,6 +34,7 @@ from distutils.version import LooseVersion
import logging
import common
import net
import metadata
import scanner
from common import FDroidException, BuildException, VCSException, FDroidPopen, SdkToolsPopen
@ -1093,7 +1094,7 @@ def main():
logging.info("...retrieving " + url)
of = "{0}_{1}.apk.binary".format(app['id'], thisbuild['vercode'])
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)
wikilog = "Build succeeded"

View File

@ -17,12 +17,14 @@
# 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/>.
# 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 sys
import re
import shutil
import glob
import requests
import stat
import subprocess
import time
@ -1916,20 +1918,6 @@ def string_is_integer(string):
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():
'''per-app repos are dirs named with the packageName of a single app'''

35
fdroidserver/net.py Normal file
View 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

View File

@ -24,6 +24,7 @@ from optparse import OptionParser
import logging
import common
import net
from common import FDroidException
options = None
@ -78,7 +79,7 @@ def main():
os.remove(remoteapk)
url = 'https://f-droid.org/repo/' + apkfilename
logging.info("...retrieving " + url)
common.download_file(url, dldir=tmp_dir)
net.download_file(url, dldir=tmp_dir)
compare_result = common.compare_apks(
os.path.join(unsigned_dir, apkfilename),