chiark / gitweb /
replace deprecated optparse with argparse
authornero-tux <neroburner@hotmail.de>
Fri, 4 Sep 2015 09:37:05 +0000 (11:37 +0200)
committerNeroBurner <neroburner@hotmail.de>
Sun, 6 Sep 2015 08:34:50 +0000 (10:34 +0200)
following guidelines from:
https://docs.python.org/2/library/argparse.html#upgrading-optparse-code
except, still using option = parse.parse_args() instead of args = ...

- using the following script in folder fdroidserver:
for i in *.py; do
sed -i -e 's/optparse/argparse/' \
-e 's/OptionParser/ArgumentParser/' \
-e 's/OptionError/ArgumentError/' \
-e 's/add_option/add_argument/' \
-e 's/(options, args) = parser/options = parser/' \
-e 's/options, args = parser/options = parser/' \
-e 's/Usage: %prog/%(prog)s/' $i;
done
- use ArgumentParser argument to replace (option, args) = parser.parse()
  call
- use parser.error(msg) instead of raise ArgumentException as suggested
  in https://docs.python.org/2/library/argparse.html#exiting-methods
- in fdroid catch ArgumentError instead of OptionError

17 files changed:
fdroid
fdroidserver/build.py
fdroidserver/checkupdates.py
fdroidserver/gpgsign.py
fdroidserver/import.py
fdroidserver/init.py
fdroidserver/install.py
fdroidserver/lint.py
fdroidserver/publish.py
fdroidserver/readmeta.py
fdroidserver/rewritemeta.py
fdroidserver/scanner.py
fdroidserver/server.py
fdroidserver/signindex.py
fdroidserver/stats.py
fdroidserver/update.py
fdroidserver/verify.py

diff --git a/fdroid b/fdroid
index 91dc992925d647bec40b9702ce2d4a774bfd4db3..33a6025103cb8b86ef2b5e60221da8b4d2d9642c 100755 (executable)
--- a/fdroid
+++ b/fdroid
@@ -22,7 +22,7 @@ import sys
 import logging
 
 import fdroidserver.common
