Beispiel #1
0
def show(ctx, name_only, cmds, all, fields, format, **kwargs):
    """Show the flow dependencies of a command"""
    show_empty = len(cmds) > 0
    if all:
        cmds = cmds or sorted(get_sub_commands(ctx, config.main_command))
    else:
        cmds = cmds or sorted(config.flowdeps.readonly.keys())
    with TablePrinter(fields, format) as tp, Colorer(kwargs) as colorer:
        for cmd in cmds:
            if name_only:
                click.echo(cmd)
            else:
                if all:
                    deps = get_flow_commands_to_run(cmd)
                    formatted = " ".join(quote(p) for p in deps)
                else:
                    values = {
                        profile.name: " ".join([
                            quote(p) for p in config.flowdeps.all_settings.get(
                                profile.name, {}).get(cmd, [])
                        ])
                        for profile in config.all_enabled_profiles
                    }
                    args = colorer.colorize(values,
                                            config.flowdeps.readprofile)
                    formatted = " ".join(args)
                if show_empty:
                    formatted = formatted or "None"
                if formatted:
                    tp.echo(cmd, formatted)
Beispiel #2
0
def show(fields, format, remote, location):
    """List the plugins to be loaded at runtime"""
    disabled_plugins = config.plugins.readonly.get('disabled_plugins', [])
    if not fields and not location:
        fields = list(get_option_choices('fields'))
        fields.remove('location')
    if remote:
        plugins = list_plugins_from_remote()
    else:
        plugins = [
            plugin_name(ensure_unicode(plugin))
            for plugin in config.plugins.plugins.list_plugins()
        ]

        def plugin_location(plugin):
            name = plugin.replace("/", "_")
            for path in config.plugins.plugins.searchpath:
                candidate = glob_first(os.path.join(path, name + ".py*"))
                if candidate is not None:
                    return candidate

        vals = [[
            plugin,
            'disabled' if plugin in disabled_plugins else 'enabled',
            load_short_help(plugin.replace('/', '_')),
            plugin_location(plugin),
        ] for plugin in sorted(plugins)]
    with TablePrinter(fields, format) as tp:
        tp.echos(vals)
Beispiel #3
0
def altered(fields, format):
    """Show the altered environment"""
    with TablePrinter(fields, format) as tp:
        for k in sorted(config.env.keys()):
            tp.echo(k, os.environ[k])
        for k in sorted(config.override_env.keys()):
            tp.echo(k, os.environ[k])
Beispiel #4
0
def show(name_only, aliases, under, fields, format, **kwargs):
    """Show the aliases"""
    if name_only:
        fields = ['alias']
    aliases = aliases or sorted(config.alias.readonly.keys())
    if under:
        aliases = [alias for alias in aliases if alias.startswith(under)]
    with TablePrinter(fields, format, separator=' , ') as tp, Colorer(kwargs) as colorer:
        for alias in aliases:
            if config.alias.readprofile == "settings-file":
                args = [format(config.alias.readonly.get(alias, {}).get("commands", []))]
            elif "/" in config.alias.readprofile:
                args = [
                    " ".join(command)
                    for command in
                    config.alias.all_settings.get(
                        config.alias.readprofile,
                        {}).get(alias)["commands"]
                ]
            else:
                all_values = [
                    (profile.name, config.alias.all_settings.get(profile.name, {}).get(alias))
                    for profile in config.all_enabled_profiles
                ]
                all_values = [(profile, value) for profile, value in all_values
                              if value is not None]
                last_profile, last_value = all_values[-1]
                last_command = last_value["commands"]
                args = [colorer.apply_color(" ".join(map(quote, token)), last_profile) for token in last_command]
            tp.echo(alias, args)
