# HG changeset patch # User Jeff Hammel # Date 1270500802 25200 # Node ID 35dc297efa252f04b13b39c0da06bf72052c510a # Parent 4d1cd60dd2a1c4f40597d0a7e331ec649995274e adding listing function and other cleanup diff -r 4d1cd60dd2a1 -r 35dc297efa25 profilemanager/command.py --- a/profilemanager/command.py Mon Apr 05 13:10:31 2010 -0700 +++ b/profilemanager/command.py Mon Apr 05 13:53:22 2010 -0700 @@ -5,6 +5,7 @@ import inspect import sys from optparse import OptionParser +from pprint import pprint if 'commands' not in globals(): commands = {} @@ -95,7 +96,7 @@ class CommandParser(OptionParser): def __init__(self, commands, description=None, setup=None): usage = '%prog [options] command [command-options]' - OptionParser.__init__(self, description=description) + OptionParser.__init__(self, usage=usage, description=description) for _command in commands: command(_command) self.disable_interspersed_args() @@ -160,5 +161,5 @@ commandparser.error("Too many arguments given") # invoke the command - print getattr(_object, name)(*command_args, **command_options.__dict__) + pprint(getattr(_object, name)(*command_args, **command_options.__dict__)) diff -r 4d1cd60dd2a1 -r 35dc297efa25 profilemanager/main.py --- a/profilemanager/main.py Mon Apr 05 13:10:31 2010 -0700 +++ b/profilemanager/main.py Mon Apr 05 13:53:22 2010 -0700 @@ -18,8 +18,9 @@ def main(args=sys.argv[1:]): # global option parsing - commands = [ ProfileManager.clone, - ProfileManager.backup, + commands = [ ProfileManager.backup, + ProfileManager.clone, + ProfileManager.list, ProfileManager.restore, ProfileManager.merge ] parser = CommandParser(commands, setup=create_profilemanager) diff -r 4d1cd60dd2a1 -r 35dc297efa25 profilemanager/manager.py --- a/profilemanager/manager.py Mon Apr 05 13:10:31 2010 -0700 +++ b/profilemanager/manager.py Mon Apr 05 13:53:22 2010 -0700 @@ -15,13 +15,27 @@ def __init__(self, profiles): """ - - profiles: profiles.ini file + - profiles: filesystem path to profiles.ini file """ self.profiles = profiles - self.profile_dir = '' + self.profile_dir = os.path.abspath(os.path.dirname(profiles)) ### (public) API + def list(self, directories=False): + """ + lists the profiles available in the config file + """ + from ConfigParser import SafeConfigParser as ConfigParser + parser = ConfigParser() + parser.read(self.profiles) + names = [] + for section in parser.sections(): + if section == 'General': + continue + names.append(parser.get(section, 'name')) + return '\n'.join(names) + def clone(self, source, dest): """ clones the profile `source` and output to `dest`