diff profilemanager/manager.py @ 0:7301d534bc6c

initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
author Jeff Hammel <k0scist@gmail.com>
date Sun, 04 Apr 2010 18:49:55 -0400
parents
children 979315ed0816
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profilemanager/manager.py	Sun Apr 04 18:49:55 2010 -0400
@@ -0,0 +1,72 @@
+"""
+manage Mozilla/Firefox profiles
+"""
+
+import os
+import shutil
+
+from command import command
+
+class ProfileNotFound(Exception):
+    """
+    exception when a profile is specified but is not present in a given
+    .ini file
+    """
+
+class ProfileManager(object):
+
+    def __init__(self, profiles):
+        """
+        - profiles: profiles.ini file
+        """
+        self.profiles = profiles
+        self.directory = '' # TODO : path to self.profiles directory
+
+    ### (public) API
+
+    @command
+    def clone(self, source, dest):
+        """
+        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
+        shutil.copytree(src_path, backup, symlinks=False)
+
+    @command
+    def backup(self, profile, dest=None):
+        """
+        backup the profile
+        - 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)
+        # TODO: add something like
+        # `Backup=$(profile)s.$(datestamp)s.bak`
+        # to self.profiles
+
+    @command
+    def restore(self, profile, date=None, delete=False):
+        """
+        restore the profile from a backup
+        the most recent backup is used unless `date` is given
+        - date : date to restore from
+        - delete : delete the backup after restoration
+        """
+        if delete:
+            # delete the backup
+            pass
+
+    @command
+    def merge(self, *profiles):
+        """merge a set of profiles (not trivial!)"""
+        raise NotImplementedError
+
+    ### internal functions
+
+    def path(self, profile):
+        """returns the path to the profile"""
+