Beispiel #5
0
def show(ctx, name_only, cmds, under, fields, format, **kwargs):
    """Show the parameters of a command"""
    cmds = cmds or sorted(config.parameters.readonly.keys())
    if under:
        cmds = [cmd for cmd in cmds if cmd.startswith(under)]
    with TablePrinter(fields, format) as tp, Colorer(kwargs) as colorer:
        for cmd_name in cmds:
            if name_only:
                click.echo(cmd_name)
            else:
                cmd = get_command_safe(cmd_name)

                def get_line(profile_name):
                    return " ".join([
                        quote(p)
                        for p in
                        config.parameters.all_settings.get(profile_name, {}).get(cmd_name, [])
                    ])

                if config.parameters.readprofile == "settings-file":
                    args = config.parameters.readonly.get(cmd_name, [])
                else:
                    values = {
                        profile.name: get_line(profile.name)
                        for profile in config.all_enabled_profiles
                    }
                    args = colorer.colorize(values, config.parameters.readprofile)
                if args == [""]:
                    # the command most likely has implicit settings and only
                    # explicit values are asked for. Skip it
                    continue
                if cmd is None:
                    LOGGER.warning("You should know that the command {} does not exist".format(cmd_name))
                args = args or 'None'
                tp.echo(cmd_name, args)
def show(ctx, name_only, cmds, full, under, fields, format, **kwargs):
    """Show the parameters of a command"""
    cmds = cmds or sorted(config.parameters.readonly.keys())
    if under:
        cmds = [cmd for cmd in cmds if cmd.startswith(under)]
    with TablePrinter(fields, format) as tp, Colorer(kwargs, full) as colorer:
        for cmd_name in cmds:
            if name_only:
                click.echo(cmd_name)
            else:
                cmd = get_command_safe(cmd_name)

                def get_line(level_name):
                    return " ".join([
                        quote(p) for p in config.parameters.all_settings.get(
                            level_name, {}).get(cmd_name, [])
                    ])

                if config.parameters.readlevel == "settings-file":
                    args = config.parameters.readonly.get(cmd_name, [])
                elif "/" in config.parameters.readlevel:
                    args = get_line(config.parameters.readlevel)
                else:
                    values = {
                        level_name: get_line(level_name)
                        for level_name in colorer.level_to_color
                    }
                    args = colorer.colorize(values,
                                            config.parameters.readlevel)
                if cmd is None:
                    LOGGER.warning(
                        "You should know that the command {} does not exist".
                        format(cmd_name))
                args = args or 'None'
                tp.echo(cmd_name, args)
Beispiel #7
0
def show(fields, format, **kwargs):
    """List the path of all custom commands."""
    with TablePrinter(fields, format) as tp, Colorer(kwargs) as colorer:
        for profile in config.all_directory_profiles:
            for plugin in profile.plugin_source.list_plugins():
                tp.echo(colorer.apply_color(plugin, profile.name),
                        profile.plugin_short_doc(plugin) or "")
Beispiel #8
0
def show(machine, fields, format, password):
    """Show the login/password"""
    res = get_keyring().get_password("click_project", machine)
    if res:
        login, password_ = json.loads(res)
        if not password:
            password_ = "*****"
        with TablePrinter(fields, format) as tp:
            tp.echo(login, password_)
    else:
        LOGGER.warn("No login/password set")
