chiark / gitweb /
Switch all headers to python3
[fdroidserver.git] / fdroidserver / publish.py
index 42f02aa448e3e5e270224e637865bec6eb9a4266..c34382342f806e9e5a30edc4b01753e53dc171c0 100644 (file)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python3
 #
 # publish.py - part of the FDroid server tools
 # Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
@@ -23,7 +22,7 @@ import os
 import shutil
 import md5
 import glob
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -39,16 +38,18 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser(usage="Usage: %prog [options] "
-                          "[APPID[:VERCODE] [APPID[:VERCODE] ...]]")
-    parser.add_option("-v", "--verbose", action="store_true", default=False,
-                      help="Spew out even more information than normal")
-    parser.add_option("-q", "--quiet", action="store_true", default=False,
-                      help="Restrict output to warnings and errors")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser(usage="%(prog)s [options] "
+                            "[APPID[:VERCODE] [APPID[:VERCODE] ...]]")
+    common.setup_global_opts(parser)
+    parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
+    if not ('jarsigner' in config and 'keytool' in config):
+        logging.critical('Java JDK not found! Install in standard location or set java_paths!')
+        sys.exit(1)
+
     log_dir = 'logs'
     if not os.path.isdir(log_dir):
         logging.info("Creating log directory")
@@ -86,7 +87,7 @@ def main():
     # Nonetheless, to be sure, before publishing we check that there are no
     # collisions, and refuse to do any publishing if that's the case...
     allapps = metadata.read_metadata()
-    vercodes = common.read_pkg_args(args, True)
+    vercodes = common.read_pkg_args(options.appid, True)
     allaliases = []
     for appid in allapps:
         m = md5.new()
@@ -119,7 +120,7 @@ def main():
             sys.exit(1)
         app = allapps[appid]
 
-        if app.get('Binaries', None):
+        if app.Binaries is not None:
 
             # It's an app where we build from source, and verify the apk
             # contents against a developer's binary, and then publish their
@@ -165,12 +166,12 @@ def main():
 
             # See if we already have a key for this application, and
             # if not generate one...
-            p = FDroidPopen(['keytool', '-list',
+            p = FDroidPopen([config['keytool'], '-list',
                              '-alias', keyalias, '-keystore', config['keystore'],
                              '-storepass:file', config['keystorepassfile']])
             if p.returncode != 0:
                 logging.info("Key does not exist - generating...")
-                p = FDroidPopen(['keytool', '-genkey',
+                p = FDroidPopen([config['keytool'], '-genkey',
                                  '-keystore', config['keystore'],
                                  '-alias', keyalias,
                                  '-keyalg', 'RSA', '-keysize', '2048',
@@ -183,10 +184,10 @@ def main():
                     raise BuildException("Failed to generate key")
 
             # Sign the application...
-            p = FDroidPopen(['jarsigner', '-keystore', config['keystore'],
+            p = FDroidPopen([config['jarsigner'], '-keystore', config['keystore'],
                              '-storepass:file', config['keystorepassfile'],
                              '-keypass:file', config['keypassfile'], '-sigalg',
-                             'MD5withRSA', '-digestalg', 'SHA1',
+                             'SHA1withRSA', '-digestalg', 'SHA1',
                              apkfile, keyalias])
             # TODO keypass should be sent via stdin
             if p.returncode != 0: