diff 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
line wrap: on
line diff
--- a/profilemanager/manager.py	Tue Apr 06 08:04:24 2010 -0700
+++ b/profilemanager/manager.py	Tue Apr 06 09:19:05 2010 -0700
@@ -27,15 +27,20 @@
     def list(self, directories=False):
         """
         lists the profiles available in the config file
+        - directories : display the directories
         """
         parser = ConfigParser()
         parser.read(self.profiles)
-        names = []
+        retval = []
         for section in parser.sections():
             if section == 'General':
                 continue
-            names.append((parser.get(section, 'name'),))
-        return format_tabular(names)
+            name = parser.get(section, 'name')
+            values = [name]
+            if directories:
+                values.append(self.path(name))
+            retval.append(values)
+        return format_tabular(retval)
 
     def clone(self, source, dest):
         """
@@ -79,9 +84,17 @@
 
     def path(self, profile):
         """returns the path to the profile"""
+        profile = self.profile_dict(profile)
+        if profile.get('isrelative', None) == '1':
+            return os.path.join(self.profile_dir, profile['path'])
+        return profile['path']
 
     def profile_dict(self, profile):
         parser = ConfigParser()
         parser.read(self.profiles)
         for section in parser.sections():
-            raise NotImplementedError
+            if not parser.has_option(section, 'name'):
+                continue # not a profile
+            if parser.get(section, 'name') == profile:
+                return dict(parser.items(section))
+        raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))