Mercurial > mozilla > hg > ProfileManager
annotate profilemanager/manager.py @ 10:c77e9bef78d6
* update list of public API functions
* further flushing out of profile manager
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 05 May 2010 17:08:47 -0700 |
parents | b1274abd1206 |
children | 543d08958b67 |
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 |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
7 import ConfigParser |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
8 from utils import format_tabular |
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
9 from ConfigParser import SafeConfigParser as ConfigParser |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
10 |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
11 # Changes to profiles.ini: |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
12 # - add a ``backups`` field for each profile: |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
13 # Backups = /path/to/backup:1273104310 /path/to/other/backup:1273104355 |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
14 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
15 class ProfileNotFound(Exception): |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
16 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
17 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
|
18 .ini file |
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 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
21 class ProfileManager(object): |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
22 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
23 def __init__(self, profiles): |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
24 """ |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
25 - profiles: filesystem path to profiles.ini file |
0
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 self.profiles = profiles |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
28 self.profile_dir = os.path.abspath(os.path.dirname(profiles)) |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
29 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
30 ### (public) API |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
31 |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
32 def new(self, name): |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
33 """ |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
34 generate a new clean profile |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
35 - name: name of the profile to generate |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
36 """ |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
37 raise NotImplementedError |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
38 |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
39 def list(self, directories=False): |
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
40 """ |
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
41 lists the profiles available in the config file |
6
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
42 - directories : display the directories |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
43 """ |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
44 profiles = self.profiles_dict() |
6
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
45 retval = [] |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
46 for name in sorted(profiles.keys()): |
6
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
47 values = [name] |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
48 if directories: |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
49 values.append(self.path(name)) |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
50 retval.append(values) |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
51 return format_tabular(retval) |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
52 |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
53 def clone(self, source, dest, hash=True): |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
54 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
55 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
|
56 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
57 source_path = self.path(source) # fs path of the `from` profile |
7
d3b22d086934
comments for what to do next
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
58 |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
59 # dest: fs path to back up to |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
60 relative = False |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
61 if not os.path.isabs(dest): |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
62 relative = True |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
63 if not os.path.dirname(dest): |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
64 dest = '%s.%s' % (self.hash(), dest) |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
65 dest = os.path.join(self.profile_dir, dest) |
7
d3b22d086934
comments for what to do next
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
66 |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
67 shutil.copytree(source_path, dest, symlinks=False) |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
68 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
69 # TODO: update profiles.ini |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
70 |
1
979315ed0816
mucho cleanup on optionparser stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
71 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
72 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
|
73 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
74 backup the profile |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
75 - 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
|
76 - 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
|
77 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
78 if dest is None: |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
79 dest = '%s.%d.bak' % (profile, int(time.time())) |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
80 self.clone(profile, dest, hash=False) |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
81 # TODO: add something like |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
82 # `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
|
83 # to self.profiles |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
84 |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
85 def backups(self, profile=None): |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
86 """ |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
87 list backups for a given profile, or all profiles if the |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
88 profile is not given; returns a list of backups if |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
89 profile is given or a dictionary of lists otherwise |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
90 """ |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
91 if profile is None: |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
92 # all profiles |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
93 retval = {} |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
94 return retval |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
95 # TODO |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
96 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
97 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
|
98 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 - 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
|
102 - 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
|
103 """ |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
104 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
105 # get the possible backups |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
106 backups = self.backups(profile) |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
107 # TODO: check to see if these all exist (print warnings if not) |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
108 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
109 # restore the backup over ``profile`` |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
110 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
111 if delete: # delete the backup |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
112 # delete the directory |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
113 # delete the entry from ``profiles.ini`` |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
114 # if there are no backups, delete the ``backups`` line |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
115 pass #TODO |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
116 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
117 |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
118 def merge(self, output, *profiles): |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
119 """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
|
120 raise NotImplementedError |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
121 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
122 ### internal functions |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
123 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
124 def path(self, profile): |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
125 """returns the path to the profile""" |
6
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
126 profile = self.profile_dict(profile) |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
127 if profile.get('isrelative', None) == '1': |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
128 return os.path.join(self.profile_dir, profile['path']) |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
129 return profile['path'] |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
130 |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
131 def profile_dict(self, profile): |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
132 """ |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
133 return option dictionary for a single profile |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
134 """ |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
135 parser = ConfigParser() |
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
136 parser.read(self.profiles) |
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
137 for section in parser.sections(): |
6
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
138 if not parser.has_option(section, 'name'): |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
139 continue # not a profile |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
140 if parser.get(section, 'name') == profile: |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
141 return dict(parser.items(section)) |
2a3f5cdfd60c
flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
142 raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles)) |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
143 |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
144 def profiles_dict(self): |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
145 """ |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
146 return nested dict of all profiles |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
147 """ |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
148 # XXX assumes profiles have unique names |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
149 parser = ConfigParser() |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
150 parser.read(self.profiles) |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
151 retval = {} |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
152 for section in parser.sections(): |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
153 if section == 'General': |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
154 continue |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
155 try: |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
156 name = parser.get(section, 'name') |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
157 except ConfigParser.NoOptionError: |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
158 continue |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
159 retval[name] = self.profile_dict(name) |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
160 return retval |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
161 |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
162 |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
163 def hash(self): |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
164 """ |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
165 generate a random hash for a new profile |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
166 """ |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
167 # XXX right now this is completely fake |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
168 return 'FOO' |
9
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
169 |
b1274abd1206
rework API a bit; the "public" methods are becoming a bit specialized to the command line, which was my fear, so I should probably inherit from ProfileManager to do the interface like I should
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
170 |