-from optparse import OptionError
+from argparse import ArgumentError
 
 commands = {
     "build": "Build a package from source",
@@ -124,7 +124,7 @@ def main():
         else:
             logging.critical(str(e))
         sys.exit(1)
-    except OptionError, e:
+    except ArgumentError as e:
         logging.critical(str(e))
         sys.exit(1)
     except KeyboardInterrupt:
index be93410814aa303f85301114a839d50f99c76d9e..9bc8724cff884fa31a2c7fcd3c4a950c9cc51e5b 100644 (file)
@@ -29,7 +29,7 @@ import traceback
 import time
 import json
 from ConfigParser import ConfigParser
-from optparse import OptionParser, OptionError
+from argparse import ArgumentParser
 from distutils.version import LooseVersion
 import logging
 
@@ -930,47 +930,48 @@ def trybuild(app, thisbuild, build_dir, output_dir, also_check_dir, srclib_dir,
 
 
 def parse_commandline():
-    """Parse the command line. Returns options, args."""
-
-    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")
-    parser.add_option("-l", "--latest", action="store_true", default=False,
-                      help="Build only the latest version of each package")
-    parser.add_option("-s", "--stop", action="store_true", default=False,
-                      help="Make the build stop on exceptions")
-    parser.add_option("-t", "--test", action="store_true", default=False,
-                      help="Test mode - put output in the tmp directory only, and always build, even if the output already exists.")
-    parser.add_option("--server", action="store_true", default=False,
-                      help="Use build server")
-    parser.add_option("--resetserver", action="store_true", default=False,
-                      help="Reset and create a brand new build server, even if the existing one appears to be ok.")
-    parser.add_option("--on-server", dest="onserver", action="store_true", default=False,
-                      help="Specify that we're running on the build server")
-    parser.add_option("--skip-scan", dest="skipscan", action="store_true", default=False,
-                      help="Skip scanning the source code for binaries and other problems")
-    parser.add_option("--no-tarball", dest="notarball", action="store_true", default=False,
-                      help="Don't create a source tarball, useful when testing a build")
-    parser.add_option("--no-refresh", dest="refresh", action="store_false", default=True,
-                      help="Don't refresh the repository, useful when testing a build with no internet connection")
-    parser.add_option("-f", "--force", action="store_true", default=False,
-                      help="Force build of disabled apps, and carries on regardless of scan problems. Only allowed in test mode.")
-    parser.add_option("-a", "--all", action="store_true", default=False,
-                      help="Build all applications available")
-    parser.add_option("-w", "--wiki", default=False, action="store_true",
-                      help="Update the wiki")
-    options, args = parser.parse_args()
+    """Parse the command line. Returns options, parser."""
+
+    parser = ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("-l", "--latest", action="store_true", default=False,
+                        help="Build only the latest version of each package")
+    parser.add_argument("-s", "--stop", action="store_true", default=False,
+                        help="Make the build stop on exceptions")
+    parser.add_argument("-t", "--test", action="store_true", default=False,
+                        help="Test mode - put output in the tmp directory only, and always build, even if the output already exists.")
+    parser.add_argument("--server", action="store_true", default=False,
+                        help="Use build server")
+    parser.add_argument("--resetserver", action="store_true", default=False,
+                        help="Reset and create a brand new build server, even if the existing one appears to be ok.")
+    parser.add_argument("--on-server", dest="onserver", action="store_true", default=False,
+                        help="Specify that we're running on the build server")
+    parser.add_argument("--skip-scan", dest="skipscan", action="store_true", default=False,
+                        help="Skip scanning the source code for binaries and other problems")
+    parser.add_argument("--no-tarball", dest="notarball", action="store_true", default=False,
+                        help="Don't create a source tarball, useful when testing a build")
+    parser.add_argument("--no-refresh", dest="refresh", action="store_false", default=True,
+                        help="Don't refresh the repository, useful when testing a build with no internet connection")
+    parser.add_argument("-f", "--force", action="store_true", default=False,
+                        help="Force build of disabled apps, and carries on regardless of scan problems. Only allowed in test mode.")
+    parser.add_argument("-a", "--all", action="store_true", default=False,
+                        help="Build all applications available")
+    parser.add_argument("-w", "--wiki", default=False, action="store_true",
+                        help="Update the wiki")
+    options = parser.parse_args()
 
     # Force --stop with --on-server to get correct exit code
     if options.onserver:
         options.stop = True
 
     if options.force and not options.test:
-        raise OptionError("Force is only allowed in test mode", "force")
+        parser.error("option %s: Force is only allowed in test mode" % "force")
 
-    return options, args
+    return options, parser
 
 options = None
 config = None
@@ -980,16 +981,16 @@ def main():
 
     global options, config
 
-    options, args = parse_commandline()
-    if not args and not options.all:
-        raise OptionError("If you really want to build all the apps, use --all", "all")
+    options, parser = parse_commandline()
+    if not options.appid and not options.all:
+        parser.error("option %s: If you really want to build all the apps, use --all" % "all")
 
     config = common.read_config(options)
 
     if config['build_server_always']:
         options.server = True
     if options.resetserver and not options.server:
-        raise OptionError("Using --resetserver without --server makes no sense", "resetserver")
+        parser.error("option %s: Using --resetserver without --server makes no sense" % "resetserver")
 
     log_dir = 'logs'
     if not os.path.isdir(log_dir):
@@ -1026,7 +1027,7 @@ def main():
     # Read all app and srclib metadata
     allapps = metadata.read_metadata(xref=not options.onserver)
 
-    apps = common.read_app_args(args, allapps, True)
+    apps = common.read_app_args(options.appid, allapps, True)
     for appid, app in apps.items():
         if (app['Disabled'] and not options.force) or not app['Repo Type'] or not app['builds']:
             del apps[appid]
index 1962dded82df9be449c7b468d655b0bfe41296f5..0e68c97c9249c37e8761e04832d39b3a76eeadf6 100644 (file)
@@ -24,7 +24,7 @@ import re
 import urllib2
 import time
 import subprocess
-from optparse import OptionParser
+from argparse import ArgumentParser
 import traceback
 import HTMLParser
 from distutils.version import LooseVersion
@@ -515,27 +515,28 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
-    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")
-    parser.add_option("--auto", action="store_true", default=False,
-                      help="Process auto-updates")
-    parser.add_option("--autoonly", action="store_true", default=False,
-                      help="Only process apps with auto-updates")
-    parser.add_option("--commit", action="store_true", default=False,
-                      help="Commit changes")
-    parser.add_option("--gplay", action="store_true", default=False,
-                      help="Only print differences with the Play Store")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id to check for updates")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("--auto", action="store_true", default=False,
+                        help="Process auto-updates")
+    parser.add_argument("--autoonly", action="store_true", default=False,
+                        help="Only process apps with auto-updates")
+    parser.add_argument("--commit", action="store_true", default=False,
+                        help="Commit changes")
+    parser.add_argument("--gplay", action="store_true", default=False,
+                        help="Only print differences with the Play Store")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
     # Get all apps...
     allapps = metadata.read_metadata()
 
-    apps = common.read_app_args(args, allapps, False)
+    apps = common.read_app_args(options.appid, allapps, False)
 
     if options.gplay:
         for app in apps:
index 0358e99ed62ec1cb754d56fac262cf0bfc790fed..8fca41cd46ad125cf80dc38049be7d6966fd77e1 100644 (file)
@@ -20,7 +20,7 @@
 import sys
 import os
 import glob
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -35,12 +35,12 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser(usage="Usage: %prog [options]")
-    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]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
index 31757dbe7ce861d16559720dd3f47ec504540198..9323f9bdfb93589a953f0b1c8087b266e5db9619 100644 (file)
@@ -22,7 +22,7 @@ import sys
 import os
 import shutil
 import urllib
