Mercurial > mozilla > hg > ProfileManager
comparison profilemanager/manager.py @ 51:dc9324b52c2a
* add write convenience function
* finish backup method
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 07 May 2010 09:59:08 -0700 |
parents | 4cd6fc940407 |
children | 85b5fe402ab4 |
comparison
equal
deleted
inserted
replaced
50:4cd6fc940407 | 51:dc9324b52c2a |
---|---|
76 if section is None: | 76 if section is None: |
77 raise ProfileNotFound(profile, self.profiles) | 77 raise ProfileNotFound(profile, self.profiles) |
78 if delete: # remove the profile from disk | 78 if delete: # remove the profile from disk |
79 shutil.rmtree(self.path(name)) | 79 shutil.rmtree(self.path(name)) |
80 parser.remove_section(section) | 80 parser.remove_section(section) |
81 parser.write(file(self.profiles, 'w')) | 81 self.write(parser) |
82 | 82 |
83 def list(self, directories=False): | 83 def list(self, directories=False): |
84 """ | 84 """ |
85 lists the profiles available in the config file | 85 lists the profiles available in the config file |
86 - directories : display the directories | 86 - directories : display the directories |
150 | 150 |
151 # copy the files | 151 # copy the files |
152 self.clone(profile, dest, add=False) | 152 self.clone(profile, dest, add=False) |
153 | 153 |
154 | 154 |
155 # add backup entry to profiles.ini: | 155 # add backup entry to profiles.ini (colon separated): |
156 # `Backup=$(profile)s.$(datestamp)s.bak` | 156 # `Backup=$(profile)s.$(datestamp)s.bak` |
157 import pdb; pdb.set_trace() | 157 if parser.has_option(section, 'Backups'): |
158 raise NotImplementedError | 158 backups = '%s:%s' % (parser.get(section, 'Backups'), name) |
159 | 159 else: |
160 backups = name | |
161 parser.set(section, 'Backups', backups) | |
162 self.write(parser) | |
160 | 163 |
161 def backups(self, profile=None): | 164 def backups(self, profile=None): |
162 """ | 165 """ |
163 list backups for a given profile, or all profiles if the | 166 list backups for a given profile, or all profiles if the |
164 profile is not given; returns a list of backups if | 167 profile is not given; returns a list of backups if |
224 parser.set(section, 'Path', path) | 227 parser.set(section, 'Path', path) |
225 if not ctr: | 228 if not ctr: |
226 parser.set(section, 'Default', '1') | 229 parser.set(section, 'Default', '1') |
227 | 230 |
228 # write the file | 231 # write the file |
229 parser.write(file(self.profiles, 'w')) | 232 self.write(parser) |
230 | |
231 | 233 |
232 def path(self, profile): | 234 def path(self, profile): |
233 """returns the path to the profile""" | 235 """returns the path to the profile""" |
234 profile = self.profile_dict(profile) | 236 profile = self.profile_dict(profile) |
235 if profile.get('isrelative', None) == '1': | 237 if profile.get('isrelative', None) == '1': |
242 """ | 244 """ |
243 parser = ConfigParser() | 245 parser = ConfigParser() |
244 parser.read(self.profiles) | 246 parser.read(self.profiles) |
245 return parser | 247 return parser |
246 | 248 |
249 def write(self, parser): | |
250 f = file(self.profiles, 'w') | |
251 parser.write(f) | |
252 f.close() | |
247 | 253 |
248 def section(self, profile, parser=None): | 254 def section(self, profile, parser=None): |
249 """ | 255 """ |
250 returns the name of the section that a profile is in or None | 256 returns the name of the section that a profile is in or None |
251 if not found | 257 if not found |