Mercurial > mozilla > hg > ProfileManager
annotate profilemanager/manager.py @ 64:18f16bd1ba6b
finish backups listing function and formatting for it
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 07 May 2010 12:23:49 -0700 |
parents | 2f58555b3b28 |
children | 1cd3e3c71bff |
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 |
15
543d08958b67
actually sample 8 random lowercase letters and numbers for the profile hash
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
7 import string |
50 | 8 import time |
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
|
9 import ConfigParser |
15
543d08958b67
actually sample 8 random lowercase letters and numbers for the profile hash
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
10 from random import Random |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
11 from utils import format_tabular |
59
ee2777913a9e
check the correct way to see if the option is there
Jeff Hammel <jhammel@mozilla.com>
parents:
58
diff
changeset
|
12 #from ConfigParser import NoOptionError |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
13 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
|
14 |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
15 # Changes to profiles.ini: |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
16 # - add a ``backups`` field for each profile: |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
17 # 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
|
18 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
19 class ProfileNotFound(Exception): |
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 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
|
22 .ini file |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
23 """ |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
24 def __init__(self, profile, config): |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
25 self.profile = profile |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
26 self.config = config |
57
3b4b87faa2a8
* make options case-sensitive
Jeff Hammel <jhammel@mozilla.com>
parents:
56
diff
changeset
|
27 Exception.__init__(self, |
3b4b87faa2a8
* make options case-sensitive
Jeff Hammel <jhammel@mozilla.com>
parents:
56
diff
changeset
|
28 'Profile %s not found in %s' % (profile, config)) |
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 class ProfileManager(object): |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
31 |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
32 backups_dir = 'backups' # directory for backups relative to profile_dir |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
33 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
34 def __init__(self, profiles): |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
35 """ |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
36 - 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
|
37 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
38 self.profiles = profiles |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
39 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
|
40 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
41 ### (public) API |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
42 |
16 | 43 def new(self, name, directory=None, hash=True): |
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 """ |
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
|
45 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
|
46 - name: name of the profile to generate |
16 | 47 - directory: where to create the profile [DEFAULT: relative to profiles.ini] |
48 - hash: whether to generate a a random hash tag | |
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
|
49 """ |
16 | 50 |
51 # path to the profile directory | |
20 | 52 dirname = name |
53 relative = False | |
16 | 54 if hash: |
18
8e651dd8e9ad
fix two things about hash() usage
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
55 dirname = '%s.%s' % (self.hash(), dirname) |
16 | 56 if not directory: |
57 directory = self.profile_dir | |
20 | 58 relative = True |
59 path = os.path.join(directory, dirname) | |
16 | 60 |
61 # create directory | |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
62 # TODO: (optionally) pre-populate the directory a la Firefox |
20 | 63 os.mkdir(path) |
16 | 64 |
19
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
65 # update profiles.ini |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
66 self.add(name, relative and dirname or path, relative) |
19
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
67 |
16 | 68 # return the directory name |
36
a6222b71aab6
return the right thing, finally
Jeff Hammel <jhammel@mozilla.com>
parents:
31
diff
changeset
|
69 return path |
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
|
70 |
19
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
71 def remove(self, name, delete=True): |
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
72 """ |
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
73 remove a profile from profiles.ini |
20 | 74 - delete: delete the profile directory as well |
19
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
75 """ |
37 | 76 parser = self.parser() |
77 section = self.section(name, parser) | |
21
15484adb9758
note what section a a profile is in
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
78 if section is None: |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
79 raise ProfileNotFound(profile, self.profiles) |
22
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
80 if delete: # remove the profile from disk |
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
81 shutil.rmtree(self.path(name)) |
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
82 parser.remove_section(section) |
51
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
83 self.write(parser) |
19
4a1815f8d146
* stub adding new profile to configuration
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
84 |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
85 def list(self, directories=False): |
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
86 """ |
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
87 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
|
88 - directories : display the directories |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
89 """ |
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
|
90 profiles = self.profiles_dict() |
38 | 91 if not directories: |
92 return sorted(profiles.keys()) | |
93 return dict([(name, self.path(name)) for name in profiles.keys()]) | |
4
35dc297efa25
adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
94 |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
95 def clone(self, source, dest, add=True): |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
96 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
97 clones the profile `source` and output to `dest` |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
98 - add: add the profile to the profiles.ini file |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
99 """ |
45 | 100 |
101 # filesystem path of the `from` profile | |
102 source_path = self.path(source) | |
7
d3b22d086934
comments for what to do next
Jeff Hammel <jhammel@mozilla.com>
parents:
6
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 # 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
|
105 relative = False |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
106 if os.path.sep in dest: |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
107 if not os.path.isabs(dest): |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
108 dest = os.path.abspath(dest) |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
109 dirname = dest |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
110 name = os.path.basename(dest) |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
111 else: |
46
df1b2e48dddb
handle hashing for clones only if they are added to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
45
diff
changeset
|
112 name = dest |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
113 relative = True |
46
df1b2e48dddb
handle hashing for clones only if they are added to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
45
diff
changeset
|
114 if add: |
df1b2e48dddb
handle hashing for clones only if they are added to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
45
diff
changeset
|
115 dirname = '%s.%s' % (self.hash(), name) |
48
09a2666999fa
* restore profiles.ini to base in tests
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
116 dest = os.path.join(self.profile_dir, dirname) |
7
d3b22d086934
comments for what to do next
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
117 |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
118 # update profiles.ini |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
119 if add: |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
120 self.add(name, dirname, relative) |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
121 |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
122 # copy the files |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
123 shutil.copytree(source_path, dest, symlinks=False) |
43 | 124 |
125 return dest | |
1
979315ed0816
mucho cleanup on optionparser stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
126 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
127 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
|
128 """ |
56 | 129 backup a profile |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
130 - profile: name of the profile to be backed up |
56 | 131 - dest: name of the destination; if not given, a default is used |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
132 """ |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
133 |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
134 # get the profile section |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
135 parser = self.parser() |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
136 section = self.section(profile) |
58
ce6a101fb239
check for section; of course profile will not be none
Jeff Hammel <jhammel@mozilla.com>
parents:
57
diff
changeset
|
137 if section is None: |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
138 raise ProfileNotFound(profile, self.profiles) |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
139 |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
140 # determine destination directory |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
141 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
|
142 dest = '%s.%d.bak' % (profile, int(time.time())) |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
143 name = dest |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
144 backups_dir = os.path.join(self.profile_dir, self.backups_dir) |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
145 if not os.path.exists(backups_dir): |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
146 os.mkdir(backups_dir) |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
147 dest = os.path.join(backups_dir, dest) |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
148 else: |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
149 if not os.path.isabs(dest): |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
150 dest = os.path.abspath(dest) |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
151 name = dest |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
152 |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
153 # copy the files |
45 | 154 self.clone(profile, dest, add=False) |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
155 |
51
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
156 # add backup entry to profiles.ini (colon separated): |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
157 # `Backup=$(profile)s.$(datestamp)s.bak` |
51
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
158 if parser.has_option(section, 'Backups'): |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
159 backups = '%s:%s' % (parser.get(section, 'Backups'), name) |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
160 else: |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
161 backups = name |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
162 parser.set(section, 'Backups', backups) |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
163 self.write(parser) |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
164 |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
165 def backups(self, profile=None, datestamp=None): |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
166 """ |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
167 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
|
168 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
|
169 profile is given or a dictionary of lists otherwise |
53
c279d2797d45
document datestamp argument
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
170 - datestamp: format of date; otherwise, seconds since epoch |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
171 """ |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
172 if profile is None: # all profiles |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
173 # XXX this should probably be recursive |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
174 retval = {} |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
175 profiles_dict = self.profiles_dict() |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
176 for profile in profiles_dict: |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
177 if 'Backups' in profiles_dict[profile]: |
64
18f16bd1ba6b
finish backups listing function and formatting for it
Jeff Hammel <jhammel@mozilla.com>
parents:
63
diff
changeset
|
178 retval[profile] = self.backups(profile, datestamp) |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
179 return retval |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
180 |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
181 # single profile |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
182 profile_dict = self.profile_dict(profile) |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
183 if 'Backups' not in profile_dict: |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
184 return [] |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
185 backups = profile_dict['Backups'].split(':') |
63 | 186 backups_dirs = [] |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
187 for backup in backups: |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
188 if os.path.isabs(backup): |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
189 backup_dir = backup |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
190 else: |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
191 backup_dir = os.path.join(self.profile_dir, self.backups_dir, backup) |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
192 backups_dirs.append((backup, int(os.path.getmtime(backup_dir)))) |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
193 # TODO: check if the getmtime == the datestamp for relative backups |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
194 |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
195 # sort by reverse datestamp |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
196 backups_dirs.sort(key=lambda x: x[1], reverse=True) |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
197 |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
198 # format to datestamps, if applicable |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
199 if datestamp: |
63 | 200 backups_dirs = [ (i[0], time.strftime(datestamp, |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
201 time.localtime(int(i[1])))) |
63 | 202 for i in backups_dirs ] |
52
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
203 |
85b5fe402ab4
finish backups functionality (to test)
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
204 return backups_dirs |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
205 |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
206 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
|
207 """ |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
208 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
|
209 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
|
210 - 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
|
211 - 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
|
212 """ |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
213 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
214 # get the possible backups |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
215 backups = self.backups(profile) |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
216 # 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
|
217 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
218 # 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
|
219 |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
220 if delete: # delete the backup |
10
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
221 # delete the directory |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
222 # delete the entry from ``profiles.ini`` |
c77e9bef78d6
* update list of public API functions
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
223 # 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
|
224 pass #TODO |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
225 |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
226 def temporary(self): |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
227 """make a temporary profile""" |
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
228 raise NotImplementedError |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
229 |
5
ca57920aa223
adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
230 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
|
231 """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
|
232 raise NotImplementedError |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
233 |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
234 ### internal functions |
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
235 |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
236 def add(self, profile, path, relative=True): |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
237 """ |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
238 add a profile entry to profiles.ini |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
239 """ |
41 | 240 |
241 # ensure name is not already present | |
242 assert profile not in self.profiles_dict(), 'Profile "%s" already in %s' % (name, self.profiles) | |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
243 parser = self.parser() |
41 | 244 |
245 # find and add the section | |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
246 ctr = 0 |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
247 section = 'Profile%d' % ctr # unsure of this naming convention |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
248 while section in parser.sections(): |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
249 ctr += 1 |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
250 section = 'Profile%d' % ctr |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
251 parser.add_section(section) |
41 | 252 |
253 # add metadata | |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
254 parser.set(section, 'Name', profile) |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
255 parser.set(section, 'IsRelative', '%d' % int(relative)) |
42 | 256 parser.set(section, 'Path', path) |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
257 if not ctr: |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
258 parser.set(section, 'Default', '1') |
41 | 259 |
260 # write the file | |
51
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
261 self.write(parser) |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
262 |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
263 def path(self, profile): |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
264 """returns the path to the profile""" |
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
265 profile = self.profile_dict(profile) |
62 | 266 if profile.get('IsRelative', None) == '1': |
267 return os.path.join(self.profile_dir, profile['Path']) | |
268 return profile['Path'] | |
40
34c740d1962d
abstract out adding an entry to profiles.ini
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
269 |
22
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
270 def parser(self): |
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
271 """ |
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
272 return a ConfigParser instance appropriate to profiles.ini |
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
273 """ |
25
fc31d3f26755
i seriously need to learn to code
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
274 parser = ConfigParser() |
57
3b4b87faa2a8
* make options case-sensitive
Jeff Hammel <jhammel@mozilla.com>
parents:
56
diff
changeset
|
275 parser.optionxform = str |
25
fc31d3f26755
i seriously need to learn to code
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
276 parser.read(self.profiles) |
fc31d3f26755
i seriously need to learn to code
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
277 return parser |
22
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
278 |
51
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
279 def write(self, parser): |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
280 f = file(self.profiles, 'w') |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
281 parser.write(f) |
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
282 f.close() |
0
7301d534bc6c
initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
283 |
22
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
284 def section(self, profile, parser=None): |
20 | 285 """ |
21
15484adb9758
note what section a a profile is in
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
286 returns the name of the section that a profile is in or None |
15484adb9758
note what section a a profile is in
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
287 if not found |
20 | 288 """ |
22
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
289 if parser is None: |
29 | 290 parser = self.parser() |
31 | 291 for section in parser.sections(): |
61
24782e4c70ca
now that we are case sensitive, correct case for getting options
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
292 if not parser.has_option(section, 'Name'): |
21
15484adb9758
note what section a a profile is in
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
293 continue # not a profile |
61
24782e4c70ca
now that we are case sensitive, correct case for getting options
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
294 if parser.get(section, 'Name') == profile: |
21
15484adb9758
note what section a a profile is in
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
295 return section |
20 | 296 |
27
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
297 def profile_dict(self, profile): |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
298 """ |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
299 return option dictionary for a single profile |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
300 """ |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
301 parser = self.parser() |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
302 section = self.section(profile, parser) |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
303 if section is None: |
47
420becb84df7
* move exception string to the exception itself
Jeff Hammel <jhammel@mozilla.com>
parents:
46
diff
changeset
|
304 raise ProfileNotFound(profile, self.profiles) |
27
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
305 return dict(parser.items(section)) |
5988a15da3b4
things are being awful; checking in anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
26
diff
changeset
|
306 |
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
|
307 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
|
308 """ |
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
|
309 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
|
310 """ |
22
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
311 # assumes profiles have unique names |
956f5a4c589a
* restructure utility functions to do less more efficiently
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
312 parser = self.parser() |
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
|
313 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
|
314 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
|
315 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
|
316 continue |
59
ee2777913a9e
check the correct way to see if the option is there
Jeff Hammel <jhammel@mozilla.com>
parents:
58
diff
changeset
|
317 if not parser.has_option(section, 'Name'): |
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
|
318 continue |
61
24782e4c70ca
now that we are case sensitive, correct case for getting options
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
319 name = parser.get(section, 'Name') |
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
|
320 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
|
321 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
|
322 |
8
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
323 def hash(self): |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
324 """ |
7205cb6f5530
various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
325 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
|
326 """ |
15
543d08958b67
actually sample 8 random lowercase letters and numbers for the profile hash
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
327 population = string.lowercase + string.digits |
18
8e651dd8e9ad
fix two things about hash() usage
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
328 return ''.join(Random().sample(population, 8)) |
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
|
329 |
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
|
330 |