def packages_list(api: Sarasvati, args: CommandArguments):
    """Lists all the packages could be installed."""
    def _to_s(package):
        return f"<green>{package.key:<20}</green> {package.description}"

    text = list(map(_to_s, api.packages.packages))
    return CommandResult(text)
Beispiel #2
0
    def do(self):
        # get commad info
        command_info = self.__command_line.get_command(self.__command)
        if not command_info:
            raise CommandException(f"No '{self.__command}' command registered")

        self.__command_line.alias(self.__alias, self.__command)
        return CommandResult(f"Alias created.")
def packages_install(api: Sarasvati, args: CommandArguments):
    """Installs all provided packages."""
    # check if package name is provided (or list of names)
    packages = args.arg
    if not packages:
        raise CommandException("No package name provided")

    # install each package one by one
    try:
        packages = args.arg.split(" ")
        for package in packages:
            api.packages.add(package)
    except PackagesException as ex:
        raise CommandException(f"Unable to install package. {ex}")

    # return result: how many packages has been installed
    hint = "Run <blue>/reload-plugins</blue> to load installed plugins."
    return CommandResult(
        f"Package <green>{packages[0]}</green> has been installed. {hint}"
        if len(packages) ==
        1 else f"{len(packages)} packages has been installed. {hint}")
def reload_plugins(api: Sarasvati):
    """Reloads all plugins."""
    def _get_loaded_plugins():
        return list(map(lambda x: x.info.name, api.plugins.all))

    def _build_diff_str(items: List, sign: str, color: str) -> List[str]:
        return list(map(lambda x: f"<{color}>{sign} {x}</{color}>", items))

    # reload plugins and get diff info
    before = _get_loaded_plugins()
    api.plugins.update()
    after = _get_loaded_plugins()

    # build string
    loaded = _build_diff_str(list(set(after) - set(before)), "+", "green")
    unloaded = _build_diff_str(list(set(before) - set(after)), "-", "red")
    modified = loaded + unloaded
    result = "\n".join(modified)

    # return result
    return CommandResult(
        result if modified else "No plugins loaded or unloaded.")
def disable_plugin(api: Sarasvati, args: CommandArguments):
    """Disbale plugin."""
    name = args.arg
    api.plugins.disable_plugin(name)
    return CommandResult(f"Plugin '{name}' disabled.")
def packages_update(api: Sarasvati, args: CommandArguments):
    """Updates local repositories cache."""
    api.packages.update()
    replen = len(api.packages.repositories)
    return CommandResult(f"{replen} Repositories has been updated")
def enable_plugin(api: Sarasvati, args: CommandArguments):
    """Enable plugin."""
    name = args.arg
    api.plugins.enable_plugin(name)
    return CommandResult(f"Plugin '{name}' enabled.")
def list_plugins(api: Sarasvati):
    """Lists all of a loaded plugins."""
    def _to_s(plugin):
        return f"<green>{plugin.info.name}</green>"

    return CommandResult(list(map(_to_s, api.plugins.all)))