diff profilemanager/manager.py @ 47:420becb84df7

* move exception string to the exception itself * further stubbing on backup * stub on temporary profile function
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 May 2010 09:06:16 -0700
parents df1b2e48dddb
children 09a2666999fa
line wrap: on
line diff
--- a/profilemanager/manager.py	Thu May 06 19:05:28 2010 -0700
+++ b/profilemanager/manager.py	Fri May 07 09:06:16 2010 -0700
@@ -19,9 +19,15 @@
     exception when a profile is specified but is not present in a given
     .ini file
     """
+    def __init__(self, profile, config):
+        self.profile = profile
+        self.config = config
+        Exception.__init__('Profile %s not found in %s' % (profile, config))
 
 class ProfileManager(object):
 
+    backups_dir = 'backups' # directory for backups relative to profile_dir
+
     def __init__(self, profiles):
         """
         - profiles: filesystem path to profiles.ini file
@@ -67,7 +73,7 @@
         parser = self.parser()
         section = self.section(name, parser)
         if section is None:
-            raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))
+            raise ProfileNotFound(profile, self.profiles)
         if delete: # remove the profile from disk
             shutil.rmtree(self.path(name))
         parser.remove_section(section)
@@ -121,12 +127,34 @@
         - profile: name of the profile to be backed up
         - dest: name of the destination (optional)
         """
+
+        # get the profile section
+        parser = self.parser()
+        section = self.section(profile)
+        if profile is None:
+            raise ProfileNotFound(profile, self.profiles)
+
+        # determine destination directory
         if dest is None:
             dest = '%s.%d.bak' % (profile, int(time.time()))
+            name = dest
+            backups_dir = os.path.join(self.profile_dir, self.backups_dir)
+            if not os.path.exists(backups_dir):
+                os.mkdir(backups_dir)
+            dest = os.path.join(backups_dir, dest)
+        else:
+            if not os.path.isabs(dest):
+                dest = os.path.abspath(dest)
+            name = dest
+
+        # copy the files
         self.clone(profile, dest, add=False)
-        # TODO: add something like
+
+        
+        # add backup entry to profiles.ini:
         # `Backup=$(profile)s.$(datestamp)s.bak`
-        # to self.profiles
+        raise NotImplementedError
+
 
     def backups(self, profile=None):
         """
@@ -139,6 +167,7 @@
             retval = {}
             return retval
         # TODO
+        raise NotImplementedError
 
     def restore(self, profile, date=None, delete=False):
         """
@@ -159,7 +188,10 @@
             # delete the entry from ``profiles.ini``
             # if there are no backups, delete the ``backups`` line
             pass #TODO
-        
+
+    def temporary(self):
+        """make a temporary profile"""
+        raise NotImplementedError
 
     def merge(self, output, *profiles):
         """merge a set of profiles (not trivial!)"""
@@ -231,7 +263,7 @@
         parser = self.parser()
         section = self.section(profile, parser)
         if section is None:
-            raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))
+            raise ProfileNotFound(profile, self.profiles)
         return dict(parser.items(section))
 
     def profiles_dict(self):