Esempio n. 1
0
    def __init__(self, name: str, meta: TingMeta, init_values: Mapping[str,
                                                                       Any]):

        self._input_sets = FreckletInput()

        self._base_args: Optional[RecordArg] = None
        self._base_vars: Optional[VarSet] = None

        self._required_args: Optional[RecordArg] = None
        self._required_vars: Optional[VarSet] = None

        self._input_args: Optional[RecordArg] = None
        self._input_vars: Optional[VarSet] = None

        self._processed_args: Optional[RecordArg] = None
        self._processed_vars: Optional[Mapping[str, Any]] = None

        self._vars: Optional[Mapping[str, Any]] = None

        self._result_args: Optional[RecordArg] = None
        self._result: Optional[TasksResult] = None

        self._current_console: Optional[Console] = None

        super().__init__(name=name, meta=meta)
        wrap_async_task(self.init_frecklet, init_values)
Esempio n. 2
0
    def format_commands(self, ctx, formatter):
        """Extra format methods for multi methods that adds all the commands
        after the options.
        """

        wrap_async_task(print_pkg_list_help,
                        bring=self._bring,
                        formatter=formatter)
Esempio n. 3
0
    def base_metadata(self) -> Mapping[str, Any]:

        if self._base_metadata is None:
            self._base_metadata = wrap_async_task(
                self.data.get_value, "info", _raise_exception=True
            )
        return self._base_metadata
Esempio n. 4
0
async def create_pkg_list_for_help(
    bring: Bring, indicate_optional_index: bool = True
) -> List[Tuple[str, str]]:
    """Extra format methods for multi methods that adds all the commands
    after the options.
    """

    default_index_name = wrap_async_task(bring.get_default_index)

    pkgs = await bring.get_pkg_property_map("info", "index_name")

    short_help_map = []

    for pkg_name in sorted(pkgs.keys()):
        details = pkgs[pkg_name]
        info = details["info"]
        index_name = details["index_name"]
        short_help = info.get("slug", "n/a")
        if short_help.endswith("."):
            short_help = short_help[0:-1]

        if index_name == default_index_name:
            tokens = pkg_name.split(".")
            # _name = tokens[1]
            _name = f"[{tokens[0]}.]{tokens[1]}"
        else:
            _name = pkg_name

        short_help_map.append((_name, short_help))

    return short_help_map
Esempio n. 5
0
    async def get_info(self) -> Doc:

        args: Dict[str, Any] = {"include_metadata": True}
        if self.update:
            args["retrieve_config"] = {"metadata_max_age": 0}

        info: MutableMapping[str, Any] = await self.data.get_values(  # type: ignore
            resolve=True
        )  # type: ignore

        metadata_timestamp = info["metadata_timestamp"]
        t = arrow.get(metadata_timestamp)

        doc_dict = dict(info["info"])
        doc_dict["metadata_timestamp"] = t.humanize()
        if info["labels"]:
            doc_dict["labels"] = info["labels"]
        if info["tags"]:
            doc_dict["tags"] = info["tags"]

        doc_dict["uri"] = info["uri"]
        defaults = info["defaults"]
        if defaults:
            defaults_markdown: Union[str, Syntax] = create_dict_element(
                _theme=bring_code_theme, **defaults
            )
        else:
            defaults_markdown = "  -- no defaults --"
        doc_dict["defaults"] = defaults_markdown

        doc_dict["index_type"] = info["index_type"]
        config = info["index_type_config"]
        if not config:
            _config: Union[str, Syntax] = "  -- no config --"
        else:
            _config = create_dict_element(_theme=bring_code_theme, **config)
        doc_dict["config"] = _config

        if self.display_packages:

            pkg_infos = wrap_async_task(self.data.get_all_pkg_values, "info")

            table = Table(box=box.SIMPLE, show_header=False, padding=(0, 2, 0, 0))
            table.add_column("Name", no_wrap=True, style="bold deep_sky_blue4")
            table.add_column("Description", no_wrap=False, style="italic")
            for pkg, vals in sorted(pkg_infos.items()):
                slug = vals["info"].get("slug", "n/a")
                table.add_row(pkg, slug)

            doc_dict["packages"] = table

        doc = Doc(
            doc_dict, short_help_key=self._short_help_key, help_key=self._help_key
        )

        return doc
