# HG changeset patch # User Jeff Hammel # Date 1271286440 25200 # Node ID b1274abd120655f1ec92e95a859e47201f27c09c # Parent 7205cb6f5530c5fdb50dff77483a9111063542d8 rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should diff -r 7205cb6f5530 -r b1274abd1206 profilemanager/manager.py --- a/profilemanager/manager.py Tue Apr 13 19:24:52 2010 -0700 +++ b/profilemanager/manager.py Wed Apr 14 16:07:20 2010 -0700 @@ -4,6 +4,7 @@ import os import shutil +import ConfigParser from utils import format_tabular from ConfigParser import SafeConfigParser as ConfigParser @@ -24,18 +25,21 @@ ### (public) API + def new(self, name): + """ + generate a new clean profile + - name: name of the profile to generate + """ + raise NotImplementedError + def list(self, directories=False): """ lists the profiles available in the config file - directories : display the directories """ - parser = ConfigParser() - parser.read(self.profiles) + profiles = self.profiles_dict() retval = [] - for section in parser.sections(): - if section == 'General': - continue - name = parser.get(section, 'name') + for name in sorted(profiles.keys()): values = [name] if directories: values.append(self.path(name)) @@ -45,8 +49,13 @@ def backups(self, profile=None): """ list backups for a given profile, or all profiles if the - profile is not given + profile is not given; returns a list of backups if + profile is given or a dictionary of lists otherwise """ + if profile is None: + # all profiles + retval = {} + return retval # TODO def clone(self, source, dest, hash=True): @@ -111,6 +120,9 @@ return profile['path'] def profile_dict(self, profile): + """ + return option dictionary for a single profile + """ parser = ConfigParser() parser.read(self.profiles) for section in parser.sections(): @@ -120,9 +132,30 @@ return dict(parser.items(section)) raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles)) + def profiles_dict(self): + """ + return nested dict of all profiles + """ + # XXX assumes profiles have unique names + parser = ConfigParser() + parser.read(self.profiles) + retval = {} + for section in parser.sections(): + if section == 'General': + continue + try: + name = parser.get(section, 'name') + except ConfigParser.NoOptionError: + continue + retval[name] = self.profile_dict(name) + return retval + + def hash(self): """ generate a random hash for a new profile """ # XXX right now this is completely fake return 'FOO' + +