1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-14 11:00:10 +01:00

set_command_in_config() for finding CLI tools to run

This commit is contained in:
Hans-Christoph Steiner 2017-01-09 15:21:05 +01:00
parent 70915a7445
commit ffd490d8da

View 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'''