コード例 #1
0
ファイル: __main__.py プロジェクト: tilmanpotthof/upmctl
def run(args):
    client = Client(base_url=args.base_url,
                    base_auth=args.base_authentication)
    pp = pprint.PrettyPrinter()

    if hasattr(args, 'list'):
        if args.user:
            plugins = list_plugins(client, key='userInstalled',
                                   value='boolean', pattern='true')
        elif args.system:
            plugins = list_plugins(client, key='userINstalled',
                                   value='boolean', pattern='false')
        elif args.key:
            plugins = list_plugins(client, key='key', value='regex',
                                   pattern=args.key)
        elif args.key_configuration_file:
            config = read_config(args.key_configuration_file)
            key = get_key_config(config)
            plugins = list_plugins(client, key='key', value='regex',
                                   pattern=key)
        else:
            plugins = list_plugins(client)
        pp.pprint(plugins)
    elif hasattr(args, 'show'):
        plugin = show_plugin(client, args.key)
        pp.pprint(plugin)
コード例 #2
0
ファイル: __main__.py プロジェクト: tschaefer/upmctl
def run(args):
    client = Client(base_url=args.base_url,
                    base_auth=args.base_authentication)

    try:

        if hasattr(args, 'list'):
            if args.user:
                plugins = list_plugins(client, key='userInstalled',
                                       value='boolean', pattern='true')
            elif args.system:
                plugins = list_plugins(client, key='userInstalled',
                                       value='boolean', pattern='false')
            elif args.key:
                plugins = list_plugins(client, key='key', value='regex',
                                       pattern=args.key)
            elif args.key_configuration_file:
                config = read_config(args.key_configuration_file)
                key = get_key_config(config)
                plugins = list_plugins(client, key='key', value='regex',
                                       pattern=key)
            else:
                plugins = list_plugins(client)
            if plugins is not None:
                print plugins
        elif hasattr(args, 'show'):
            plugin = show_plugin(client, args.key)
            print plugin
        elif hasattr(args, 'install'):
            token = get_upm_token(client)
            client.request.url = args.base_url
            install_plugin(client, token, args.plugin)
        elif hasattr(args, 'delete'):
            delete_plugin(client, args.key)
        elif hasattr(args, 'activate'):
            activate_plugin(client, args.key)
        elif hasattr(args, 'deactivate'):
            deactivate_plugin(client, args.key)

    except ClientError as e:
        print >> sys.stderr, "%s: %s" % ('upmctl', e)
        sys.exit(1)

    sys.exit(0)
コード例 #3
0
def method_list_plugins():
    plugins.list_plugins()