-from optparse import OptionParser
+from argparse import ArgumentParser
 from ConfigParser import ConfigParser
 import logging
 import common
@@ -75,18 +75,18 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser()
-    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")
-    parser.add_option("-u", "--url", default=None,
-                      help="Project URL to import from.")
-    parser.add_option("-s", "--subdir", default=None,
-                      help="Path to main android project subdirectory, if not in root.")
-    parser.add_option("--rev", default=None,
-                      help="Allows a different revision (or git branch) to be specified for the initial import")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser()
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("-u", "--url", default=None,
+                        help="Project URL to import from.")
+    parser.add_argument("-s", "--subdir", default=None,
+                        help="Path to main android project subdirectory, if not in root.")
+    parser.add_argument("--rev", default=None,
+                        help="Allows a different revision (or git branch) to be specified for the initial import")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
index 0ed66d6b9b2ad2f9d5fc5a4656752aae3d9891fe..cf75b911d5391fd17bc3e3531ce727475ee55cd0 100644 (file)
@@ -25,7 +25,7 @@ import re
 import shutil
 import socket
 import sys
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -50,22 +50,22 @@ def main():
     global options, config
 
     # Parse command line...
-    parser = OptionParser()
-    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")
-    parser.add_option("-d", "--distinguished-name", default=None,
-                      help="X.509 'Distiguished Name' used when generating keys")
-    parser.add_option("--keystore", default=None,
-                      help="Path to the keystore for the repo signing key")
-    parser.add_option("--repo-keyalias", default=None,
-                      help="Alias of the repo signing key in the keystore")
-    parser.add_option("--android-home", default=None,
-                      help="Path to the Android SDK (sometimes set in ANDROID_HOME)")
-    parser.add_option("--no-prompt", action="store_true", default=False,
-                      help="Do not prompt for Android SDK path, just fail")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser()
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("-d", "--distinguished-name", default=None,
+                        help="X.509 'Distiguished 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,
+                        help="Alias of the repo signing key in the keystore")
+    parser.add_argument("--android-home", default=None,
+                        help="Path to the Android SDK (sometimes set in ANDROID_HOME)")
+    parser.add_argument("--no-prompt", action="store_true", default=False,
+                        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])
index a5cb98adf17c0fa0cb63cb222be171e4c325c9b3..5339319fb69b2bb60ca4a7b4460a967c102f8fc1 100644 (file)
@@ -21,7 +21,7 @@
 import sys
 import os
 import glob
-from optparse import OptionParser, OptionError
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -49,17 +49,18 @@ def main():
     global options, config
 
     # 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")
-    parser.add_option("-a", "--all", action="store_true", default=False,
-                      help="Install all signed applications available")
-    (options, args) = parser.parse_args()
-
-    if not args and not options.all:
-        raise OptionError("If you really want to install all the signed apps, use --all", "all")
+    parser = ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("-a", "--all", action="store_true", default=False,
+                        help="Install all signed applications available")
+    options = parser.parse_args()
+
+    if not options.appid and not options.all:
+        parser.error("option %s: If you really want to install all the signed apps, use --all" % "all")
 
     config = common.read_config(options)
 
@@ -68,9 +69,9 @@ def main():
         logging.info("No signed output directory - nothing to do")
         sys.exit(0)
 
-    if args:
+    if options.appid:
 
-        vercodes = common.read_pkg_args(args, True)
+        vercodes = common.read_pkg_args(options.appid, True)
         apks = {appid: None for appid in vercodes}
 
         # Get the signed apk with the highest vercode
index 123ed688c71759bef6249911333661eecf49269c..ab24201d242901a8d31aefb1795dd3d24f744934 100644 (file)
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU Affero General Public Licen
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from optparse import OptionParser
+from argparse import ArgumentParser
 import re
 import logging
 import common
@@ -150,18 +150,19 @@ def main():
         count['warn'] += 1
 
     # Parse command line...
-    parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
-    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 [APPID ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
     # Get all apps...
     allapps = metadata.read_metadata(xref=True)
-    apps = common.read_app_args(args, allapps, False)
+    apps = common.read_app_args(options.appid, allapps, False)
 
     filling_ucms = re.compile('^(Tags.*|RepoManifest.*)')
 
index 42f02aa448e3e5e270224e637865bec6eb9a4266..0ef5b60d63d04ad166523913ce3d24574a3e5b9d 100644 (file)
@@ -23,7 +23,7 @@ import os
 import shutil
 import md5
 import glob
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -39,13 +39,14 @@ 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] ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
@@ -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()
index 3dd6865ac49f0d5f025223eaf60637ba5e9ec8a2..a01a358f315d89c0c8c482e9a6384954188c0320 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from optparse import OptionParser
+from argparse import ArgumentParser
 import common
 import metadata
 
 
 def main():
 
-    parser = OptionParser(usage="Usage: %prog")
-    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")
+    parser = ArgumentParser(usage="%(prog)s")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
     parser.parse_args()
     common.read_config(None)
 
index 5f6f190e3f8e0dd73a82873cd3ef43d74600a7e4..45497695fb8ac8f62eea2c364b0bf124e2304adf 100644 (file)
@@ -19,7 +19,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 import common
 import metadata
@@ -33,18 +33,19 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
-    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 [APPID ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
     # Get all apps...
     allapps = metadata.read_metadata(xref=True)
-    apps = common.read_app_args(args, allapps, False)
+    apps = common.read_app_args(options.appid, allapps, False)
 
     for appid, app in apps.iteritems():
         metadatapath = app['metadatapath']
index c8a816369d22754fece7e21f30ecadfc60daa7b1..fc15569b5eee4cb088199ec18c0be7e217067f67 100644 (file)
@@ -20,7 +20,7 @@
 import os
 import re
 import traceback
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -249,18 +249,19 @@ 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] ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
     # Read all app and srclib metadata
     allapps = metadata.read_metadata()
-    apps = common.read_app_args(args, allapps, True)
+    apps = common.read_app_args(options.appid, allapps, True)
 
     probcount = 0
 
index 2acd21807af74e0ed72776e057cd28af325d8e89..114e8a801076384187ac0f4eabd37a70c26142d2 100644 (file)
@@ -24,7 +24,7 @@ import os
 import paramiko
 import pwd
 import subprocess
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 import common
 
