chiark / gitweb /
Reading config now also checks its assigned bins and dirs
authorDaniel Martí <mvdan@mvdan.cc>
Fri, 6 Dec 2013 11:55:56 +0000 (12:55 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 6 Dec 2013 11:55:56 +0000 (12:55 +0100)
fdroidserver/common.py

index 629d6d6fca81ee813bd29b76bec1e26f0c4cc5a1..73c0730e5321f87c02f82d08118772f9bd8de0db 100644 (file)
@@ -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):