コード例 #4
0
ファイル: new.py プロジェクト: havocesp/new
def main(argd):
    """ Main entry point, expects doctopt arg dict as argd """
    global DEBUG
    plugins.DEBUG = DEBUG = argd['--debug']

    # Load all available plugins.
    plugins.load_plugins(PLUGINDIR)

    # Do any procedures that don't require a file name/type.
    if argd['--plugins']:
        plugins.list_plugins()
        return 0
    elif argd['--config']:
        return 0 if plugins.config_dump() else 1

    # Determine plugin based on file name/file type/explicit name.
    plugin = plugins.determine_plugin(argd)
    if not plugin:
        ftype = argd['PLUGIN'] or argd['FILENAME']
        errmsg = '\n'.join(
            ('Not a valid file type (not supported): {}',
             'Use --plugins to list available plugins.\n')).format(ftype)
        print_err(errmsg)
        return 1

    if argd['--executable'] and 'chmodx' in plugin.ignore_post:
        # Current behaviour says files are made executable unless told
        # otherwise, so to 'force chmodx' simply means to remove it from the
        # 'ignored' list.
        with suppress(AttributeError, KeyError):
            plugin.ignore_post.remove('chmodx')

    pluginname = plugin.get_name().title()
    debug('Using plugin: {}'.format(pluginname))
    # Do plugin help.
    if argd['--pluginhelp']:
        return 0 if plugins.plugin_help(plugin) else 1
    elif argd['--pluginconfig']:
        return 0 if plugins.plugin_config_dump(plugin) else 1
    # Get valid file name for this file.
    fname = ensure_file_ext(argd['FILENAME'], plugin)

    # Make sure the file name doesn't conflict with any plugins.
    # ...mainly during development and testing.
    if plugins.conflicting_file(plugin, argd['FILENAME'], fname):
        return 1

    try:
        content = plugin._create(fname, argd['ARGS'])
    except plugins.SignalAction as action:
        # See if we have content to write
        # No-content is fatal unless explicitly allowed.
        if not (action.content or plugin.allow_blank):
            errmsg = 'Plugin action with no content!\n    {}'
            print(errmsg.format(action.message))
            return 1

        content = action.content
        # Print plugin notification of any major changes (file name changes)
        if action.message:
            print(action.message)
        # Plugin is changing the output file name.
        if action.filename:
            fname = action.filename
    except plugins.SignalExit as excancel:
        # Plugin wants to stop immediately.
        if excancel.code != 0:
            # This was a real error, so print a message.
            reason = excancel.reason or 'No reason was given for the exit.'
            print('\n{}\n'.format(reason))
        return excancel.code
    except Exception as ex:
        print_ex(ex, '{} error:'.format(pluginname), with_class=True)
        return 1

    # Confirm overwriting existing files, exit on refusal.
    # Non-existant file names are considered valid, and need no confimation.
    if not valid_filename(fname):
        return 1

    if not (plugin.allow_blank or content):
        debug('{} is not allowed to create a blank file.'.format(pluginname))
        print('\nFailed to create file: {}'.format(fname))
        return 1

    return handle_content(fname, content, plugin, dryrun=argd['--dryrun'])
コード例 #5
0
ファイル: urls.py プロジェクト: SnifferNandez/bCTF
    path('activate/<uidb64>/<token>/', ActivateView.as_view(),
         name='activate'),

    # API
    path('api-auth/', include('rest_framework.urls')),
    path('v1/', include(router.urls)),

    # apps
    path('', include('apps.scoreboard.urls')),
    path('api/', include('api.urls')),
    path('administration/', include('apps.administration.urls')),
    path('teams/', include('apps.teams.urls')),
    path('challenges/', include('apps.challenges.urls')),
    path('pages/', include('apps.pages.urls')),
    path('importer/', include('apps.tasksimporter.urls')),

    # installer
    path('install/', InstallView.as_view(), name='installer'),
]

print(list_plugins())

