chiark / gitweb /
update: make icon extraction less dependent on aapt
[fdroidserver.git] / fdroidserver / init.py
index a115f64c717cc4cb74d3b25306d3545be79dd884..b47d65b6219fd4b6433828eaed8c4f012ff6fa15 100644 (file)
@@ -54,7 +54,7 @@ def main():
     parser = ArgumentParser()
     common.setup_global_opts(parser)
     parser.add_argument("-d", "--distinguished-name", default=None,
-                        help=_("X.509 'Distiguished Name' used when generating keys"))
+                        help=_("X.509 'Distinguished Name' used when generating keys"))
     parser.add_argument("--keystore", default=None,
                         help=_("Path to the keystore for the repo signing key"))
     parser.add_argument("--repo-keyalias", default=None,
@@ -65,27 +65,10 @@ def main():
                         help=_("Do not prompt for Android SDK path, just fail"))
     options = parser.parse_args()
 
-    # find root install prefix
-    tmp = os.path.dirname(sys.argv[0])
-    examplesdir = None
-    if os.path.basename(tmp) == 'bin':
-        egg_link = os.path.join(tmp, '..', 'local/lib/python2.7/site-packages/fdroidserver.egg-link')
-        if os.path.exists(egg_link):
-            # installed from local git repo
-            examplesdir = os.path.join(open(egg_link).readline().rstrip(), 'examples')
-        else:
-            # try .egg layout
-            examplesdir = os.path.dirname(os.path.dirname(__file__)) + '/share/doc/fdroidserver/examples'
-            if not os.path.exists(examplesdir):  # use UNIX layout
-                examplesdir = os.path.dirname(tmp) + '/share/doc/fdroidserver/examples'
-    else:
-        # we're running straight out of the git repo
-        prefix = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
-        examplesdir = prefix + '/examples'
-
     aapt = None
     fdroiddir = os.getcwd()
     test_config = dict()
+    examplesdir = common.get_examples_dir()
     common.fill_config_defaults(test_config)
 
     # track down where the Android SDK is, the default is to use the path set
@@ -100,11 +83,21 @@ def main():
             # make sure at least aapt is found, since this can't do anything without it
             test_config['aapt'] = common.find_sdk_tools_cmd('aapt')
         else:
-            # if neither --android-home nor the default sdk_path exist, prompt the user
+            # if neither --android-home nor the default sdk_path
+            # exist, prompt the user using platform-specific default
             default_sdk_path = '/opt/android-sdk'
             if sys.platform == 'win32' or sys.platform == 'cygwin':
-                default_sdk_path = os.path.join(os.getenv('USERPROFILE'),
-                                                'AppData', 'Local', 'Android', 'android-sdk')
+                p = os.path.join(os.getenv('USERPROFILE'),
+                                 'AppData', 'Local', 'Android', 'android-sdk')
+            elif sys.platform == 'darwin':
+                # on OSX, Homebrew is common and has an easy path to detect
+                p = '/usr/local/opt/android-sdk'
+            else:
+                # if the Debian packages are installed, suggest them
+                p = '/usr/lib/android-sdk'
+            if os.path.exists(p):
+                default_sdk_path = p
+
             while not options.no_prompt:
                 try:
                     s = input(_('Enter the path to the Android SDK (%s) here:\n> ') % default_sdk_path)
@@ -138,7 +131,9 @@ def main():
         logging.info('Try running `fdroid init` in an empty directory.')
         raise FDroidException('Repository already exists.')
 
-    if 'aapt' not in test_config or not os.path.isfile(test_config['aapt']):
+    if common.use_androguard():
+        pass
+    elif 'aapt' not in test_config or not os.path.isfile(test_config['aapt']):
         # try to find a working aapt, in all the recent possible paths
         build_tools = os.path.join(test_config['sdk_path'], 'build-tools')
         aaptdirs = []
@@ -151,7 +146,7 @@ def main():
             if os.path.isfile(os.path.join(d, 'aapt')):
                 aapt = os.path.join(d, 'aapt')
                 break
-        if os.path.isfile(aapt):
+        if aapt and os.path.isfile(aapt):
             dirname = os.path.basename(os.path.dirname(aapt))
             if dirname == 'build-tools':
                 # this is the old layout, before versioned build-tools
@@ -185,6 +180,7 @@ def main():
                              + '" does not exist, creating a new keystore there.')
     common.write_to_config(test_config, 'keystore', keystore)
     repo_keyalias = None
+    keydname = None
     if options.repo_keyalias:
         repo_keyalias = options.repo_keyalias
         common.write_to_config(test_config, 'repo_keyalias', repo_keyalias)
@@ -218,7 +214,16 @@ def main():
                                    flags=re.MULTILINE)
             with open('opensc-fdroid.cfg', 'w') as f:
                 f.write(opensc_fdroid)
-    elif not os.path.exists(keystore):
+    elif os.path.exists(keystore):
+        to_set = ['keystorepass', 'keypass', 'repo_keyalias', 'keydname']
+        if repo_keyalias:
+            to_set.remove('repo_keyalias')
+        if keydname:
+            to_set.remove('keydname')
+        logging.warning('\n' + _('Using existing keystore "{path}"').format(path=keystore)
+                        + '\n' + _('Now set these in config.py:') + ' '
+                        + ', '.join(to_set) + '\n')
+    else:
         password = common.genpassword()
         c = dict(test_config)
         c['keystorepass'] = password