Beispiel #1
0
def get_bundle(metadata):
    try:
        if is_activity_bundle(metadata):
            file_path = model.get_file(metadata['uid'])
            if not os.path.exists(file_path):
                logging.warning('Invalid path: %r', file_path)
                return None
            return get_bundle_instance(file_path)

        elif is_content_bundle(metadata):
            file_path = model.get_file(metadata['uid'])
            if not os.path.exists(file_path):
                logging.warning('Invalid path: %r', file_path)
                return None
            return ContentBundle(file_path)

        elif is_journal_bundle(metadata):
            file_path = model.get_file(metadata['uid'])
            if not os.path.exists(file_path):
                logging.warning('Invalid path: %r', file_path)
                return None
            return JournalEntryBundle(file_path, metadata['uid'])
        else:
            return None
    except Exception:
        logging.exception('Incorrect bundle')
        return None
Beispiel #2
0
def bundle_from_dir(path):
    """
    Return an appropriate Bundle object for a given directory containing
    an unzipped bundle.
    """
    if os.path.exists(os.path.join(path, 'activity', 'activity.info')):
        return ActivityBundle(path)
    elif os.path.exists(os.path.join(path, 'library', 'library.info')):
        return ContentBundle(path)
    return None
Beispiel #3
0
def bundle_from_archive(path, mime_type=None):
    """
    Return an appropriate Bundle object for a given file path.
    The bundle type is identified by mime_type, which is guessed if not
    provided.
    """
    if mime_type is None:
        mime_type, certainty = Gio.content_type_guess(path, data=None)
    if mime_type == ActivityBundle.MIME_TYPE:
        return ActivityBundle(path)
    elif mime_type == ContentBundle.MIME_TYPE:
        return ContentBundle(path)
    return None
Beispiel #4
0
def resume(metadata, bundle_id=None):
    registry = bundleregistry.get_registry()

    if is_activity_bundle(metadata) and bundle_id is None:

        logging.debug('Creating activity bundle')

        file_path = model.get_file(metadata['uid'])
        bundle = ActivityBundle(file_path)
        if not registry.is_installed(bundle):
            logging.debug('Installing activity bundle')
            try:
                registry.install(bundle)
            except AlreadyInstalledException:
                _downgrade_option_alert(bundle)
                return
        else:
            logging.debug('Upgrading activity bundle')
            registry.upgrade(bundle)

        _launch_bundle(bundle)

    elif is_content_bundle(metadata) and bundle_id is None:

        logging.debug('Creating content bundle')

        file_path = model.get_file(metadata['uid'])
        bundle = ContentBundle(file_path)
        if not bundle.is_installed():
            logging.debug('Installing content bundle')
            bundle.install()

        activities = _get_activities_for_mime('text/html')
        if len(activities) == 0:
            logging.warning('No activity can open HTML content bundles')
            return

        uri = bundle.get_start_uri()
        logging.debug('activityfactory.creating with uri %s', uri)

        activity_bundle = registry.get_bundle(activities[0].get_bundle_id())
        launch(activity_bundle, uri=uri)
    else:
        activity_id = metadata.get('activity_id', '')

        if bundle_id is None:
            activities = get_activities(metadata)
            if not activities:
                logging.warning('No activity can open this object, %s.',
                                metadata.get('mime_type', None))
                return
            bundle_id = activities[0].get_bundle_id()

        bundle = registry.get_bundle(bundle_id)

        if metadata.get('mountpoint', '/') == '/':
            object_id = metadata['uid']
        else:
            object_id = model.copy(metadata, '/')

        launch(bundle,
               activity_id=activity_id,
               object_id=object_id,
               color=get_icon_color(metadata))