comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:7301d534bc6c
1 """
2 manage Mozilla/Firefox profiles
3 """
4
5 import os
6 import shutil
7
8 from command import command
9
10 class ProfileNotFound(Exception):
11 """
12 exception when a profile is specified but is not present in a given
13 .ini file
14 """
15
16 class ProfileManager(object):
17
18 def __init__(self, profiles):
19 """
20 - profiles: profiles.ini file
21 """
22 self.profiles = profiles
23 self.directory = '' # TODO : path to self.profiles directory
24
25 ### (public) API
26
27 @command
28 def clone(self, source, dest):
29 """
30 clones the profile `source` and output to `dest`
31 """
32 source_path = self.path(source) # fs path of the `from` profile
33 dest_path = self.path(dest) # fs path to back up to
34 shutil.copytree(src_path, backup, symlinks=False)
35
36 @command
37 def backup(self, profile, dest=None):
38 """
39 backup the profile
40 - profile: name of the profile to be backed up
41 - dest: name of the destination (optional)
42 """
43 # XXX should use `self.clone` !
44 if dest is None:
45 dest = ''
46 self.clone(profile, dest)
47 # TODO: add something like
48 # `Backup=$(profile)s.$(datestamp)s.bak`
49 # to self.profiles
50
51 @command
52 def restore(self, profile, date=None, delete=False):
53 """
54 restore the profile from a backup
55 the most recent backup is used unless `date` is given
56 - date : date to restore from
57 - delete : delete the backup after restoration
58 """
59 if delete:
60 # delete the backup
61 pass
62
63 @command
64 def merge(self, *profiles):
65 """merge a set of profiles (not trivial!)"""
66 raise NotImplementedError
67
68 ### internal functions
69
70 def path(self, profile):
71 """returns the path to the profile"""
72