def get_payment_plugins():
    """Returns a dict containing the available payment plugins."""
    return {
        remove_prefix_re.sub('', p.name): p
        for p in plugin_engine.get_active_plugins().itervalues()
        if isinstance(p, PaymentPluginMixin)
    }
def _call_with_plugins(*args, **kwargs):
    func = kwargs.pop('_func')
    ctx = click.get_current_context()
    all_plugins = ctx.parent.params['all_plugins']
    plugin = ctx.parent.params['plugin']
    if plugin:
        plugins = {plugin_engine.get_plugin(plugin)}
    elif all_plugins:
        plugins = set(plugin_engine.get_active_plugins().viewvalues())
    else:
        plugins = None

    if plugins is None:
        func(*args, **kwargs)
    else:
        PluginScriptDirectory.dir = os.path.join(current_app.root_path, 'core',
                                                 'plugins', 'alembic')
        alembic.command.ScriptDirectory = PluginScriptDirectory
        for plugin in plugins:
            if not os.path.exists(plugin.alembic_versions_path):
                print cformat(
                    "%{cyan}skipping plugin '{}' (no migrations folder)"
                ).format(plugin.name)
                continue
            print cformat("%{cyan!}executing command for plugin '{}'").format(
                plugin.name)
            with plugin.plugin_context():
                func(*args, **kwargs)
Beispiel #3
0
def _make_shell_context():
    context = {}
    info = [cformat('%{white!}Available objects')]
    add_to_context = partial(_add_to_context, context, info)
    add_to_context_multi = partial(_add_to_context_multi, context, info)
    add_to_context_smart = partial(_add_to_context_smart, context, info)
    # Common stdlib modules
    info.append(cformat('*** %{magenta!}stdlib%{reset} ***'))
    DATETIME_ATTRS = ('date', 'time', 'datetime', 'timedelta')
    ORM_ATTRS = ('joinedload', 'defaultload', 'contains_eager', 'lazyload',
                 'noload', 'subqueryload', 'undefer', 'undefer_group',
                 'load_only')
    add_to_context_multi([getattr(datetime, attr) for attr in DATETIME_ATTRS] +
                         [getattr(sqlalchemy.orm, attr)
                          for attr in ORM_ATTRS] + [itertools, re, sys, os],
                         color='yellow')
    # Models
    info.append(cformat('*** %{magenta!}Models%{reset} ***'))
    models = [
        cls for name, cls in sorted(db.Model._decl_class_registry.items(),
                                    key=itemgetter(0))
        if hasattr(cls, '__table__')
    ]
    add_to_context_smart(models)
    # Tasks
    info.append(cformat('*** %{magenta!}Tasks%{reset} ***'))
    tasks = [
        task for task in sorted(celery.tasks.values())
        if not task.name.startswith('celery.')
    ]
    add_to_context_smart(tasks,
                         get_name=lambda x: x.name.replace('.', '_'),
                         color='blue!')
    # Plugins
    info.append(cformat('*** %{magenta!}Plugins%{reset} ***'))
    plugins = [
        type(plugin)
        for plugin in sorted(plugin_engine.get_active_plugins().values(),
                             key=attrgetter('name'))
    ]
    add_to_context_multi(plugins, color='yellow!')
    # Utils
    info.append(cformat('*** %{magenta!}Misc%{reset} ***'))
    add_to_context(celery, 'celery', doc='celery app', color='blue!')
    add_to_context(db, 'db', doc='sqlalchemy db interface', color='cyan!')
    add_to_context(now_utc,
                   'now_utc',
                   doc='get current utc time',
                   color='cyan!')
    add_to_context(config, 'config', doc='fossir config')
    add_to_context(current_app, 'app', doc='flask app')
    add_to_context(lambda *a, **kw: server_to_utc(datetime.datetime(*a, **kw)),
                   'dt',
                   doc='like datetime() but converted from localtime to utc')
    add_to_context(Event.get, 'EE', doc='get event by id')
    # Stuff from plugins
    signals.plugin.shell_context.send(
        add_to_context=add_to_context,
        add_to_context_multi=add_to_context_multi)
    return context, info
def get_vc_plugins():
    """Returns a dict containing the available videoconference plugins."""
    from fossir.modules.vc import VCPluginMixin
    return {
        p.service_name: p
        for p in plugin_engine.get_active_plugins().itervalues()
        if isinstance(p, VCPluginMixin)
    }
def _get_sql_line():
    paths = [current_app.root_path] + [p.root_path for p in plugin_engine.get_active_plugins().itervalues()]
    stack = [item for item in reversed(traceback.extract_stack()) if _interesting_tb_item(item, paths)]
    for i, item in enumerate(stack):
        return {'file': item[0],
                'line': item[1],
                'function': item[2],
                'items': stack[i:i+5]}
Beispiel #6
0
def i18n_locale(locale_name):
    """
    Retrieve a locale in a Jed-compatible format
    """
    root_path = os.path.join(current_app.root_path, 'translations')
    plugin_key = ','.join(sorted(plugin_engine.get_active_plugins()))
    cache_file = os.path.join(
        config.CACHE_DIR,
        'assets_i18n_{}_{}.js'.format(locale_name, crc32(plugin_key)))

    if not os.path.exists(cache_file):
        i18n_data = locale_data(root_path, locale_name, 'fossir')
        if not i18n_data:
            # Dummy data, not having the fossir domain would cause lots of failures
            i18n_data = {
                'fossir': {
                    '': {
                        'domain': 'fossir',
                        'lang': locale_name
                    }
                }
            }

        for pid, plugin in plugin_engine.get_active_plugins().iteritems():
            data = {}
            if plugin.translation_path:
                data = locale_data(plugin.translation_path, locale_name, pid)
            if not data:
                # Dummy entry so we can still load the domain
                data = {pid: {'': {'domain': pid, 'lang': locale_name}}}
            i18n_data.update(data)

        with open(cache_file, 'wb') as f:
            f.write("window.TRANSLATIONS = {};".format(json.dumps(i18n_data)))

    return send_file('{}.js'.format(locale_name),
                     cache_file,
                     mimetype='application/javascript',
                     no_cache=False,
                     conditional=True)
    def _process(self):
        plugins = [p for p in plugin_engine.get_active_plugins().viewvalues()]
        categories = defaultdict(list)
        other = []
        for plugin in plugins:
            if plugin.category:
                categories[plugin.category].append(plugin)
            else:
                other.append(plugin)

        # Sort the plugins of each category in alphabetic order and in a way that the internal plugins are always
        # listed in the front
        for category in categories:
            categories[category].sort(key=attrgetter('configurable', 'title'))
        ordered_categories = OrderedDict(sorted(categories.items()))
        if other:
            ordered_categories[PluginCategory.other] = other
        return WPPlugins.render_template('index.html', categorized_plugins=ordered_categories)
def _get_menu_cache_data(event):
    from fossir.core.plugins import plugin_engine
    cache_key = unicode(event.id)
    plugin_hash = crc32(','.join(sorted(plugin_engine.get_active_plugins())))
    cache_version = '{}:{}'.format(fossir.__version__, plugin_hash)
    return cache_key, cache_version