if settings.DEBUG is True:
    import debug_toolbar
    urlpatterns += [
        path('super-secret/', admin.site.urls),
        path('__debug__/', include(debug_toolbar.urls)),
    ]
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
コード例 #6
0
ファイル: new.py プロジェクト: welbornprod/new
def main(argd):
    """ Main entry point, expects doctopt arg dict as argd """
    global DEBUG
    DEBUG = argd['--debug']
    if not DEBUG:
        plugins.debugprinter.disable()
    if argd['--customhelp']:
        return 0 if plugins.custom_plugin_help() else 1

    try:
        # Load all available plugins.
        plugins.load_plugins(PLUGINDIR)
    except plugins.InvalidConfig as ex:
        print_err(ex)
        return 1

    # Do any procedures that don't require a file name/type.
    if argd['--plugins']:
        plugins.list_plugins()
        return 0
    elif argd['--config']:
        return 0 if plugins.config_dump() else 1

    # Determine plugin based on file name/file type/explicit name.
    use_default_plugin = not (argd['--pluginhelp'] or argd['--pluginconfig'])
    debug('Use default plugin?: {}'.format(use_default_plugin))
    plugin = get_plugin(argd, use_default=use_default_plugin)
    if not plugin:
        # Not a valid plugin name, user cancelled text plugin use.
        return 1

    if DEBUG_PLUGIN:
        plugins.print_json(plugin.attributes(), sort_keys=True)

    # Notify plugin that this might be a dry run.
    plugin.dryrun = argd['--dryrun']

    if argd['--executable'] and 'chmodx' in plugin.ignore_post:
        # Current behaviour says files are made executable unless told
        # otherwise, so to 'force chmodx' simply means to remove it from the
        # 'ignored' list.
        try:
            plugin.ignore_post.remove('chmodx')
        except (AttributeError, KeyError):
            pass
    pluginname = plugin.get_name().title()
    debug('Using plugin: {}'.format(pluginname))
    # Do plugin help.
    if argd['--pluginhelp']:
        return 0 if plugin.help() else 1
    elif argd['--pluginconfig']:
        return 0 if plugin.config_dump() else 1
    elif hasattr(plugin, 'run'):
        # This is a post plugin, it should only be used as a command.
        debug(
            'Running post-processing plugin as command: {}'.format(pluginname))
        try:
            exitcode = plugin._run(args=argd['ARGS'])
        except NotImplementedError as ex:
            print_err(str(ex))
            exitcode = 1
        except plugins.SignalExit as excancel:
            exitcode = handle_signalexit(excancel)
        except Exception:
            exitcode = handle_exception('{} error:'.format(pluginname),
                                        *sys.exc_info())
        return exitcode

    # Get valid file name for this file.
    fname = expand_path(ensure_file_ext(argd['FILENAME'], plugin))

    # Make sure the file name doesn't conflict with any plugins.
    # ...mainly during development and testing.
    if plugins.conflicting_file(plugin, argd['FILENAME'], fname):
        return 1

    try:
        content = plugin._create(fname, argd['ARGS'])
    except plugins.SignalAction as action:
        # See if we have content to write
        # No-content is fatal unless explicitly allowed.
        if not (action.content or plugin.allow_blank):
            errmsg = 'Plugin action with no content!\n    {}'
            print_err(errmsg.format(action.message))
            return 1

        content = action.content
        # Print plugin notification of any major changes (file name changes)
        if action.message:
            for line in action.message.split('\n'):
                plugin.print_status(line)
        # Plugin is changing the output file name.
        if action.filename:
            fname = action.filename
        # Plugin is adding ignore_post plugins.
        if action.ignore_post:
            debug('Adding ignore_post: {!r}'.format(action.ignore_post))
            plugin.ignore_post.update(action.ignore_post)
    except plugins.SignalExit as excancel:
        # Plugin wants to stop immediately.
        return handle_signalexit(excancel)
    except Exception:
        return handle_exception('{} error:'.format(pluginname),
                                *sys.exc_info())

    # Confirm overwriting existing files, exit on refusal.
    # Non-existant file names are considered valid, and need no confimation.
    if not valid_filename(
            fname, dryrun=argd['--dryrun'], overwrite=argd['--overwrite']):
        return 1

    if not (plugin.allow_blank or content):
        debug('{} is not allowed to create a blank file.'.format(pluginname))
        print_err('\nFailed to create file: {}'.format(fname))
        return 1

    if argd['--noopen']:
        # Don't open the file.
        debug('Cancelling open plugin for {}'.format(plugin.get_name()))
        plugin.ignore_deferred.add('open')

    return handle_content(fname, content, plugin, dryrun=argd['--dryrun'])
