[sugar] [PATCH] Bundle API now provides write functionality.

Andrew Clunis orospakr
Wed Feb 28 23:23:15 EST 2007


* now provides property setters and write_info() method, which will write
  the activity metadata back to activity.info.
* now supports the comment and host_version fields.
* various cleanups.
---
 sugar/activity/bundle.py |  128 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 105 insertions(+), 23 deletions(-)

diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py
index 6a6ebdd..482b105 100644
--- a/sugar/activity/bundle.py
+++ b/sugar/activity/bundle.py
@@ -8,18 +8,25 @@ _PYTHON_FACTORY='sugar-activity-factory'
 
 class Bundle:
     """Info about an activity bundle. Wraps the activity.info file."""
+    
+    section = 'Activity'
+    
     def __init__(self, path):
         self._name = None
         self._icon = None
+        self._class = None
+        self._exec = None
         self._service_name = None
         self._show_launcher = True
         self._valid = True
         self._path = path
+        self._comment = None
         self._activity_version = 0
+        self._host_version = 0
 
-        info_path = os.path.join(path, 'activity', 'activity.info')
-        if os.path.isfile(info_path):
-            self._parse_info(info_path)
+        self._info_path = os.path.join(path, 'activity', 'activity.info')
+        if os.path.isfile(self._info_path):
+            self._parse_info(self._info_path)
         else:
             self._valid = False
 
@@ -27,44 +34,46 @@ class Bundle:
         cp = ConfigParser()
         cp.read([info_path])
 
-        section = 'Activity'
-
-        if cp.has_option(section, 'service_name'):
-            self._service_name = cp.get(section, 'service_name')
+        if cp.has_option(self.section, 'service_name'):
+            self._service_name = cp.get(self.section, 'service_name')
         else:
             self._valid = False
             logging.error('%s must specify a service name' % self._path)
 
-        if cp.has_option(section, 'name'):
-            self._name = cp.get(section, 'name')
+        if cp.has_option(self.section, 'name'):
+            self._name = cp.get(self.section, 'name')
         else:
             self._valid = False
             logging.error('%s must specify a name' % self._path)
+            
+        if cp.has_option(self.section, 'comment'):
+            self._comment = cp.get(self.section, 'comment')
 
-        if cp.has_option(section, 'class'):
-            self._class = cp.get(section, 'class')
+        if cp.has_option(self.section, 'class'):
+            self._class = cp.get(self.section, 'class')
             self._exec = '%s %s --bundle-path=%s' % (
                  os.path.join(env.get_shell_bin_dir(), _PYTHON_FACTORY),
                  self._class, self.get_path())
-        elif cp.has_option(section, 'exec'):
+        elif cp.has_option(self.section, 'exec'):
             self._class = None
-            self._exec = cp.get(section, 'exec')
+            self._exec = cp.get(self.section, 'exec')
         else:
             self._exec = None
             self._valid = False
             logging.error('%s must specify exec or class' % self._path)
 
-        if cp.has_option(section, 'show_launcher'):
-            if cp.get(section, 'show_launcher') == 'no':
+        if cp.has_option(self.section, 'show_launcher'):
+            if cp.get(self.section, 'show_launcher') == 'no':
                 self._show_launcher = False
 
-        if cp.has_option(section, 'icon'):
-            icon = cp.get(section, 'icon')
-            activity_path = os.path.join(self._path, 'activity')
-            self._icon = os.path.join(activity_path, icon + ".svg")
+        if cp.has_option(self.section, 'icon'):
+            self._icon_name = cp.get(self.section, 'icon')
 
-        if cp.has_option(section, 'activity_version'):
-            self._activity_version = int(cp.get(section, 'activity_version'))
+        if cp.has_option(self.section, 'activity_version'):
+            self._activity_version = int(cp.get(self.section, 'activity_version'))
+        
+        if cp.has_option(self.section, 'host_version'):
+            self._host_version = int(cp.get(self.section, 'host_version'))
 
     def is_valid(self):
         return self._valid
@@ -76,10 +85,26 @@ class Bundle:
     def get_name(self):
         """Get the activity user visible name."""
         return self._name
+    
+    def set_name(self, name):
+        """Set the activity user visible name"""
+        self._name = name
+    
+    def get_comment(self):
+        """Get the activity comment"""
+        return self._comment
+    
+    def set_comment(self, comment):
+        """Set the activity comment"""
+        self._comment = comment
 
     def get_service_name(self):
         """Get the activity service name"""
         return self._service_name
+    
+    def set_service_name(self, service_name):
+        """Set the activity service name"""
+        self._service_name = service_name
 
     def get_object_path(self):
         """Get the path to the service object"""
@@ -93,21 +118,78 @@ class Bundle:
         return '_' + '_'.join(splitted) + '._udp'
 
     def get_icon(self):
+        """Get the activity icon file name"""
+        activity_path = os.path.join(self._path, 'activity')
+        icon = os.path.join(activity_path, self._icon_name + ".svg")
+        return icon
+    
+    def get_icon_name(self):
         """Get the activity icon name"""
-        return self._icon
+        return self._icon_name
+    
+    def set_icon_name(self, icon_name):
+        """Set the activity icon name"""
+        self._icon_name = icon_name
 
     def get_activity_version(self):
         """Get the activity version"""
         return self._activity_version
+    
+    def set_activity_version(self, activity_version):
+        """Set the activity version"""
+        self._activity_version = activity_version
+        
+    def get_host_version(self):
+        """Get the host version required for this activity"""
+        return self._host_version
+    
+    def set_host_version(self, host_version):
+        """Set the host version required for this activity"""
+        self._host_version = host_version
 
     def get_exec(self):
         """Get the command to execute to launch the activity factory"""
         return self._exec
+    
+    def set_exec(self, exec_name):
+        """Set the command to execute to launch the activity factory"""
+        self._exec = exec_name
 
     def get_class(self):
         """Get the main Activity class"""
-        return self._exec
+        return self._class
+    
+    def set_class(self, klass):
+        """Set the main Activity class"""
+        self._class = klass
 
     def get_show_launcher(self):
         """Get whether there should be a visible launcher for the activity"""
         return self._show_launcher
+    
+    def set_show_launcher(self, show_launcher):
+        self._show_launcher = show_launcher
+
+    def write_info(self):
+        """Write changed configuration parameters back to the activity.info
+        file"""
+        cp = ConfigParser()
+        info_fd = open(self._info_path, "wb")
+        cp.add_section(self.section)
+        cp.set(self.section, "name", self._name)
+        cp.set(self.section, "icon", self._icon_name)
+        cp.set(self.section, "service_name", self._service_name)
+        if self._comment is not None:
+            cp.set(self.section, "comment", self._comment)
+        if self._show_launcher:
+            cp.set(self.section, "show_launcher", "yes")
+        else:
+            cp.set(self.section, "show_launcher", "no")
+        if self._class is None:
+            cp.set(self.section, "exec", self._exec)
+        else:
+            cp.set(self.section, "class", self._class)
+        cp.set(self.section, "activity_version", str(self._activity_version))
+        cp.set(self.section, "host_version", str(self._host_version))
+        cp.write(info_fd)
+        info_fd.close()
-- 
1.4.1



More information about the Sugar-devel mailing list