Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-08-15 14:43:31 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-08-15 15:45:31 (GMT)
commit271721c0b24e64eab03f6b5f549094a4010d4393 (patch)
tree2518074928bdfc98675ce33fed8d9a158e2963dd
parent5343c4c09cd0f24cc98e93b0e53b06d685b9fbc9 (diff)
Cleanup MIME directory after activity checkout
-rw-r--r--sugar_network/local/activities.py14
-rwxr-xr-xtests/units/activities.py19
2 files changed, 30 insertions, 3 deletions
diff --git a/sugar_network/local/activities.py b/sugar_network/local/activities.py
index d750dd7..7d67e66 100644
--- a/sugar_network/local/activities.py
+++ b/sugar_network/local/activities.py
@@ -18,7 +18,7 @@ import hashlib
import logging
import tempfile
from os.path import join, exists, lexists, relpath, dirname, basename, isdir
-from os.path import abspath
+from os.path import abspath, islink
from sweets_recipe import Spec
from sugar_network.toolkit.inotify import Inotify, \
@@ -202,11 +202,13 @@ class _Inotify(Inotify):
os.unlink(context_path)
os.unlink(checkin_path)
+ self._checkout_activity(impl_path)
+
def lost_mimetypes(self, impl_path):
hashed_path, __ = _checkin_path(impl_path)
dst_path = join(self._mime_dir, 'packages', hashed_path + '.xml')
- if not exists(dst_path):
+ if not lexists(dst_path):
return
_logger.debug('Update MIME database to process lost %r', impl_path)
@@ -226,6 +228,14 @@ class _Inotify(Inotify):
join(self._icons_dir,
mime_type.replace('/', '-') + '.svg'))
+ def _checkout_activity(self, impl_path):
+ if exists(self._icons_dir):
+ for filename in os.listdir(self._icons_dir):
+ path = join(self._icons_dir, filename)
+ if islink(path) and \
+ os.readlink(path).startswith(impl_path + os.sep):
+ os.unlink(path)
+
class _Root(object):
diff --git a/tests/units/activities.py b/tests/units/activities.py
index 707e05b..077e6dc 100755
--- a/tests/units/activities.py
+++ b/tests/units/activities.py
@@ -317,14 +317,25 @@ class ActivitiesTest(tests.Test):
title={'en': 'title'}, summary={'en': 'summary'},
description={'en': 'description'}, user=[sugar.uid()])
+ self.touch('Activities/activity/activity/icon.svg')
+ self.touch(('Activities/activity/activity/mimetypes.xml', [
+ '<?xml version="1.0" encoding="UTF-8"?>',
+ '<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">',
+ '<mime-type type="application/x-foo-bar">',
+ '<comment xml:lang="en">foo-bar</comment>',
+ '<glob pattern="*.foo"/>',
+ '</mime-type>',
+ '</mime-info>',
+ ]))
self.touch(('Activities/activity/activity/activity.info', [
'[Activity]',
'name = HelloWorld',
'activity_version = 1',
'bundle_id = org.sugarlabs.HelloWorld',
'exec = sugar-activity activity.HelloWorldActivity',
- 'icon = activity-helloworld',
+ 'icon = icon',
'license = GPLv2+',
+ 'mime_types = foo/bar',
]))
coroutine.sleep(1)
@@ -334,6 +345,9 @@ class ActivitiesTest(tests.Test):
self.assertEqual(
{'guid': 'org.sugarlabs.HelloWorld', 'title': {'en': 'title'}, 'keep': False, 'keep_impl': 2},
self.mounts.home_volume['context'].get('org.sugarlabs.HelloWorld').properties(['guid', 'title', 'keep', 'keep_impl']))
+ assert exists('share/icons/sugar/scalable/mimetypes/foo-bar.svg')
+ assert exists('share/mime/packages/%s.xml' % hashed_path)
+ assert exists('share/mime/application/x-foo-bar.xml')
shutil.rmtree('Activities/activity')
coroutine.sleep(1)
@@ -343,6 +357,9 @@ class ActivitiesTest(tests.Test):
self.assertEqual(
{'guid': 'org.sugarlabs.HelloWorld', 'title': {'en': 'title'}, 'keep': False, 'keep_impl': 0},
self.mounts.home_volume['context'].get('org.sugarlabs.HelloWorld').properties(['guid', 'title', 'keep', 'keep_impl']))
+ assert not lexists('share/icons/sugar/scalable/mimetypes/foo-bar.svg')
+ assert not lexists('share/mime/packages/%s.xml' % hashed_path)
+ assert not lexists('share/mime/application/x-foo-bar.xml')
if __name__ == '__main__':