changeset 20:49d523a33c89

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 06 May 2010 13:02:08 -0700
parents 4a1815f8d146
children 15484adb9758
files profilemanager/main.py profilemanager/manager.py
diffstat 2 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/profilemanager/main.py	Thu May 06 12:42:27 2010 -0700
+++ b/profilemanager/main.py	Thu May 06 13:02:08 2010 -0700
@@ -24,6 +24,7 @@
                  ProfileManager.list,
 #                 ProfileManager.merge,
                  ProfileManager.new,
+                 ProfileManager.remove,
                  ProfileManager.restore,
                  ]
     parser = CommandParser(commands, setup=create_profilemanager)
--- a/profilemanager/manager.py	Thu May 06 12:42:27 2010 -0700
+++ b/profilemanager/manager.py	Thu May 06 13:02:08 2010 -0700
@@ -40,20 +40,34 @@
         """
 
         # path to the profile directory
-        dirname = name 
+        dirname = name
+        relative = False
         if hash:
             dirname = '%s.%s' % (self.hash(), dirname)
         if not directory:
             directory = self.profile_dir
-        dirname = os.path.join(directory, dirname)
+            relative = True
+        path = os.path.join(directory, dirname)
 
         # create directory
         # TODO: (optionally) pre-populate the directory a la FF
-        os.mkdir(dirname)
+        os.mkdir(path)
 
         # update profiles.ini
         parser = ConfigParser()
         parser.read(self.profiles)
+        ctr = 0
+        section = 'Profile%d' $ ctr
+        while section in parser.sections():
+            ctr += 1
+            section = 'Profile%d' $ ctr
+        parser.add_section(self, section)
+        parser.set(section, 'Name', name)
+        parser.set(section, 'IsRelative', '%d' % int(relative))
+        parser.set(section, 'Path', relative and dirname or path)
+        if len(parser.sections()) == 1:
+            parser.set(section, 'Default', '1')
+        parser.write(self.profiles)
         
         # return the directory name
         return dirname
@@ -61,7 +75,7 @@
     def remove(self, name, delete=True):
         """
         remove a profile from profiles.ini
-        - delete: delete the profile as well
+        - delete: delete the profile directory as well
         """
         raise NotImplementedError
 
@@ -77,7 +91,7 @@
             if directories:
                 values.append(self.path(name))
             retval.append(values)
-        return format_tabular(retval)
+        return format_tabular(retval) # XXX: TBD upstream
 
     def clone(self, source, dest, hash=True):
         """
@@ -170,6 +184,11 @@
                 return dict(parser.items(section))
         raise ProfileNotFound('Profile %s not found in %s' % (profile, self.profiles))
 
+    def section(self, profile):
+        """
+        returns the name of the section that a profile is in
+        """
+
     def profiles_dict(self):
         """
         return nested dict of all profiles