Beispiel #9
0
def show(fields, format, link, order, recipes, enabled_only, disabled_only,
         **kwargs):
    """List the recipes and some info about them"""
    config_recipes = set(config.recipe.readonly.keys())
    avail_recipes = set([r.short_name for r in config.all_recipes])
    if not fields:
        fields = list(get_option_choices('fields'))
        if not link:
            fields.remove('link')
        if not order:
            fields.remove('order')

    if not recipes:
        for profile in config.root_profiles:
            config_recipes |= profile.recipe_link_names
        recipes = config_recipes | avail_recipes
    if not recipes:
        LOGGER.status("No recipe yet")
        exit(0)
    with Colorer(kwargs) as colorer, TablePrinter(fields, format) as tp:
        for recipe_name in sorted(recipes):
            profiles = ", ".join([
                click.style(profile.name, **colorer.get_style(profile.name))
                for profile in config.root_profiles
                if profile.has_recipe(recipe_name)
            ])
            link_profiles = ", ".join([
                profile.name for profile in config.root_profiles
                if profile.has_recipe_link(recipe_name)
            ])
            profile = colorer.last_profile_of_settings(
                recipe_name,
                config.recipe.all_settings,
            )
            recipe_enabled = config.is_recipe_enabled(recipe_name)
            if ((not enabled_only or recipe_enabled)
                    and (not disabled_only or not recipe_enabled)):
                profile_style = colorer.get_style(profile) if profile else {}

                tp.echo(
                    click.style(recipe_name,
                                fg="green" if recipe_enabled else "red"),
                    (profile and click.style(profile, **profile_style))
                    or "Unset",
                    profiles or "Undefined",
                    link_profiles,
                    config.get_recipe_order(recipe_name),
                )
Beispiel #10
0
def show(format, all, fields, index):
    """Show the git records

    The first value is the path where the file/directory should be located. Ths
    second value is the name of the file in the git store. Since git is content
    addressable, a same git store name indicates a same content.

    """
    if index and all:
        raise click.UsageError("--index and --all are mutually exclusives")

    index = index or 1
    locally_avail_names = {
        r[1]
        for r in get_refs()
    }

    def format_records(records):
        def format_record(record):
            res = record["name"]
            if "documentation" in record and record["documentation"]:
                res += " '{}'".format(record["documentation"])
            if record["name"] in locally_avail_names:
                res += " (in here)"
            else:
                res += " (not in here)"
            if "date" in record:
                res += " (Recorded at {})".format(dateutil.parser.parse(record["date"]))
            return res

        top = records[-index]
        res = format_record(top)
        if len(records) > 1:
            res += " ({}/{})".format(index, len(records))
        if all and len(records) > 1:
            res += ". Other records: {}".format(
                ", ".join(
                    "{}: {}".format(index_ + 1, format_record(record))
                    for index_, record in enumerate(reversed(records[:-1]))
                )
            )
        return res

    with TablePrinter(fields, format) as tp:
        for key in sorted(config.git_record.readonly.keys()):
            tp.echo(key, format_records(config.git_record.readonly[key]))
Beispiel #11
0
def show(fields, format, **kwargs):
    """Show all the custom commands paths"""
    with Colorer(kwargs) as colorer, TablePrinter(fields, format) as tp:
        values = {
            profile.name: format_paths(
                config.customcommands.all_settings.get(profile.name, {}).get(
                    "pythonpaths", []))
            for profile in config.all_enabled_profiles
        }
        args = colorer.colorize(values, config.customcommands.readprofile)
        tp.echo("pythonpaths", " ".join(args))
        values = {
            profile.name: format_paths(
                config.customcommands.all_settings.get(profile.name, {}).get(
                    "executablepaths", []))
            for profile in config.all_enabled_profiles
        }
        args = colorer.colorize(values, config.customcommands.readprofile)
        tp.echo("executablepaths", " ".join(args))
Beispiel #12
0
def show(ctx, name_only, launchers, all, fields, format, **kwargs):
    """Show the launchers"""
    launchers = launchers or sorted(config.settings.get("launchers", {}))
    with TablePrinter(fields, format) as tp, Colorer(kwargs, all) as colorer:
        for launcher_name in launchers:
            if name_only:
                click.echo(launcher_name)
            else:
                if config.launchers.readlevel == "settings-file":
                    args = config.launchers.readonly.get(launcher_name, [])
                else:
                    values = {
                        level_name: " ".join([
                            quote(p) for p in config.launchers.
                            all_settings[level_name].get(launcher_name, [])
                        ])
                        for level_name in colorer.level_to_color
                    }
                    args = colorer.colorize(values, config.launchers.readlevel)
                if args and args[0]:
                    tp.echo(launcher_name, args)
