annotate profilemanager/manager.py @ 2:fc0dabd2269f

add README
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 05 Apr 2010 09:27:23 -0700
parents 979315ed0816
children 4d1cd60dd2a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 manage Mozilla/Firefox profiles
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 import os
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 import shutil
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 from command import command
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 class ProfileNotFound(Exception):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 exception when a profile is specified but is not present in a given
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 .ini file
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 class ProfileManager(object):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 def __init__(self, profiles):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 - profiles: profiles.ini file
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 self.profiles = profiles
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 self.directory = '' # TODO : path to self.profiles directory
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 ### (public) API
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 def clone(self, source, dest):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 clones the profile `source` and output to `dest`
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 source_path = self.path(source) # fs path of the `from` profile
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 dest_path = self.path(dest) # fs path to back up to
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 shutil.copytree(src_path, backup, symlinks=False)
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34
1
979315ed0816 mucho cleanup on optionparser stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
35
0
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 def backup(self, profile, dest=None):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 backup the profile
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 - profile: name of the profile to be backed up
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
40 - dest: name of the destination (optional)
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42 # XXX should use `self.clone` !
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43 if dest is None:
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
44 dest = ''
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
45 self.clone(profile, dest)
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
46 # TODO: add something like
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
47 # `Backup=$(profile)s.$(datestamp)s.bak`
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
48 # to self.profiles
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
49
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
50 def restore(self, profile, date=None, delete=False):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
51 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
52 restore the profile from a backup
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
53 the most recent backup is used unless `date` is given
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
54 - date : date to restore from
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
55 - delete : delete the backup after restoration
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
56 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
57 if delete:
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
58 # delete the backup
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
59 pass
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
60
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
61 def merge(self, *profiles):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
62 """merge a set of profiles (not trivial!)"""
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
63 raise NotImplementedError
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
64
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
65 ### internal functions
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
66
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
67 def path(self, profile):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
68 """returns the path to the profile"""
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
69