WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-tools

[Xen-tools] [PATCH 2/2] Cleanup bogus argument handling

To: Xen Tools Developers <xen-tools@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-tools] [PATCH 2/2] Cleanup bogus argument handling
From: Dan Smith <danms@xxxxxxxxxx>
Date: Mon, 29 Aug 2005 11:48:25 -0700
Delivery-date: Mon, 29 Aug 2005 18:46:28 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-tools-request@lists.xensource.com?subject=help>
List-id: Xen control tools developers <xen-tools.lists.xensource.com>
List-post: <mailto:xen-tools@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-tools-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux)
The attached patch makes the argument handling within subcommand
handlers more consistent.  Now, subcommands don't modify the args list
they're given, so that error handling can be the same for all
commands.

Signed-off-by: Dan Smith <danms@xxxxxxxxxx>

diff -r a184de8302e3 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Mon Aug 29 17:26:24 2005
+++ b/tools/python/xen/xm/main.py       Mon Aug 29 10:57:15 2005
@@ -173,8 +173,7 @@
     from xen.xm import create
     # ugly hack because the opt parser apparently wants
     # the subcommand name just to throw it away!
-    args.insert(0,"bogus")
-    create.main(args)
+    create.main(["bogus"] + args)
 
 def xm_save(args):
     arg_check(args,2,"save")
@@ -202,8 +201,7 @@
     from xen.xm import migrate
     # ugly hack because the opt parser apparently wants
     # the subcommand name just to throw it away!
-    args.insert(0,"bogus")
-    migrate.main(args)
+    migrate.main(["bogus"] + args)
 
 def xm_list(args):
     use_long = 0
@@ -290,8 +288,7 @@
                    vcpuinfo)
 
 def xm_vcpu_list(args):
-    args.insert(0,"-v")
-    xm_list(args)
+    xm_list(["-v"] + args)
 
 def xm_destroy(args):
     arg_check(args,1,"destroy")
@@ -299,33 +296,28 @@
     from xen.xm import destroy
     # ugly hack because the opt parser apparently wants
     # the subcommand name just to throw it away!
-    args.insert(0,"bogus")
-    destroy.main(args)
+    destroy.main(["bogus"] + args)
             
 def xm_reboot(args):
     arg_check(args,1,"reboot")
+    from xen.xm import shutdown
     # ugly hack because the opt parser apparently wants
     # the subcommand name just to throw it away!
-    args.insert(0,"bogus")
-    args.insert(2,"-R")
-    from xen.xm import shutdown
-    shutdown.main(args)
+    shutdown.main(["bogus", "-R"] + args)
 
 def xm_shutdown(args):
     arg_check(args,1,"shutdown")
 
+    from xen.xm import shutdown
     # ugly hack because the opt parser apparently wants
     # the subcommand name just to throw it away!
-    args.insert(0,"bogus")
-    from xen.xm import shutdown
-    shutdown.main(args)
+    shutdown.main(["bogus"] + args)
 
 def xm_sysrq(args):
     from xen.xm import sysrq
     # ugly hack because the opt parser apparently wants
     # the subcommand name just to throw it away!
-    args.insert(0,"bogus")
-    sysrq.main(args)
+    sysrq.main(["bogus"] + args)
 
 def xm_pause(args):
     arg_check(args, 1, "pause")
@@ -480,10 +472,11 @@
               fn=set_true, default=0,
               use="Clear the contents of the Xen message buffer.")
     # Work around for gopts
-    args.insert(0,"bogus")
-    gopts.parse(args)
-    if not (1 <= len(args) <= 2):
-        err('Invalid arguments: ' + str(args))
+    myargs = args
+    myargs.insert(0, "bogus")
+    gopts.parse(myargs)
+    if not (1 <= len(myargs) <= 2):
+        err('Invalid arguments: ' + str(myargs))
 
     from xen.xend.XendClient import server
     if not gopts.vals.clear:
@@ -730,8 +723,6 @@
             sys.exit(1)
         except XendError, ex:
             if len(args) > 0:
-                if args[0] == "bogus":
-                    args.remove("bogus")
                 handle_xend_error(argv[1], args[0], ex)
             else:
                 print "Unexpected error:", sys.exc_info()[0]
-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms@xxxxxxxxxx

_______________________________________________
Xen-tools mailing list
Xen-tools@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-tools
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-tools] [PATCH 2/2] Cleanup bogus argument handling, Dan Smith <=