From 9a2a0efa4125415645711c4f1661c37906807ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 6 Dec 2013 12:55:56 +0100 Subject: [PATCH] Reading config now also checks its assigned bins and dirs --- fdroidserver/common.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 629d6d6f..73c0730e 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -26,6 +26,7 @@ import operator import Queue import threading import magic +from distutils.spawn import find_executable import metadata @@ -45,6 +46,7 @@ def read_config(opts, config_file='config.py'): if not os.path.isfile(config_file): print "Missing config file - is this a repo directory?" sys.exit(2) + st = os.stat(config_file) if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO: print "WARNING: unsafe permissions on {0} (should be 0600)!".format(config_file) @@ -67,11 +69,35 @@ def read_config(opts, config_file='config.py'): if options.verbose: print "Reading %s..." % config_file execfile(config_file, config) + + # Expand environment variables for k, v in config.items(): if type(v) != str: continue if v[0] == '$': config[k] = os.environ[v[1:]] + + # Check that commands and binaries do exist + for key in ('mvn3', 'gradle'): + if key not in config: + print "WARNING: %s not set in config" % key + val = config[key] + executable = find_executable(val) + if not executable: + print "ERROR: No such command or binary for %s: %s" % (key, val) + sys.exit(3) + + # Check that directories exist + for key in ('sdk_path', 'ndk_path', 'build_tools'): + if key not in config: + print "WARNING: %s not set in config" % key + val = config[key] + if key == 'build_tools': + val = os.path.join(config['sdk_path'], 'build-tools', val) + if not os.path.isdir(val): + print "ERROR: No such directory found for %s: %s" % (key, val) + sys.exit(3) + return config def getapkname(app, build):