Opened 10 years ago

Closed 10 years ago

Last modified 6 years ago

#955 closed defect (fixed)

mimetype database only updated when installing activities

Reported by: erikos Owned by: tomeu
Priority: Unspecified by Maintainer Milestone:
Component: Sugar Version: 0.84.x
Severity: Major Keywords: r+
Cc: Distribution/OS: Unspecified
Bug Status: New

Description

The code to read in the activity/imetypes.xml lives in sugar/bundle/ActivityBundle.install This is only executed when installing an activity.

When one unzip a .xo into ~/Activities (when running Sugar) the mimetype is not added to the database. There is some code in jarabe/model/bundleregistry.py to monitor those folders for changes. We could call the mimetype adding there.

Another case is, when sugar is not running (emulator for example) and one places an activity in the ~/Activity folder. This should ideally be handled as well.

Change History (3)

comment:1 Changed 10 years ago by erikos

  • Keywords r? added
diff --git a/src/sugar/bundle/activitybundle.py b/src/sugar/bundle/activitybundle.py
index 268576e..1c00dea 100644
--- a/src/sugar/bundle/activitybundle.py
+++ b/src/sugar/bundle/activitybundle.py
@@ -311,7 +311,15 @@ class ActivityBundle(Bundle):
                 raise MalformedBundleException(err)
             else:
                 logging.warning(err)
+        
+        self.install_myme_type(install_path)
+        
+        return install_path
 
+    def install_mime_type(self, install_path):
+        ''' Update the mime type database and
+            install the mime type icon
+        '''
         xdg_data_home = os.getenv('XDG_DATA_HOME',
                                   os.path.expanduser('~/.local/share'))
 
@@ -347,7 +355,6 @@ class ActivityBundle(Bundle):
                     os.symlink(info_file,
                                os.path.join(installed_icons_dir,
                                             os.path.basename(info_file)))
-        return install_path
 
     def uninstall(self, install_path, force=False):
         if os.path.islink(install_path):
@@ -355,7 +362,7 @@ class ActivityBundle(Bundle):
             # because we may be removing user data.
             os.unlink(install_path)
             return
-
+        
         xdg_data_home = os.getenv('XDG_DATA_HOME',
                                   os.path.expanduser('~/.local/share'))

Move the mime-database-update function out of the install one.

diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index 068cf8d..7c758eb 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -78,7 +78,7 @@ class BundleRegistry(gobject.GObject):
         if not one_file.get_path().endswith('.activity'):
             return
         if event_type == gio.FILE_MONITOR_EVENT_CREATED:
-            self.add_bundle(one_file.get_path())
+            self.add_bundle(one_file.get_path(), monitor=True)
         elif event_type == gio.FILE_MONITOR_EVENT_DELETED:
             self.remove_bundle(one_file.get_path())
 
@@ -194,8 +194,8 @@ class BundleRegistry(gobject.GObject):
                 logging.error('Error while processing installed activity ' \
                               'bundle: %s, %s, %s' % (folder, e.__class__, e))
 
-    def add_bundle(self, bundle_path):
-        bundle = self._add_bundle(bundle_path)
+    def add_bundle(self, bundle_path, monitor=False):
+        bundle = self._add_bundle(bundle_path, monitor)
         if bundle is not None:
             self._set_bundle_favorite(bundle.get_bundle_id(),
                                       bundle.get_activity_version(),
@@ -205,10 +205,12 @@ class BundleRegistry(gobject.GObject):
         else:
             return False
 
-    def _add_bundle(self, bundle_path):
+    def _add_bundle(self, bundle_path, monitor=False):
         logging.debug('STARTUP: Adding bundle %r' % bundle_path)
         try:
             bundle = ActivityBundle(bundle_path)
+            if monitor is True:
+                bundle.install_mime_type(bundle_path)
         except MalformedBundleException:
:

update mime-database on new folder detection.

comment:2 Changed 10 years ago by tomeu

  • Keywords r+ added; r? removed
  • Resolution set to fixed
  • Status changed from new to closed

Pushed, thanks!

comment:3 Changed 6 years ago by dnarvaez

  • Milestone 0.86 deleted

Milestone 0.86 deleted

Note: See TracTickets for help on using tickets.