Exemple #1
0
    def get_system_bundles(self, bundle_id):
        """
        Searches for system bundles (eg. those in /usr/share/sugar/activities)
        with a given bundle id.

        Prams:
            * bundle_id (string):  the bundle id to look for

        Returns a list of ActivityBundle or ContentBundle objects, or an empty
        list if there are none found.
        """
        bundles = []
        for root in GLib.get_system_data_dirs():
            root = os.path.join(root, 'sugar', 'activities')

            try:
                dir_list = os.listdir(root)
            except OSError:
                logging.debug('Can not find GLib system dir %s', root)
                continue

            for activity_dir in dir_list:
                try:
                    bundle = bundle_from_dir(os.path.join(root, activity_dir))
                except MalformedBundleException:
                    continue

                if bundle.get_bundle_id() == bundle_id:
                    bundles.append(bundle)
        return bundles
Exemple #2
0
    def __file_monitor_changed_cb(self, monitor, one_file, other_file,
                                  event_type):
        if event_type == Gio.FileMonitorEvent.CREATED or \
           event_type == Gio.FileMonitorEvent.ATTRIBUTE_CHANGED:
            self.add_bundle(one_file.get_path(), set_favorite=True)
        elif event_type == Gio.FileMonitorEvent.DELETED:
            self.remove_bundle(one_file.get_path())
            for root in GLib.get_system_data_dirs():
                root = os.path.join(root, 'sugar', 'activities')

                try:
                    os.listdir(root)
                except OSError:
                    logging.debug('Can not find GLib system dir %s', root)
                    continue
                activity_dir = os.path.basename(one_file.get_path())
                try:
                    bundle = bundle_from_dir(os.path.join(root, activity_dir))
                except MalformedBundleException:
                    continue

                if bundle is not None:
                    path = bundle.get_path()
                    if path is not None:
                        self.add_bundle(path)
Exemple #3
0
    def get_system_bundles(self, bundle_id):
        """
        Searches for system bundles (eg. those in /usr/share/sugar/activities)
        with a given bundle id.

        Prams:
            * bundle_id (string):  the bundle id to look for

        Returns a list of ActivityBundle or ContentBundle objects, or an empty
        list if there are none found.
        """
        bundles = []
        for root in GLib.get_system_data_dirs():
            root = os.path.join(root, 'sugar', 'activities')

            try:
                dir_list = os.listdir(root)
            except OSError:
                logging.debug('Can not find GLib system dir %s', root)
                continue

            for activity_dir in dir_list:
                try:
                    bundle = bundle_from_dir(os.path.join(root, activity_dir))
                except MalformedBundleException:
                    continue

                if bundle.get_bundle_id() == bundle_id:
                    bundles.append(bundle)
        return bundles
Exemple #4
0
    def __file_monitor_changed_cb(self, monitor, one_file, other_file,
                                  event_type):
        if event_type == Gio.FileMonitorEvent.CREATED or \
           event_type == Gio.FileMonitorEvent.ATTRIBUTE_CHANGED:
            self.add_bundle(one_file.get_path(), set_favorite=True)
        elif event_type == Gio.FileMonitorEvent.DELETED:
            self.remove_bundle(one_file.get_path())
            for root in GLib.get_system_data_dirs():
                root = os.path.join(root, 'sugar', 'activities')

                try:
                    os.listdir(root)
                except OSError:
                    logging.debug('Can not find GLib system dir %s', root)
                    continue
                activity_dir = os.path.basename(one_file.get_path())
                try:
                    bundle = bundle_from_dir(os.path.join(root, activity_dir))
                except MalformedBundleException:
                    continue

                if bundle is not None:
                    path = bundle.get_path()
                    if path is not None:
                        self.add_bundle(path)
def get_bundle(bundle_id='', object_id=''):
    bus = dbus.SessionBus()
    obj = bus.get_object(J_DBUS_SERVICE, J_DBUS_PATH)
    journal = dbus.Interface(obj, J_DBUS_INTERFACE)
    bundle_path = journal.GetBundlePath(bundle_id, object_id)
    if bundle_path:
        return bundle_from_dir(bundle_path)
    else:
        return None