コード例 #7
0
ファイル: new.py プロジェクト: welbornprod/new
def main(argd):
    """ Main entry point, expects doctopt arg dict as argd """
    global DEBUG
    DEBUG = argd['--debug']
    if not DEBUG:
        plugins.debugprinter.disable()
    if argd['--customhelp']:
        return 0 if plugins.custom_plugin_help() else 1

    try:
        # Load all available plugins.
        plugins.load_plugins(PLUGINDIR)
    except plugins.InvalidConfig as ex:
        print_err(ex)
        return 1

    # Do any procedures that don't require a file name/type.
    if argd['--plugins']:
        plugins.list_plugins()
        return 0
    elif argd['--config']:
        return 0 if plugins.config_dump() else 1

    # Determine plugin based on file name/file type/explicit name.
    use_default_plugin = not (argd['--pluginhelp'] or argd['--pluginconfig'])
    debug('Use default plugin?: {}'.format(use_default_plugin))
    plugin = get_plugin(argd, use_default=use_default_plugin)
    if not plugin:
        # Not a valid plugin name, user cancelled text plugin use.
        return 1

    if DEBUG_PLUGIN:
        plugins.print_json(plugin.attributes(), sort_keys=True)

    # Notify plugin that this might be a dry run.
    plugin.dryrun = argd['--dryrun']

    if argd['--executable'] and 'chmodx' in plugin.ignore_post:
        # Current behaviour says files are made executable unless told
        # otherwise, so to 'force chmodx' simply means to remove it from the
        # 'ignored' list.
        try:
            plugin.ignore_post.remove('chmodx')
        except (AttributeError, KeyError):
            pass
    pluginname = plugin.get_name().title()
    debug('Using plugin: {}'.format(pluginname))
    # Do plugin help.
    if argd['--pluginhelp']:
        return 0 if plugin.help() else 1
    elif argd['--pluginconfig']:
        return 0 if plugin.config_dump() else 1
    elif hasattr(plugin, 'run'):
        # This is a post plugin, it should only be used as a command.
        debug('Running post-processing plugin as command: {}'.format(
            pluginname
        ))
        try:
            exitcode = plugin._run(args=argd['ARGS'])
        except NotImplementedError as ex:
            print_err(str(ex))
            exitcode = 1
        except plugins.SignalExit as excancel:
            exitcode = handle_signalexit(excancel)
        except Exception:
            exitcode = handle_exception(
                '{} error:'.format(pluginname),
                *sys.exc_info())
        return exitcode

    # Get valid file name for this file.
    fname = expand_path(
        ensure_file_ext(argd['FILENAME'], plugin)
    )

    # Make sure the file name doesn't conflict with any plugins.
    # ...mainly during development and testing.
    if plugins.conflicting_file(plugin, argd['FILENAME'], fname):
        return 1

    try:
        content = plugin._create(fname, argd['ARGS'])
    except plugins.SignalAction as action:
        # See if we have content to write
        # No-content is fatal unless explicitly allowed.
        if not (action.content or plugin.allow_blank):
            errmsg = 'Plugin action with no content!\n    {}'
            print_err(errmsg.format(action.message))
            return 1

        content = action.content
        # Print plugin notification of any major changes (file name changes)
        if action.message:
            for line in action.message.split('\n'):
                plugin.print_status(line)
        # Plugin is changing the output file name.
        if action.filename:
            fname = action.filename
        # Plugin is adding ignore_post plugins.
        if action.ignore_post:
            debug('Adding ignore_post: {!r}'.format(action.ignore_post))
            plugin.ignore_post.update(action.ignore_post)
    except plugins.SignalExit as excancel:
        # Plugin wants to stop immediately.
        return handle_signalexit(excancel)
    except Exception:
        return handle_exception(
            '{} error:'.format(pluginname),
            *sys.exc_info())

    # Confirm overwriting existing files, exit on refusal.
    # Non-existant file names are considered valid, and need no confimation.
    if not valid_filename(
            fname,
            dryrun=argd['--dryrun'],
            overwrite=argd['--overwrite']):
        return 1

    if not (plugin.allow_blank or content):
        debug('{} is not allowed to create a blank file.'.format(pluginname))
        print_err('\nFailed to create file: {}'.format(fname))
        return 1

    if argd['--noopen']:
        # Don't open the file.
        debug('Cancelling open plugin for {}'.format(plugin.get_name()))
        plugin.ignore_deferred.add('open')

    return handle_content(fname, content, plugin, dryrun=argd['--dryrun'])