[elbe-devel] [PATCH 04/25] [V2] commands: improve argument parsing

Manuel Traut manut at linutronix.de
Fri Dec 8 19:08:35 CET 2017


use same schema in all commands and avoid outofindex exception if no filename
is give to validate command.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/commands/control.py  |  3 +--
 elbepack/commands/initvm.py   |  3 +--
 elbepack/commands/pbuilder.py |  3 +--
 elbepack/commands/prjrepo.py  |  3 +--
 elbepack/commands/validate.py | 14 +++++++++-----
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index c0e99571..c09ac3ab 100755
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -91,8 +91,7 @@ def run_command (argv):
     oparser.add_option_group (devel)
 
 
-    (opt,args) = oparser.parse_args (sys.argv)
-    args = args[2:]
+    (opt,args) = oparser.parse_args (argv)
 
     if len(args) < 1:
         print ('elbe control - no subcommand given', file=sys.stderr)
diff --git a/elbepack/commands/initvm.py b/elbepack/commands/initvm.py
index f96282b5..5d8185d7 100755
--- a/elbepack/commands/initvm.py
+++ b/elbepack/commands/initvm.py
@@ -63,8 +63,7 @@ def run_command (argv):
                         action="store_true", default=False,
            help="allow initvm to support nested kvm. This makes /proc/cpuinfo inside initvm differ per host." )
 
-    (opt,args) = oparser.parse_args (sys.argv)
-    args = args[2:]
+    (opt,args) = oparser.parse_args (argv)
 
     if len(args) < 1:
         print ('elbe initvm - no subcommand given', file=sys.stderr)
diff --git a/elbepack/commands/pbuilder.py b/elbepack/commands/pbuilder.py
index 2f8b94ab..eaa50f7d 100755
--- a/elbepack/commands/pbuilder.py
+++ b/elbepack/commands/pbuilder.py
@@ -46,8 +46,7 @@ def run_command (argv):
                         help="directory where to save downloaded Files")
 
 
-    (opt,args) = oparser.parse_args (sys.argv)
-    args = args[2:]
+    (opt,args) = oparser.parse_args (argv)
 
     if len(args) < 1:
         print ('elbe pbuilder - no subcommand given', file=sys.stderr)
diff --git a/elbepack/commands/prjrepo.py b/elbepack/commands/prjrepo.py
index dfc8c4d4..462fb3c4 100755
--- a/elbepack/commands/prjrepo.py
+++ b/elbepack/commands/prjrepo.py
@@ -67,8 +67,7 @@ def run_command(argv):
                      help="allow different elbe version on host and initvm")
     oparser.add_option_group(devel)
 
-    (opt, args) = oparser.parse_args(sys.argv)
-    args = args[2:]
+    (opt, args) = oparser.parse_args(argv)
 
     if len(args) < 1:
         print ('elbe prjrepo - no subcommand given', file=sys.stderr)
diff --git a/elbepack/commands/validate.py b/elbepack/commands/validate.py
index f9ff4e86..340eb506 100644
--- a/elbepack/commands/validate.py
+++ b/elbepack/commands/validate.py
@@ -28,14 +28,18 @@ def run_command( argv ):
                         help="try to access specified repositories",
                         default=False, action="store_true")
 
-    (opt,args) = oparser.parse_args(sys.argv)
+    (opt,args) = oparser.parse_args(argv)
 
-    if not os.path.exists(args[2]):
-        print ("%s - file not found" % args[2])
+    if len(args) < 1:
         oparser.print_help()
         sys.exit(20)
 
-    validation = validate_xml (args[2])
+    if not os.path.exists(args[0]):
+        print ("%s - file not found" % args[0])
+        oparser.print_help()
+        sys.exit(20)
+
+    validation = validate_xml (args[0])
     if len (validation):
         print "validation failed"
         for i in validation:
@@ -44,7 +48,7 @@ def run_command( argv ):
 
     if opt.validate_urls:
         try:
-            xml = ElbeXML(args[2], url_validation=ValidationMode.CHECK_ALL)
+            xml = ElbeXML(args[0], url_validation=ValidationMode.CHECK_ALL)
         except ValidationError as e:
             print e
             sys.exit(20)
-- 
2.15.1




More information about the elbe-devel mailing list