@@ -195,28 +195,25 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser()
-    parser.add_option("-i", "--identity-file", default=None,
-                      help="Specify an identity file to provide to SSH for rsyncing")
-    parser.add_option("--local-copy-dir", default=None,
-                      help="Specify a local folder to sync the repo to")
-    parser.add_option("--sync-from-local-copy-dir", action="store_true", default=False,
-                      help="Before uploading to servers, sync from local copy dir")
-    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")
-    parser.add_option("--no-checksum", action="store_true", default=False,
-                      help="Don't use rsync checksums")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser()
+    parser.add_argument("command", help="command to execute, either 'init' or 'update'")
+    parser.add_argument("-i", "--identity-file", default=None,
+                        help="Specify an identity file to provide to SSH for rsyncing")
+    parser.add_argument("--local-copy-dir", default=None,
+                        help="Specify a local folder to sync the repo to")
+    parser.add_argument("--sync-from-local-copy-dir", action="store_true", default=False,
+                        help="Before uploading to servers, sync from local copy dir")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("--no-checksum", action="store_true", default=False,
+                        help="Don't use rsync checksums")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
-    if len(args) != 1:
-        logging.critical("Specify a single command")
-        sys.exit(1)
-
-    if args[0] != 'init' and args[0] != 'update':
+    if options.command != 'init' and options.command != 'update':
         logging.critical("The only commands currently supported are 'init' and 'update'")
         sys.exit(1)
 
@@ -288,7 +285,7 @@ def main():
     if config['per_app_repos']:
         repo_sections += common.get_per_app_repos()
 
-    if args[0] == 'init':
+    if options.command == 'init':
         ssh = paramiko.SSHClient()
         ssh.load_system_host_keys()
         for serverwebroot in config.get('serverwebroot', []):
@@ -310,7 +307,7 @@ def main():
                     sftp.mkdir(repo_path, mode=0755)
             sftp.close()
             ssh.close()
-    elif args[0] == 'update':
+    elif options.command == 'update':
         for repo_section in repo_sections:
             if local_copy_dir is not None:
                 if config['sync_from_local_copy_dir'] and os.path.exists(repo_section):
index 4c0c39cabaf3cd5c25bee3d1bc5f8824d8399043..e3645278f94729ed4c955e3b55bd3de3c688ff1c 100644 (file)
@@ -19,7 +19,7 @@
 
 import sys
 import os
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -34,12 +34,12 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser(usage="Usage: %prog [options]")
-    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]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
index 5df006948176b9bfe0f8759e21f1b4a21107b483..a4f7cf162526204cac165c6568e36490af099e66 100644 (file)
@@ -24,7 +24,7 @@ import time
 import traceback
 import glob
 import json
-from optparse import OptionParser
+from argparse import ArgumentParser
 import paramiko
 import socket
 import logging
@@ -50,19 +50,19 @@ def main():
     global options, config
 
     # Parse command line...
-    parser = OptionParser()
-    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")
-    parser.add_option("-d", "--download", action="store_true", default=False,
-                      help="Download logs we don't have")
-    parser.add_option("--recalc", action="store_true", default=False,
-                      help="Recalculate aggregate stats - use when changes "
-                      "have been made that would invalidate old cached data.")
-    parser.add_option("--nologs", action="store_true", default=False,
-                      help="Don't do anything logs-related")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser()
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("-d", "--download", action="store_true", default=False,
+                        help="Download logs we don't have")
+    parser.add_argument("--recalc", action="store_true", default=False,
+                        help="Recalculate aggregate stats - use when changes "
+                        "have been made that would invalidate old cached data.")
+    parser.add_argument("--nologs", action="store_true", default=False,
+                        help="Don't do anything logs-related")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
index d332222baeb3ad6da182f32fc49f92aa9bdd5d22..c3fba05b808b198e75fba50c32803240f0f528e1 100644 (file)
@@ -29,7 +29,7 @@ import hashlib
 import pickle
 from datetime import datetime, timedelta
 from xml.dom.minidom import Document
-from optparse import OptionParser
+from argparse import ArgumentParser
 import time
 from pyasn1.error import PyAsn1Error
 from pyasn1.codec.der import decoder, encoder
