Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugin/bundleregistry.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/bundleregistry.py')
-rw-r--r--plugin/bundleregistry.py87
1 files changed, 51 insertions, 36 deletions
diff --git a/plugin/bundleregistry.py b/plugin/bundleregistry.py
index d4ca5f8..3f9bb36 100644
--- a/plugin/bundleregistry.py
+++ b/plugin/bundleregistry.py
@@ -15,14 +15,13 @@
import os
import logging
-from os.path import lexists, basename
+from os.path import lexists
from gettext import gettext as _
import gtk
import gobject
-import sugar_network
-from sugar.util import LRU
+from sugar_network import checkins, sugar
from sugar.bundle.activitybundle import ActivityBundle
from jarabe.plugins.sn import SN_BROWSER_NAME, get_client
@@ -30,7 +29,6 @@ from jarabe.plugins.sn import SN_BROWSER_NAME, get_client
_logger = logging.getLogger('plugins.sn.bundleregistry')
_stub_icon_path = None
-_online_cache = LRU(100)
class BundleRegistry(gobject.GObject):
@@ -51,15 +49,21 @@ class BundleRegistry(gobject.GObject):
def populate(self):
client = get_client()
+ client.connect_to_signal('Event', self.__Event_cb)
- for props in client.find('~', 'context', 0, 50,
- reply=['guid', 'keep', 'keep_impl', 'position']):
- if props['keep_impl']:
+ def reply_handler(entries, total):
+ for props in entries:
bundle = self._add_bundle(props['guid'], props)
- self.emit('bundle-added', bundle)
+ if bundle is not None:
+ self.emit('bundle-added', bundle)
+
+ def error_handler(error):
+ _logger.warning('Cannot call Find(): %s', error)
- client.connect('keep', self.__keep_cb)
- client.connect('keep_impl', self.__keep_impl_cb)
+ client.Find('~', 'context',
+ ['guid', 'keep', 'keep_impl', 'position'],
+ {'keep_impl': 2, 'limit': 1024},
+ reply_handler=reply_handler, error_handler=error_handler)
def __iter__(self):
return self._bundles.itervalues()
@@ -76,22 +80,17 @@ class BundleRegistry(gobject.GObject):
if context_guid in self._bundles:
return self._bundles[context_guid]
- if context_guid in _online_cache:
- return _online_cache[context_guid]
-
if mountpoint == '~':
return None
-
try:
- props = get_client().get(mountpoint, 'context', context_guid,
- reply=['guid', 'keep', 'keep_impl', 'title'])
+ props = get_client().Get(mountpoint, 'context', context_guid,
+ ['guid', 'keep', 'keep_impl', 'title'])
result = _ContextInfo(mountpoint, props)
except Exception:
- _logger.warning(_('Cannot fetch activity metadata'))
+ _logger.warning('Cannot fetch activity metadata for %r on %r',
+ context_guid, mountpoint)
result = None
- _online_cache[context_guid] = result
-
return result
def get_activities_for_type(self, mime_type):
@@ -112,7 +111,7 @@ class BundleRegistry(gobject.GObject):
bundle = self._bundles.get(bundle_id)
if bundle is None:
return
- get_client().update('~', 'context', bundle_id, keep=keep)
+ get_client().Update('~', 'context', bundle_id, {'keep': keep})
bundle.props['keep'] = keep
self.emit('bundle-changed', bundle)
@@ -127,7 +126,7 @@ class BundleRegistry(gobject.GObject):
if bundle is None:
return
position = bundle.props['position'] = [int(x), int(y)]
- get_client().update('~', 'context', bundle_id, position=position)
+ get_client().Update('~', 'context', bundle_id, {'position': position})
self.emit('bundle-changed', bundle)
def get_default_for_type(self, mime_type):
@@ -148,7 +147,7 @@ class BundleRegistry(gobject.GObject):
raise NotImplementedError('Not yet supported')
def _add_bundle(self, bundle_id, props):
- for path in sugar_network.checkins(bundle_id):
+ for path in checkins(bundle_id):
try:
bundle = self._bundles[bundle_id] = \
_BundleInfo(ActivityBundle(path), props)
@@ -160,28 +159,43 @@ class BundleRegistry(gobject.GObject):
else:
_logger.info('No bundles for %r', bundle_id)
- def __keep_cb(self, sender, bundle_id, keep):
+ def _set_keep(self, bundle_id, keep):
bundle = self._bundles.get(bundle_id)
if bundle is None:
return
bundle.props['keep'] = keep
self.emit('bundle-changed', bundle)
- def __keep_impl_cb(self, sender, bundle_id, keep_impl):
+ def _set_keep_impl(self, bundle_id, keep_impl):
if keep_impl:
- props = get_client().get('~', 'context', bundle_id,
- reply=['guid', 'keep', 'keep_impl', 'position'])
bundle = self._bundles.get(bundle_id)
if bundle is None:
+ props = get_client().Get('~', 'context', bundle_id,
+ ['guid', 'keep', 'keep_impl', 'position'])
bundle = self._add_bundle(bundle_id, props)
- else:
- bundle.props.update(props)
- self.emit('bundle-added', bundle)
+ if bundle is not None:
+ self.emit('bundle-added', bundle)
else:
if bundle_id in self._bundles:
bundle = self._bundles.pop(bundle_id)
self.emit('bundle-removed', bundle)
+ def __Event_cb(self, event):
+ if 'mountpoint' in event and event['mountpoint'] != '~' or \
+ event.get('document') != 'context':
+ return
+ event_type = event.get('event')
+ if event_type in ('create', 'update'):
+ bundle_id = event['guid']
+ props = event['props']
+ if props.get('keep_impl') in (0, 2):
+ self._set_keep_impl(bundle_id, props['keep_impl'])
+ if 'keep' in props:
+ self._set_keep(bundle_id, props['keep'])
+ elif event_type == 'delete':
+ bundle_id = event['guid']
+ self._set_keep_impl(bundle_id, 0)
+
class _ContextInfo(object):
@@ -196,21 +210,22 @@ class _ContextInfo(object):
return self.props['guid']
def get_icon(self):
- path = None
+ blob = None
try:
- path, __ = get_client().get_blob_path('/', 'context',
+ blob = get_client().GetBlob(self.mountpoint, 'context',
self.get_bundle_id(), 'artifact_icon')
except Exception, error:
_logger.debug('Fail to get icon for %r: %s',
self.get_bundle_id(), error)
- if not path or os.stat(path).st_size == 0:
+ if not blob or os.stat(blob['path']).st_size == 0:
return _stub_icon()
else:
- svg_path = path + '.svg'
- if not lexists(svg_path):
- os.symlink(basename(path), svg_path)
- return svg_path
+ path = sugar.profile_path('data', self.get_bundle_id() + '.svg')
+ if lexists(path):
+ os.unlink(path)
+ os.symlink(blob['path'], path)
+ return path
def get_tags(self):
# Doesn't matter with Sweets' features enabled