Beispiel #13
0
def show(ctx, name_only, launchers, fields, format, **kwargs):
    """Show the launchers"""
    launchers = launchers or sorted(config.settings.get("launchers", {}))
    with TablePrinter(fields, format) as tp, Colorer(kwargs) as colorer:
        for launcher_name in launchers:
            if name_only:
                click.echo(launcher_name)
            else:
                if config.launchers.readprofile == "settings-file":
                    args = config.launchers.readonly.get(launcher_name, [])
                else:
                    values = {
                        profile.name: " ".join([
                            quote(p) for p in config.launchers.all_settings[
                                profile.name].get(launcher_name, [])
                        ])
                        for profile in config.all_enabled_profiles
                    }
                    args = colorer.colorize(values,
                                            config.launchers.readprofile)
                if any(args):
                    tp.echo(launcher_name, args)
Beispiel #14
0
def show(remote, format, fields, with_notes, name):
    """Show the available files

    It also show some low level information about the file, like its hash value.

    If you want to list the files of a remote, use the --remote option.
    """
    refs = [
        r for r in get_refs(remote)
        if not name or "refs/git-store/" + r[1] in name
    ]

    def get(blob_ref):
        ref = "refs/git-store/" + blob_ref[1]
        res = "Hash: {}".format(blob_ref[0][:8])
        try:
            typ = check_output(
                [git(), "cat-file", "-t", ref],
                nostderr=True,
                internal=True,
            ).strip()
        except subprocess.CalledProcessError:
            typ = "unknown"
        res += " , Type: {}".format(typ)
        if with_notes:
            try:
                note = check_output(notes_command() + ["show", ref],
                                    nostderr=True).strip()
            except subprocess.CalledProcessError:
                note = None
            if note:
                res += " , Note: {}".format(note.splitlines()[0])
        return res

    with TablePrinter(fields, format) as tp:
        for ref in refs:
            tp.echo(ref[1], get(ref))
 def show(fields, format, keys, all, **kwargs):
     """Show the values"""
     keys = keys or (sorted(config.settings.get(settings_name, {}))
                     if all else sorted(
                         getattr(config, settings_name).readonly.keys()))
     with TablePrinter(fields, format) as tp, Colorer(kwargs,
                                                      all) as colorer:
         for key in keys:
             if getattr(config, settings_name).readlevel == "settings-file":
                 args = [
                     format(
                         getattr(config, settings_name).readonly.get(
                             key, {}).get("commands", []))
                 ]
             elif "/" in getattr(config, settings_name).readlevel:
                 args = getattr(config, settings_name).all_settings.get(
                     getattr(config, settings_name).readlevel,
                     {}).get(key, {}).get("value")
                 if args is None:
                     continue
             else:
                 all_values = [
                     (level,
                      getattr(config,
                              settings_name).all_settings.get(level,
                                                              {}).get(key))
                     for level in colorer.level_to_color.keys()
                 ]
                 all_values = [(level, value) for level, value in all_values
                               if value is not None]
                 if not all_values:
                     # noting to show for this key
                     continue
                 last_level, last_value = all_values[-1]
                 value = last_value["value"]
                 args = colorer.apply_color(value, last_level)
             tp.echo(key, args)
Beispiel #16
0
def dump(fields, format):
    """Show all the environment variables"""
    with TablePrinter(fields, format) as tp:
        for k in sorted(os.environ.keys()):
            tp.echo(k, os.environ[k])
Beispiel #17
0
def extended(fields, format):
    """Show the extended environment variables"""
    with TablePrinter(fields, format) as tp:
        for k in sorted(config.env.keys()):
            tp.echo(k, os.environ[k])
Beispiel #18
0
def overriden(fields, format):
    """Show the overriden environment variables"""
    with TablePrinter(fields, format) as tp:
        for k in sorted(config.override_env.keys()):
            tp.echo(k, os.environ[k])