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] Re: [Xen-devel] [PATCH] rework xen/xm/main.py to be more str

To: Sean Dague <sean@xxxxxxxxx>
Subject: [Xen-tools] Re: [Xen-devel] [PATCH] rework xen/xm/main.py to be more straight forward
From: Anthony Liguori <aliguori@xxxxxxxxxx>
Date: Fri, 05 Aug 2005 10:23:16 -0500
Cc: xen-tools@xxxxxxxxxxxxxxxxxxx, Ian Pratt <m+Ian.Pratt@xxxxxxxxxxxx>
Delivery-date: Fri, 05 Aug 2005 15:21:45 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20050801192216.GA5974@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>
References: <20050801192216.GA5974@xxxxxxxxxxxxxxxxxxx>
Sender: xen-tools-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
Hi Sean,

I think there are a few ways we can improve this. The key is to make sure that we don't add additional complexity.

1) Move all of the functions that implement the commands into a separate file (xmlib.py perhaps?) 2) Have main.py parse the command line and look in xmlib.__dict__ for the function pointer 3) Have --help be generated based on the contents of xmlib.__dict__[cmd].__doc__

#3 has the nice side-effect of ensuring that xmlib is completely documented which makes xmlib the perfect python interface for management tools. It would be even nicer if the arguments were expanded instead of passed as a list so the functions could be called in a more natural way.

A short help can be autogenerated by only grabbing the first sentence of __doc__.

Aliases could be supported with module-level variables assigned to the function they alias. However, I don't like aliases so I'd just not do anything.

One thing this would break is abbrevation but I'm quite sure Mark is the only one using them :-)

Regards,

Anthony Liguori

Sean Dague wrote:

The following patch is a major restructuring of main.py to be more straight
forward, and remove as much code as possible.  It does a number of things:

* It implements the standardized options proposed via my RFC for xm
* It restructures the calling of these functions to be function pointers out
 of a dictionary, instead of subclasses found through inspection
* It consolidates all help info, making it easier to see that the help
 screen looks consistent across commands
* It moves object importing into the functions that require them only,
 allowing commands like "xm help" to be runable as non root
* It adds command aliasing to provide backwards compatibility with many
 commands (i.e. xm balloon)
* It provides more useful error messages is most fail cases
* It implements a short help by default (which takes < 24 screen lines) as
 requested by Mark W at OLS
* It attempts to trap more exceptions than before and provide useful errors
 based on them (this requires more testing)

It also has the added benefit of dropping the total size of main.py from
935 lines to 694 lines.

This patch makes no changes to any other elements of xen/xm, and works with
all other objects and libraries as is.


_______________________________________________
Xen-tools mailing list
Xen-tools@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-tools