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

Torben Hohn torben.hohn at linutronix.de
Fri Dec 15 16:49:03 CET 2017


On Fri, Dec 08, 2017 at 07:08:35PM +0100, Manuel Traut wrote:
> use same schema in all commands and avoid outofindex exception if no filename
> is give to validate command.

You folded 2 things into a single commit.
I will let this through, because its not so much.

Dont do this in the future, please.


Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>




> 
> 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
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Mit freundlichen Grüßen
Torben Hohn

Linutronix GmbH

Standort: Bremen

Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Firmensitz / Registered Office: D-88690 Uhldingen, Bahnhofstr. 3
Registergericht / Local District Court: Amtsgericht Freiburg i. Br.; HRB
Nr. / Trade register no.: 700 806

Geschäftsführer / Managing Directors: Heinz Egger, Thomas Gleixner

Eine Bitte von uns: Sollten Sie diese E-Mail irrtümlich erhalten haben,
benachrichtigen Sie uns in diesem Falle bitte sobald wie es Ihnen
möglich ist, durch Antwort-Mail. Vielen Dank!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20171215/20b64c17/attachment.sig>


More information about the elbe-devel mailing list