changeset 51:dc9324b52c2a

* add write convenience function * finish backup method
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 May 2010 09:59:08 -0700
parents 4cd6fc940407
children 85b5fe402ab4
files profilemanager/manager.py profilemanager/tests/test.py
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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):
         """
--- 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')