chiark / gitweb /
run all SDK tools commands using SdkToolsPopen
authorHans-Christoph Steiner <hans@eds.org>
Tue, 9 Dec 2014 14:15:36 +0000 (15:15 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Sun, 14 Dec 2014 12:25:20 +0000 (13:25 +0100)
fdroidserver/common.py
fdroidserver/install.py
fdroidserver/publish.py
tests/install.TestCase [new file with mode: 0755]
tests/run-tests

index 8c87dd3f51c8dddf6bbd32e0e297caa1ea6a7292..81233c406c99fca9255a03e5a725c1e03282e281 100644 (file)
@@ -130,32 +130,6 @@ def read_config(opts, config_file='config.py'):
 
     fill_config_defaults(config)
 
-    bin_paths = {
-        'aapt': [
-            os.path.join(config['sdk_path'], 'build-tools', config['build_tools'], 'aapt'),
-            ],
-        'zipalign': [
-            os.path.join(config['sdk_path'], 'tools', 'zipalign'),
-            os.path.join(config['sdk_path'], 'build-tools', config['build_tools'], 'zipalign'),
-            ],
-        'android': [
-            os.path.join(config['sdk_path'], 'tools', 'android'),
-            ],
-        'adb': [
-            os.path.join(config['sdk_path'], 'platform-tools', 'adb'),
-            ],
-        }
-
-    for b, paths in bin_paths.items():
-        config[b] = None
-        for path in paths:
-            if os.path.isfile(path):
-                config[b] = path
-                break
-        if config[b] is None:
-            logging.warn("Could not find %s in any of the following paths:\n%s" % (
-                b, '\n'.join(paths)))
-
     # There is no standard, so just set up the most common environment
     # variables
     env = os.environ
@@ -1378,8 +1352,8 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
 
     # Generate (or update) the ant build file, build.xml...
     if build['update'] and build['update'] != ['no'] and build['type'] == 'ant':
-        parms = [config['android'], 'update', 'lib-project']
-        lparms = [config['android'], 'update', 'project']
+        parms = ['android', 'update', 'lib-project']
+        lparms = ['android', 'update', 'project']
 
         if build['target']:
             parms += ['-t', build['target']]
@@ -1397,7 +1371,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
             else:
                 logging.debug("Updating subproject %s" % d)
                 cmd = lparms + ['-p', d]
-            p = FDroidPopen(cmd, cwd=root_dir)
+            p = SdkToolsPopen(cmd, cwd=root_dir)
             # Check to see whether an error was returned without a proper exit
             # code (this is the case for the 'no target set or target invalid'
             # error)
index f6862e5a17703d83e14bc67f01244244722d9bef..a5cb98adf17c0fa0cb63cb222be171e4c325c9b3 100644 (file)
@@ -25,14 +25,14 @@ from optparse import OptionParser, OptionError
 import logging
 
 import common
-from common import FDroidPopen, FDroidException
+from common import SdkToolsPopen, FDroidException
 
 options = None
 config = None
 
 
 def devices():
-    p = FDroidPopen([config['adb'], "devices"])
+    p = SdkToolsPopen(['adb', "devices"])
     if p.returncode != 0:
         raise FDroidException("An error occured when finding devices: %s" % p.output)
     lines = p.output.splitlines()
@@ -103,7 +103,7 @@ def main():
         logging.info("Installing %s..." % apk)
         for dev in devs:
             logging.info("Installing %s on %s..." % (apk, dev))
-            p = FDroidPopen([config['adb'], "-s", dev, "install", apk])
+            p = SdkToolsPopen(['adb', "-s", dev, "install", apk])
             fail = ""
             for line in p.output.splitlines():
                 if line.startswith("Failure"):
index 39f601c4f057ccc14fac25f5b4b51a8f996b5ee1..48d0503ef43d756b1d54fba499fa38b03b0ad9f8 100644 (file)
@@ -28,7 +28,7 @@ import logging
 
 import common
 import metadata
-from common import FDroidPopen, BuildException
+from common import FDroidPopen, SdkToolsPopen, BuildException
 
 config = None
 options = None
@@ -213,8 +213,8 @@ def main():
                 raise BuildException("Failed to sign application")
 
             # Zipalign it...
-            p = FDroidPopen([config['zipalign'], '-v', '4', apkfile,
-                             os.path.join(output_dir, apkfilename)])
+            p = SdkToolsPopen(['zipalign', '-v', '4', apkfile,
+                               os.path.join(output_dir, apkfilename)])
             if p.returncode != 0:
                 raise BuildException("Failed to align application")
             os.remove(apkfile)
diff --git a/tests/install.TestCase b/tests/install.TestCase
new file mode 100755 (executable)
index 0000000..fcedb95
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
+
+import inspect
+import optparse
+import os
+import sys
+import unittest
+
+localmodule = os.path.realpath(os.path.join(
+        os.path.dirname(inspect.getfile(inspect.currentframe())),
+        '..'))
+print('localmodule: ' + localmodule)
+if localmodule not in sys.path:
+    sys.path.insert(0,localmodule)
+
+import fdroidserver.common
+import fdroidserver.install
+
+class InstallTest(unittest.TestCase):
+    '''fdroidserver/install.py'''
+
+    def test_devices(self):
+        config = dict()
+        config['sdk_path'] = os.getenv('ANDROID_HOME')
+        fdroidserver.common.config = config
+        config['adb'] = fdroidserver.common.find_sdk_tools_cmd('adb')
+        self.assertTrue(os.path.exists(config['adb']))
+        self.assertTrue(os.path.isfile(config['adb']))
+        devices = fdroidserver.install.devices()
+        self.assertIsInstance(devices, list, 'install.devices() did not return a list!')
+        for device in devices:
+            self.assertIsInstance(device, basestring)
+
+
+if __name__ == "__main__":
+    parser = optparse.OptionParser()
+    parser.add_option("-v", "--verbose", action="store_true", default=False,
+                      help="Spew out even more information than normal")
+    (fdroidserver.install.options, args) = parser.parse_args(['--verbose'])
+
+    newSuite = unittest.TestSuite()
+    newSuite.addTest(unittest.makeSuite(InstallTest))
+    unittest.main()
index 3ea444376432668745152a5db858fc3572cb4740..d1f988fa64a3f5ef6e0983c272fb6162be80838b 100755 (executable)
@@ -97,9 +97,9 @@ echo_header "test python getsig replacement"
 
 cd $WORKSPACE/tests/getsig
 ./make.sh
-cd $WORKSPACE/tests
-./common.TestCase
-./update.TestCase
+for testcase in $WORKSPACE/tests/*.TestCase; do
+    $testcase
+done
 
 
 #------------------------------------------------------------------------------#