diff profilemanager/manager.py @ 8:7205cb6f5530

various flushing out, deleting old TODOs and making new ones
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 13 Apr 2010 19:24:52 -0700
parents d3b22d086934
children b1274abd1206
line wrap: on
line diff
--- a/profilemanager/manager.py	Tue Apr 06 10:46:16 2010 -0700
+++ b/profilemanager/manager.py	Tue Apr 13 19:24:52 2010 -0700
@@ -42,20 +42,31 @@
             retval.append(values)
         return format_tabular(retval)
 
-    def clone(self, source, dest):
+    def backups(self, profile=None):
+        """
+        list backups for a given profile, or all profiles if the
+        profile is not given
+        """
+        # TODO
+
+    def clone(self, source, dest, hash=True):
         """
         clones the profile `source` and output to `dest`
         """
         source_path = self.path(source)    # fs path of the `from` profile
 
-        dest_path = self.path(dest)  # fs path to back up to
-        # TODO:  prepend a hash key
+        # dest: fs path to back up to
+        relative = False
+        if not os.path.isabs(dest):
+            relative = True
+            if not os.path.dirname(dest):
+                dest = '%s.%s' % (self.hash(), dest)
+            dest = os.path.join(self.profile_dir, dest)
 
-        shutil.copytree(source_path, dest_path, symlinks=False)
-
-        # update profiles.ini
-        # TODO
-
+        shutil.copytree(source_path, dest, symlinks=False)
+        
+        # TODO: update profiles.ini
+        
 
     def backup(self, profile, dest=None):
         """
@@ -63,10 +74,9 @@
         - profile: name of the profile to be backed up
         - dest: name of the destination (optional)
         """
-        # XXX should use `self.clone` !
         if dest is None:
-            dest = ''
-        self.clone(profile, dest)
+            dest = '%s.%d.bak' % (profile, int(time.time()))
+        self.clone(profile, dest, hash=False)
         # TODO: add something like
         # `Backup=$(profile)s.$(datestamp)s.bak`
         # to self.profiles
@@ -78,8 +88,13 @@
         - date : date to restore from
         - delete : delete the backup after restoration
         """
-        if delete:
-            # delete the backup
+
+        # get the possible backups
+        # TODO
+
+        # restore the backup over ``profile``
+
+        if delete: # delete the backup
             pass
 
     def merge(self, output, *profiles):
@@ -104,3 +119,10 @@
             if parser.get(section, 'name') == profile:
                 return dict(parser.items(section))
         raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))
+
+    def hash(self):
+        """
+        generate a random hash for a new profile
+        """
+        # XXX right now this is completely fake
+        return 'FOO'