Esempio n. 6
0
    def get_unique_source_id(
        self, source_details: Mapping, bring_index: BringIndexTing
    ) -> str:

        pkgs = wrap_async_task(
            self.get_child_pkgs, source_details=source_details, bring_index=bring_index
        )
        pkg_names = sorted(pkgs.keys())

        return "_".join(pkg_names)
Esempio n. 7
0
def register_bring_frecklet_types(bring: Bring, freckles: Freckles) -> None:

    current = freckles.current_input

    if current.get("frecklet_types") == NO_VALUE_MARKER:
        current = {}

    to_add = {}

    if "install_pkg" not in current.keys():

        from freckles.frecklets.install_pkg import BringInstallFrecklet

        prototing_name_install_pkg = f"{bring.full_name}.frecklets.install_pkg"
        if prototing_name_install_pkg not in freckles.tingistry.ting_names:
            freckles.tingistry.register_prototing(
                prototing_name_install_pkg,
                BringInstallFrecklet,
                init_values={"bring": bring},
            )
        to_add["install_pkg"] = prototing_name_install_pkg

    if "install_assembly" not in current.keys():
        from freckles.frecklets.install_pkg import BringInstallAssemblyFrecklet

        prototing_name_install_assembly = (
            f"{bring.full_name}.frecklets.install_assembly"
        )
        if prototing_name_install_assembly not in freckles.tingistry.ting_names:
            freckles.tingistry.register_prototing(
                prototing_name_install_assembly,
                BringInstallAssemblyFrecklet,
                init_values={"bring": bring},
            )
        to_add["install_assembly"] = prototing_name_install_assembly

    if to_add:
        wrap_async_task(freckles.add_frecklet_types, _raise_exception=True, **to_add)
Esempio n. 8
0
    def __rich_console__(self, console: Console,
                         options: ConsoleOptions) -> RenderResult:

        if self._diff is None:
            wrap_async_task(self.get_diff)

        if self._diff is None:
            raise Exception("Can't print index diff, this is a bug.")

        added = self._diff.get("added", None)
        removed = self._diff.get("removed", None)
        added_versions = self._diff.get("versions_added", None)
        removed_versions = self._diff.get("versions_removed", None)

        if added:
            if len(added) == 1:
                _ps = "package"
            else:
                _ps = "packages"
            yield f"- [title]added {_ps}:[/title]"
            for a in sorted([a.name for a in added]):
                yield f"  - {a}"
        else:
            yield "- [title]no added packages[/title]"
        yield ""

        if added_versions:
            if len(added_versions) == 1:
                _ps = "package"
            else:
                _ps = "packages"
            yield f"- [title]added versions in {_ps}:[/title]"
            versions_set = set()

            for pkg, versions in sorted(added_versions.items()):
                yield f"    [key2]{pkg.name}[/key2]:"
                for v in versions:
                    _v = v.get("version", "n/a")
                    versions_set.add(_v)
                for v in sorted(versions_set):
                    yield f"      - {v}"
        else:
            yield "- [title]no versions added to any packages[/title]"

        yield ""

        if removed:
            if len(removed) == 1:
                _ps = "package"
            else:
                _ps = "packages"
            yield f"- [title][red]removed {_ps}:[/red][/title]"
            for r in sorted(removed):
                yield f"  - {r.name}"
        else:
            yield "- [title]no removed packages[/title]"
        yield ""

        if removed_versions:
            if len(removed_versions) == 1:
                _ps = "package"
            else:
                _ps = "packages"
            yield f"- [bold red]removed versions in {_ps}:[/bold red]"
            versions_set = set()
            for pkg, versions in sorted(removed_versions.items()):

                yield f"    [key2]{pkg.name}[/key2]:"
                for v in versions:
                    _v = v.get("version", "n/a")
                    versions_set.add(_v)
                for v in sorted(versions_set):
                    yield f"      - {v}"
Esempio n. 9
0
    def id(self) -> str:

        if self._id is None:
            self._id = wrap_async_task(self.get_value, "id")
        return self._id
Esempio n. 10
0
    def get_unique_source_id(self, source_details: Mapping,
                             bring_index: BringIndexTing) -> str:

        pkg = wrap_async_task(self.get_parent_pkg, source_details, bring_index)

        return pkg.full_name
Esempio n. 11
0
    def get_config_value(self, key: str) -> Any:

        if self._config_dict is None:
            wrap_async_task(self.get_config_dict)

        return self._config_dict.get(key, None)  # type: ignore