chiark / gitweb /
init: split out defconfig and sdk test to run before config is loaded
authorHans-Christoph Steiner <hans@eds.org>
Wed, 23 Apr 2014 16:44:37 +0000 (12:44 -0400)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 23 Apr 2014 23:32:04 +0000 (19:32 -0400)
`fdroid init` runs before any config.py exists, but it still needs to have
the default config and the SDK path tests.  So split those two bits out of
common.read_config() so that they can be run separately before config.py
is in place.

fdroidserver/common.py
fdroidserver/init.py

index f9db5506dd3229bdba9b0cb9321af2fb6ef79901..0c1d7dd3976f733c6dc3a866e23470df8200e5e3 100644 (file)
@@ -34,6 +34,28 @@ import metadata
 config = None
 options = None
 
+def get_default_config():
+    return {
+        'sdk_path': os.getenv("ANDROID_HOME"),
+        'ndk_path': "$ANDROID_NDK",
+        'build_tools': "19.0.3",
+        'ant': "ant",
+        'mvn3': "mvn",
+        'gradle': 'gradle',
+        'archive_older': 0,
+        'update_stats': False,
+        'stats_to_carbon': False,
+        'repo_maxage': 0,
+        'build_server_always': False,
+        'keystore': '$HOME/.local/share/fdroidserver/keystore.jks',
+        'smartcardoptions': [],
+        'char_limits': {
+            'Summary' : 50,
+            'Description' : 1500
+        },
+        'keyaliases': { },
+    }
+
 def read_config(opts, config_file='config.py'):
     """Read the repository config
 
@@ -65,26 +87,7 @@ def read_config(opts, config_file='config.py'):
                                       'sun.security.pkcs11.SunPKCS11',
                                       '-providerArg', 'opensc-fdroid.cfg']
 
-    defconfig = {
-        'sdk_path': "$ANDROID_HOME",
-        'ndk_path': "$ANDROID_NDK",
-        'build_tools': "19.0.3",
-        'ant': "ant",
-        'mvn3': "mvn",
-        'gradle': 'gradle',
-        'archive_older': 0,
-        'update_stats': False,
-        'stats_to_carbon': False,
-        'repo_maxage': 0,
-        'build_server_always': False,
-        'keystore': '$HOME/.local/share/fdroidserver/keystore.jks',
-        'smartcardoptions': [],
-        'char_limits': {
-            'Summary' : 50,
-            'Description' : 1500
-        },
-        'keyaliases': { },
-    }
+    defconfig = get_default_config()
     for k, v in defconfig.items():
         if k not in config:
             config[k] = v
@@ -96,14 +99,7 @@ def read_config(opts, config_file='config.py'):
         v = os.path.expanduser(v)
         config[k] = os.path.expandvars(v)
 
-    if not config['sdk_path']:
-        logging.critical("Neither $ANDROID_HOME nor sdk_path is set, no Android SDK found!")
-        sys.exit(3)
-    if not os.path.exists(config['sdk_path']):
-        logging.critical('Android SDK path "' + config['sdk_path'] + '" does not exist!')
-        sys.exit(3)
-    if not os.path.isdir(config['sdk_path']):
-        logging.critical('Android SDK path "' + config['sdk_path'] + '" is not a directory!')
+    if not test_sdk_exists(config):
         sys.exit(3)
 
     if any(k in config for k in ["keystore", "keystorepass", "keypass"]):
@@ -124,6 +120,21 @@ def read_config(opts, config_file='config.py'):
 
     return config
 
+def test_sdk_exists(c):
+    if c['sdk_path'] == None:
+        # c['sdk_path'] is set to the value of ANDROID_HOME by default
+        logging.critical("Neither ANDROID_HOME nor sdk_path is set, no Android SDK found!")
+        logging.info('Set ANDROID_HOME to the path to your SDK, i.e.:')
+        logging.info('\texport ANDROID_HOME=/opt/android-sdk')
+        return False
+    if not os.path.exists(c['sdk_path']):
+        logging.critical('Android SDK path "' + c['sdk_path'] + '" does not exist!')
+        return False
+    if not os.path.isdir(c['sdk_path']):
+        logging.critical('Android SDK path "' + c['sdk_path'] + '" is not a directory!')
+        return False
+    return True
+
 def write_password_file(pwtype, password=None):
     '''
     writes out passwords to a protected file instead of passing passwords as
index 1b11bcd4fcb45ca36f2e6a43a8ef7ff4d82398c0..1448ae7966a87a9c16e4796d51bc3e69d75777c6 100644 (file)
@@ -105,6 +105,8 @@ def main():
                       help="Alias of the repo signing key in the keystore")
     (options, args) = parser.parse_args()
 
+    common.test_sdk_exists(common.get_default_config())
+
     # find root install prefix
     tmp = os.path.dirname(sys.argv[0])
     if os.path.basename(tmp) == 'bin':