chiark / gitweb /
Move requests code out of common.py, closes #114
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 1 Sep 2015 00:05:08 +0000 (17:05 -0700)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 1 Sep 2015 00:05:08 +0000 (17:05 -0700)
fdroidserver/build.py
fdroidserver/common.py
fdroidserver/net.py [new file with mode: 0644]
fdroidserver/verify.py

index dbae089a803c9caece1c9b8531159a5a74ab6dc4..be93410814aa303f85301114a839d50f99c76d9e 100644 (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"
index 6347d24f02129b56f08718b2d51e733931c95489..d3c7f176fde191567f8512bc26bcdaea1de244b7 100644 (file)
 # 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'''
 
diff --git a/fdroidserver/net.py b/fdroidserver/net.py
new file mode 100644 (file)
index 0000000..42d7567
--- /dev/null
@@ -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
index fd0464ebddf78c2ca7107e857bd0b18a23463902..b751c4996aa97b126475a7fbf559000663a6d503 100644 (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),