@@ -1048,35 +1048,35 @@ def main():
     global config, options
 
     # Parse command line...
-    parser = OptionParser()
-    parser.add_option("--create-key", action="store_true", default=False,
-                      help="Create a repo signing key in a keystore")
-    parser.add_option("-c", "--create-metadata", action="store_true", default=False,
-                      help="Create skeleton metadata files that are missing")
-    parser.add_option("--delete-unknown", action="store_true", default=False,
-                      help="Delete APKs without metadata from the repo")
-    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")
-    parser.add_option("-b", "--buildreport", action="store_true", default=False,
-                      help="Report on build data status")
-    parser.add_option("-i", "--interactive", default=False, action="store_true",
-                      help="Interactively ask about things that need updating.")
-    parser.add_option("-I", "--icons", action="store_true", default=False,
-                      help="Resize all the icons exceeding the max pixel size and exit")
-    parser.add_option("-e", "--editor", default="/etc/alternatives/editor",
-                      help="Specify editor to use in interactive mode. Default " +
-                      "is /etc/alternatives/editor")
-    parser.add_option("-w", "--wiki", default=False, action="store_true",
-                      help="Update the wiki")
-    parser.add_option("", "--pretty", action="store_true", default=False,
-                      help="Produce human-readable index.xml")
-    parser.add_option("--clean", action="store_true", default=False,
-                      help="Clean update - don't uses caches, reprocess all apks")
-    parser.add_option("--nosign", action="store_true", default=False,
-                      help="When configured for signed indexes, create only unsigned indexes at this stage")
-    (options, args) = parser.parse_args()
+    parser = ArgumentParser()
+    parser.add_argument("--create-key", action="store_true", default=False,
+                        help="Create a repo signing key in a keystore")
+    parser.add_argument("-c", "--create-metadata", action="store_true", default=False,
+                        help="Create skeleton metadata files that are missing")
+    parser.add_argument("--delete-unknown", action="store_true", default=False,
+                        help="Delete APKs without metadata from the repo")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    parser.add_argument("-b", "--buildreport", action="store_true", default=False,
+                        help="Report on build data status")
+    parser.add_argument("-i", "--interactive", default=False, action="store_true",
+                        help="Interactively ask about things that need updating.")
+    parser.add_argument("-I", "--icons", action="store_true", default=False,
+                        help="Resize all the icons exceeding the max pixel size and exit")
+    parser.add_argument("-e", "--editor", default="/etc/alternatives/editor",
+                        help="Specify editor to use in interactive mode. Default " +
+                        "is /etc/alternatives/editor")
+    parser.add_argument("-w", "--wiki", default=False, action="store_true",
+                        help="Update the wiki")
+    parser.add_argument("--pretty", action="store_true", default=False,
+                        help="Produce human-readable index.xml")
+    parser.add_argument("--clean", action="store_true", default=False,
+                        help="Clean update - don't uses caches, reprocess all apks")
+    parser.add_argument("--nosign", action="store_true", default=False,
+                        help="When configured for signed indexes, create only unsigned indexes at this stage")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
index b751c4996aa97b126475a7fbf559000663a6d503..0e2f19621f5d506b334668dbf589a2ae65469db9 100644 (file)
@@ -20,7 +20,7 @@
 import sys
 import os
 import glob
-from optparse import OptionParser
+from argparse import ArgumentParser
 import logging
 
 import common
@@ -36,12 +36,13 @@ def main():
     global options, config
 
     # 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] ...]]")
+    parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+    parser.add_argument("-v", "--verbose", action="store_true", default=False,
+                        help="Spew out even more information than normal")
+    parser.add_argument("-q", "--quiet", action="store_true", default=False,
+                        help="Restrict output to warnings and errors")
+    options = parser.parse_args()
 
     config = common.read_config(options)
 
@@ -58,7 +59,7 @@ def main():
     verified = 0
     notverified = 0
 
-    vercodes = common.read_pkg_args(args, True)
+    vercodes = common.read_pkg_args(options.appid, True)
 
     for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))):