def get_bundle(bundle_id='', object_id=''):
    bus = dbus.SessionBus()
    obj = bus.get_object(J_DBUS_SERVICE, J_DBUS_PATH)
    journal = dbus.Interface(obj, J_DBUS_INTERFACE)
    bundle_path = journal.GetBundlePath(bundle_id, object_id)
    if bundle_path:
        return bundle_from_dir(bundle_path)
    else:
        return None
Exemple #7
0
    def add_bundle(self,
                   bundle_path,
                   set_favorite=False,
                   emit_signals=True,
                   force_downgrade=False):
        """
        Add a bundle to the registry.
        If the bundle is a duplicate with one already in the registry,
        the existing one from the registry is returned.
        Otherwise, the newly added bundle is returned on success, or None on
        failure.
        """
        try:
            bundle = bundle_from_dir(bundle_path)
        except MalformedBundleException:
            logging.exception('Error loading bundle %r', bundle_path)
            return None

        # None is a valid return value from bundle_from_dir helper.
        if bundle is None:
            logging.error('No bundle in %r', bundle_path)
            return None

        bundle_id = bundle.get_bundle_id()
        logging.debug('STARTUP: Adding bundle %s', bundle_id)
        installed = self.get_bundle(bundle_id)

        if installed is not None:
            if NormalizedVersion(installed.get_activity_version()) == \
                    NormalizedVersion(bundle.get_activity_version()):
                logging.debug("Bundle already known")
                return installed
            if not force_downgrade and \
                    NormalizedVersion(installed.get_activity_version()) >= \
                    NormalizedVersion(bundle.get_activity_version()):
                logging.debug('Skip old version for %s', bundle_id)
                return None
            else:
                logging.debug('Upgrade %s', bundle_id)
                self.remove_bundle(installed.get_path(), emit_signals)

        if set_favorite:
            favorite = not self.is_bundle_hidden(bundle.get_bundle_id(),
                                                 bundle.get_activity_version())
            self._set_bundle_favorite(bundle.get_bundle_id(),
                                      bundle.get_activity_version(), favorite)

        with self._lock:
            self._bundles.append(bundle)
        if emit_signals:
            self.emit('bundle-added', bundle)
        return bundle
Exemple #8
0
    def add_bundle(self, bundle_path, set_favorite=False, emit_signals=True,
                   force_downgrade=False):
        """
        Add a bundle to the registry.
        If the bundle is a duplicate with one already in the registry,
        the existing one from the registry is returned.
        Otherwise, the newly added bundle is returned on success, or None on
        failure.
        """
        try:
            bundle = bundle_from_dir(bundle_path)
        except MalformedBundleException:
            logging.exception('Error loading bundle %r', bundle_path)
            return None

        # None is a valid return value from bundle_from_dir helper.
        if bundle is None:
            logging.error('No bundle in %r', bundle_path)
            return None

        bundle_id = bundle.get_bundle_id()
        logging.debug('STARTUP: Adding bundle %s', bundle_id)
        installed = self.get_bundle(bundle_id)

        if installed is not None:
            if NormalizedVersion(installed.get_activity_version()) == \
                    NormalizedVersion(bundle.get_activity_version()):
                logging.debug("Bundle already known")
                return installed
            if not force_downgrade and \
                    NormalizedVersion(installed.get_activity_version()) >= \
                    NormalizedVersion(bundle.get_activity_version()):
                logging.debug('Skip old version for %s', bundle_id)
                return None
            else:
                logging.debug('Upgrade %s', bundle_id)
                self.remove_bundle(installed.get_path(), emit_signals)

        if set_favorite:
            favorite = not self.is_bundle_hidden(
                bundle.get_bundle_id(), bundle.get_activity_version())
            self._set_bundle_favorite(bundle.get_bundle_id(),
                                      bundle.get_activity_version(),
                                      favorite)

        with self._lock:
            self._bundles.append(bundle)
        if emit_signals:
            self.emit('bundle-added', bundle)
        return bundle
 def test_bundle_from_dir(self):
     bundle = bundle_from_dir(SAMPLE_ACTIVITY_PATH)
     self.assertIsInstance(bundle, ActivityBundle)
     bundle = bundle_from_dir(SAMPLE_CONTENT_PATH)
     self.assertIsInstance(bundle, ContentBundle)