comparison profilemanager/manager.py @ 57:3b4b87faa2a8

* make options case-sensitive * pass the child as an instance to the parent ctor for ProfileNotFound
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 May 2010 11:52:06 -0700
parents 2dde7dcc899e
children ce6a101fb239
comparison
equal deleted inserted replaced
56:2dde7dcc899e 57:3b4b87faa2a8
21 .ini file 21 .ini file
22 """ 22 """
23 def __init__(self, profile, config): 23 def __init__(self, profile, config):
24 self.profile = profile 24 self.profile = profile
25 self.config = config 25 self.config = config
26 Exception.__init__('Profile %s not found in %s' % (profile, config)) 26 Exception.__init__(self,
27 'Profile %s not found in %s' % (profile, config))
27 28
28 class ProfileManager(object): 29 class ProfileManager(object):
29 30
30 backups_dir = 'backups' # directory for backups relative to profile_dir 31 backups_dir = 'backups' # directory for backups relative to profile_dir
31 32
148 dest = os.path.abspath(dest) 149 dest = os.path.abspath(dest)
149 name = dest 150 name = dest
150 151
151 # copy the files 152 # copy the files
152 self.clone(profile, dest, add=False) 153 self.clone(profile, dest, add=False)
153
154 154
155 # add backup entry to profiles.ini (colon separated): 155 # add backup entry to profiles.ini (colon separated):
156 # `Backup=$(profile)s.$(datestamp)s.bak` 156 # `Backup=$(profile)s.$(datestamp)s.bak`
157 if parser.has_option(section, 'Backups'): 157 if parser.has_option(section, 'Backups'):
158 backups = '%s:%s' % (parser.get(section, 'Backups'), name) 158 backups = '%s:%s' % (parser.get(section, 'Backups'), name)
269 def parser(self): 269 def parser(self):
270 """ 270 """
271 return a ConfigParser instance appropriate to profiles.ini 271 return a ConfigParser instance appropriate to profiles.ini
272 """ 272 """
273 parser = ConfigParser() 273 parser = ConfigParser()
274 parser.optionxform = str
274 parser.read(self.profiles) 275 parser.read(self.profiles)
275 return parser 276 return parser
276 277
277 def write(self, parser): 278 def write(self, parser):
278 f = file(self.profiles, 'w') 279 f = file(self.profiles, 'w')
317 except ConfigParser.NoOptionError: 318 except ConfigParser.NoOptionError:
318 continue 319 continue
319 retval[name] = self.profile_dict(name) 320 retval[name] = self.profile_dict(name)
320 return retval 321 return retval
321 322
322
323 def hash(self): 323 def hash(self):
324 """ 324 """
325 generate a random hash for a new profile 325 generate a random hash for a new profile
326 """ 326 """
327 population = string.lowercase + string.digits 327 population = string.lowercase + string.digits