annotate profilemanager/manager.py @ 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
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 14 Apr 2010 16:07:20 -0700
parents 7205cb6f5530
children c77e9bef78d6
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
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
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 class ProfileNotFound(Exception):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 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
14 .ini file
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
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 class ProfileManager(object):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 def __init__(self, profiles):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 """
4
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
21 - 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
22 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 self.profiles = profiles
4
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
24 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
25
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 ### (public) API
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27
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
28 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
29 """
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
30 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
31 - 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
32 """
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 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
34
4
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
35 def list(self, directories=False):
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
36 """
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
37 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
38 - directories : display the directories
4
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
39 """
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
40 profiles = self.profiles_dict()
6
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
41 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
42 for name in sorted(profiles.keys()):
6
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
43 values = [name]
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
44 if directories:
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
45 values.append(self.path(name))
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
46 retval.append(values)
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
47 return format_tabular(retval)
4
35dc297efa25 adding listing function and other cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
48
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
49 def backups(self, profile=None):
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
50 """
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
51 list backups for a given profile, or all profiles if the
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
52 profile is not given; returns a list of backups if
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
53 profile is given or a dictionary of lists otherwise
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
54 """
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
55 if profile is None:
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
56 # 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
57 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
58 return retval
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
59 # TODO
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
60
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
61 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
62 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
63 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
64 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
65 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
66
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
67 # 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
68 relative = False
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
69 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
70 relative = True
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
71 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
72 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
73 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
74
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
75 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
76
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
77 # TODO: update profiles.ini
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
78
1
979315ed0816 mucho cleanup on optionparser stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
79
0
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
80 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
81 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
82 backup the profile
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
83 - 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
84 - 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
85 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
86 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
87 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
88 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
89 # TODO: add something like
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
90 # `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
91 # to self.profiles
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
92
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
93 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
94 """
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
95 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
96 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
97 - 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
98 - 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
99 """
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
100
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
101 # get the possible backups
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
102 # TODO
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
103
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
104 # 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
105
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
106 if delete: # delete the backup
0
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
107 pass
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
108
5
ca57920aa223 adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
109 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
110 """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
111 raise NotImplementedError
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
112
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
113 ### internal functions
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
114
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
115 def path(self, profile):
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
116 """returns the path to the profile"""
6
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
117 profile = self.profile_dict(profile)
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
118 if profile.get('isrelative', None) == '1':
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
119 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
120 return profile['path']
0
7301d534bc6c initial messy and incomplete strawman prototype for Mozilla (Firefox) profile management
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
121
5
ca57920aa223 adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
122 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
123 """
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
124 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
125 """
5
ca57920aa223 adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
126 parser = ConfigParser()
ca57920aa223 adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
127 parser.read(self.profiles)
ca57920aa223 adding better formatting for list
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
128 for section in parser.sections():
6
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
129 if not parser.has_option(section, 'name'):
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
130 continue # not a profile
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
131 if parser.get(section, 'name') == profile:
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
132 return dict(parser.items(section))
2a3f5cdfd60c flush out helper functions and list directories
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
133 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
134
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
135 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
136 """
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
137 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
138 """
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
139 # 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152
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
8
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
154 def hash(self):
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
155 """
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
156 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
157 """
7205cb6f5530 various flushing out, deleting old TODOs and making new ones
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
158 # 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
159 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
160
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