Mercurial > mozilla > hg > ProfileManager
comparison profilemanager/manager.py @ 6:2a3f5cdfd60c
flush out helper functions and list directories
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 06 Apr 2010 09:19:05 -0700 |
parents | ca57920aa223 |
children | d3b22d086934 |
comparison
equal
deleted
inserted
replaced
5:ca57920aa223 | 6:2a3f5cdfd60c |
---|---|
25 ### (public) API | 25 ### (public) API |
26 | 26 |
27 def list(self, directories=False): | 27 def list(self, directories=False): |
28 """ | 28 """ |
29 lists the profiles available in the config file | 29 lists the profiles available in the config file |
30 - directories : display the directories | |
30 """ | 31 """ |
31 parser = ConfigParser() | 32 parser = ConfigParser() |
32 parser.read(self.profiles) | 33 parser.read(self.profiles) |
33 names = [] | 34 retval = [] |
34 for section in parser.sections(): | 35 for section in parser.sections(): |
35 if section == 'General': | 36 if section == 'General': |
36 continue | 37 continue |
37 names.append((parser.get(section, 'name'),)) | 38 name = parser.get(section, 'name') |
38 return format_tabular(names) | 39 values = [name] |
40 if directories: | |
41 values.append(self.path(name)) | |
42 retval.append(values) | |
43 return format_tabular(retval) | |
39 | 44 |
40 def clone(self, source, dest): | 45 def clone(self, source, dest): |
41 """ | 46 """ |
42 clones the profile `source` and output to `dest` | 47 clones the profile `source` and output to `dest` |
43 """ | 48 """ |
77 | 82 |
78 ### internal functions | 83 ### internal functions |
79 | 84 |
80 def path(self, profile): | 85 def path(self, profile): |
81 """returns the path to the profile""" | 86 """returns the path to the profile""" |
87 profile = self.profile_dict(profile) | |
88 if profile.get('isrelative', None) == '1': | |
89 return os.path.join(self.profile_dir, profile['path']) | |
90 return profile['path'] | |
82 | 91 |
83 def profile_dict(self, profile): | 92 def profile_dict(self, profile): |
84 parser = ConfigParser() | 93 parser = ConfigParser() |
85 parser.read(self.profiles) | 94 parser.read(self.profiles) |
86 for section in parser.sections(): | 95 for section in parser.sections(): |
87 raise NotImplementedError | 96 if not parser.has_option(section, 'name'): |
97 continue # not a profile | |
98 if parser.get(section, 'name') == profile: | |
99 return dict(parser.items(section)) | |
100 raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles)) |