chiark / gitweb /
set_command_in_config() for finding CLI tools to run
authorHans-Christoph Steiner <hans@eds.org>
Mon, 9 Jan 2017 14:21:05 +0000 (15:21 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 22 Mar 2017 09:51:12 +0000 (10:51 +0100)
fdroidserver/common.py

index cf43769f198fd8a594b991357b68a5898a681c2c..c765e0050dc78f8a40b8fd8759edd360bf463d20 100644 (file)
@@ -2076,12 +2076,7 @@ def compare_apks(apk1, apk2, tmp_dir):
     absapk1 = os.path.abspath(apk1)
     absapk2 = os.path.abspath(apk2)
 
-    # try to find diffoscope in the path, if it hasn't been manually configed
-    if 'diffoscope' not in config:
-        tmp = find_command('diffoscope')
-        if tmp is not None:
-            config['diffoscope'] = tmp
-    if 'diffoscope' in config:
+    if set_command_in_config('diffoscope'):
         htmlfile = absapk1 + '.diffoscope.html'
         textfile = absapk1 + '.diffoscope.txt'
         if subprocess.call([config['diffoscope'],
@@ -2107,12 +2102,7 @@ def compare_apks(apk1, apk2, tmp_dir):
                        cwd=os.path.join(apk2dir, 'jar-xf')) != 0:
         return("Failed to unpack " + apk2)
 
-    # try to find apktool in the path, if it hasn't been manually configed
-    if 'apktool' not in config:
-        tmp = find_command('apktool')
-        if tmp is not None:
-            config['apktool'] = tmp
-    if 'apktool' in config:
+    if set_command_in_config('apktool'):
         if subprocess.call([config['apktool'], 'd', os.path.abspath(apk1), '--output', 'apktool'],
                            cwd=apk1dir) != 0:
             return("Failed to unpack " + apk1)
@@ -2136,6 +2126,22 @@ def compare_apks(apk1, apk2, tmp_dir):
     return None
 
 
+def set_command_in_config(command):
+    '''Try to find specified command in the path, if it hasn't been
+    manually set in config.py.  If found, it is added to the config
+    dict.  The return value says whether the command is available.
+
+    '''
+    if command in config:
+        return True
+    else:
+        tmp = find_command(command)
+        if tmp is not None:
+            config[command] = tmp
+            return True
+    return False
+
+
 def find_command(command):
     '''find the full path of a command, or None if it can't be found in the PATH'''