comparison profilemanager/manager.py @ 41:769447f8cd08

cleanup
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 06 May 2010 18:55:53 -0700
parents 34c740d1962d
children 232188e7c04c
comparison
equal deleted inserted replaced
40:34c740d1962d 41:769447f8cd08
102 relative = True 102 relative = True
103 if not os.path.dirname(dest): 103 if not os.path.dirname(dest):
104 dest = '%s.%s' % (self.hash(), dest) 104 dest = '%s.%s' % (self.hash(), dest)
105 dest = os.path.join(self.profile_dir, dest) 105 dest = os.path.join(self.profile_dir, dest)
106 106
107 # ensure name is not already present 107
108 assert name not in self.profiles_dict(), 'Profile "%s" already in %s' % (name, self.profiles) 108 assert name not in self.profiles_dict(), 'Profile "%s" already in %s' % (name, self.profiles)
109 109
110 # update profiles.ini 110 # update profiles.ini
111 if add: 111 if add:
112 self.add(name, dirname, relative) 112 self.add(name, dirname, relative)
169 169
170 def add(self, profile, path, relative=True): 170 def add(self, profile, path, relative=True):
171 """ 171 """
172 add a profile entry to profiles.ini 172 add a profile entry to profiles.ini
173 """ 173 """
174 assert name not in self.profiles_dict(), 'Profile "%s" already in %s' % (name, self.profiles) 174
175 parser = self.parser() 175 # ensure name is not already present
176 assert profile not in self.profiles_dict(), 'Profile "%s" already in %s' % (name, self.profiles)
177 parser = self.parser()
178
179 # find and add the section
176 ctr = 0 180 ctr = 0
177 section = 'Profile%d' % ctr # unsure of this naming convention 181 section = 'Profile%d' % ctr # unsure of this naming convention
178 while section in parser.sections(): 182 while section in parser.sections():
179 ctr += 1 183 ctr += 1
180 section = 'Profile%d' % ctr 184 section = 'Profile%d' % ctr
181 parser.add_section(section) 185 parser.add_section(section)
186
187 # add metadata
182 parser.set(section, 'Name', profile) 188 parser.set(section, 'Name', profile)
183 parser.set(section, 'IsRelative', '%d' % int(relative)) 189 parser.set(section, 'IsRelative', '%d' % int(relative))
184 parser.set(section, 'Path', relative and dirname or path) 190 parser.set(section, 'Path', relative and dirname or path)
185 if not ctr: 191 if not ctr:
186 parser.set(section, 'Default', '1') 192 parser.set(section, 'Default', '1')
193
194 # write the file
187 parser.write(file(self.profiles, 'w')) 195 parser.write(file(self.profiles, 'w'))
188 196
189 197
190 def path(self, profile): 198 def path(self, profile):
191 """returns the path to the profile""" 199 """returns the path to the profile"""