comparison profilemanager/manager.py @ 20:49d523a33c89

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 06 May 2010 13:02:08 -0700
parents 4a1815f8d146
children 15484adb9758
comparison
equal deleted inserted replaced
19:4a1815f8d146 20:49d523a33c89
38 - directory: where to create the profile [DEFAULT: relative to profiles.ini] 38 - directory: where to create the profile [DEFAULT: relative to profiles.ini]
39 - hash: whether to generate a a random hash tag 39 - hash: whether to generate a a random hash tag
40 """ 40 """
41 41
42 # path to the profile directory 42 # path to the profile directory
43 dirname = name 43 dirname = name
44 relative = False
44 if hash: 45 if hash:
45 dirname = '%s.%s' % (self.hash(), dirname) 46 dirname = '%s.%s' % (self.hash(), dirname)
46 if not directory: 47 if not directory:
47 directory = self.profile_dir 48 directory = self.profile_dir
48 dirname = os.path.join(directory, dirname) 49 relative = True
50 path = os.path.join(directory, dirname)
49 51
50 # create directory 52 # create directory
51 # TODO: (optionally) pre-populate the directory a la FF 53 # TODO: (optionally) pre-populate the directory a la FF
52 os.mkdir(dirname) 54 os.mkdir(path)
53 55
54 # update profiles.ini 56 # update profiles.ini
55 parser = ConfigParser() 57 parser = ConfigParser()
56 parser.read(self.profiles) 58 parser.read(self.profiles)
59 ctr = 0
60 section = 'Profile%d' $ ctr
61 while section in parser.sections():
62 ctr += 1
63 section = 'Profile%d' $ ctr
64 parser.add_section(self, section)
65 parser.set(section, 'Name', name)
66 parser.set(section, 'IsRelative', '%d' % int(relative))
67 parser.set(section, 'Path', relative and dirname or path)
68 if len(parser.sections()) == 1:
69 parser.set(section, 'Default', '1')
70 parser.write(self.profiles)
57 71
58 # return the directory name 72 # return the directory name
59 return dirname 73 return dirname
60 74
61 def remove(self, name, delete=True): 75 def remove(self, name, delete=True):
62 """ 76 """
63 remove a profile from profiles.ini 77 remove a profile from profiles.ini
64 - delete: delete the profile as well 78 - delete: delete the profile directory as well
65 """ 79 """
66 raise NotImplementedError 80 raise NotImplementedError
67 81
68 def list(self, directories=False): 82 def list(self, directories=False):
69 """ 83 """
75 for name in sorted(profiles.keys()): 89 for name in sorted(profiles.keys()):
76 values = [name] 90 values = [name]
77 if directories: 91 if directories:
78 values.append(self.path(name)) 92 values.append(self.path(name))
79 retval.append(values) 93 retval.append(values)
80 return format_tabular(retval) 94 return format_tabular(retval) # XXX: TBD upstream
81 95
82 def clone(self, source, dest, hash=True): 96 def clone(self, source, dest, hash=True):
83 """ 97 """
84 clones the profile `source` and output to `dest` 98 clones the profile `source` and output to `dest`
85 """ 99 """
167 if not parser.has_option(section, 'name'): 181 if not parser.has_option(section, 'name'):
168 continue # not a profile 182 continue # not a profile
169 if parser.get(section, 'name') == profile: 183 if parser.get(section, 'name') == profile:
170 return dict(parser.items(section)) 184 return dict(parser.items(section))
171 raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles)) 185 raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))
186
187 def section(self, profile):
188 """
189 returns the name of the section that a profile is in
190 """
172 191
173 def profiles_dict(self): 192 def profiles_dict(self):
174 """ 193 """
175 return nested dict of all profiles 194 return nested dict of all profiles
176 """ 195 """