# HG changeset patch # User Jeff Hammel # Date 1273251548 25200 # Node ID dc9324b52c2aea376ccf01dc566083e04e34e1c2 # Parent 4cd6fc94040723063a1a498a081ca835892b522a * add write convenience function * finish backup method diff -r 4cd6fc940407 -r dc9324b52c2a profilemanager/manager.py --- a/profilemanager/manager.py Fri May 07 09:43:35 2010 -0700 +++ b/profilemanager/manager.py Fri May 07 09:59:08 2010 -0700 @@ -78,7 +78,7 @@ if delete: # remove the profile from disk shutil.rmtree(self.path(name)) parser.remove_section(section) - parser.write(file(self.profiles, 'w')) + self.write(parser) def list(self, directories=False): """ @@ -152,11 +152,14 @@ self.clone(profile, dest, add=False) - # add backup entry to profiles.ini: + # add backup entry to profiles.ini (colon separated): # `Backup=$(profile)s.$(datestamp)s.bak` - import pdb; pdb.set_trace() - raise NotImplementedError - + if parser.has_option(section, 'Backups'): + backups = '%s:%s' % (parser.get(section, 'Backups'), name) + else: + backups = name + parser.set(section, 'Backups', backups) + self.write(parser) def backups(self, profile=None): """ @@ -226,8 +229,7 @@ parser.set(section, 'Default', '1') # write the file - parser.write(file(self.profiles, 'w')) - + self.write(parser) def path(self, profile): """returns the path to the profile""" @@ -244,6 +246,10 @@ parser.read(self.profiles) return parser + def write(self, parser): + f = file(self.profiles, 'w') + parser.write(f) + f.close() def section(self, profile, parser=None): """ diff -r 4cd6fc940407 -r dc9324b52c2a profilemanager/tests/test.py --- a/profilemanager/tests/test.py Fri May 07 09:43:35 2010 -0700 +++ b/profilemanager/tests/test.py Fri May 07 09:59:08 2010 -0700 @@ -34,7 +34,7 @@ # Backup the profile manager.backup('testprofile') -manager.restore('testprofile') +# TODO: manager.restore('testprofile') # Cleanup: manager.remove('testprofile')