Replace "optparse" package with "argparse"
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Apr 2016 17:37:52 +0200
changeset 57 c7f27ae4230d
parent 56 01de65ad00fb
child 58 c191cc6756f5
Replace "optparse" package with "argparse"
src/pyams_utils/scripts/zodb.py
--- a/src/pyams_utils/scripts/zodb.py	Mon Apr 11 17:37:23 2016 +0200
+++ b/src/pyams_utils/scripts/zodb.py	Mon Apr 11 17:37:52 2016 +0200
@@ -14,7 +14,7 @@
 
 
 # import standard library
-import optparse
+import argparse
 import sys
 import textwrap
 
@@ -27,17 +27,16 @@
 
 def upgrade_site():
     """Check for site upgrade"""
-    usage = "usage: %prog config_uri"
+    usage = "usage: {0} config_uri".format(sys.argv[0])
     description = """Check for database upgrade.
                   Usage: pyams_upgrade production.ini
                   """
-    parser = optparse.OptionParser(usage=usage,
-                                   description=textwrap.dedent(description))
-    options, args = parser.parse_args(sys.argv[1:])
-    if not len(args) >= 1:
-        print("You must provide at least one configuration file")
-        return 2
-    config_uri = args[0]
+    parser = argparse.ArgumentParser(usage=usage,
+                                     description=textwrap.dedent(description))
+    parser.add_argument('config_uri', help='Name of configuration file')
+    args = parser.parse_args()
+
+    config_uri = args.config_uri
     env = bootstrap(config_uri)
     settings, closer = env['registry'].settings, env['closer']
     try: