Skip to content

Uninstall languages

hypha.apply.translate.management.commands.uninstall_languages

Command

Bases: BaseCommand

help class-attribute instance-attribute

help = "Delete all drafts that haven't been modified in the specified time (in days)"

installed_packages class-attribute instance-attribute

installed_packages = get_installed_packages()

add_arguments

add_arguments(parser)
Source code in hypha/apply/translate/management/commands/uninstall_languages.py
def add_arguments(self, parser):
    parser.add_argument(
        "languages",
        action="store",
        nargs="*",
        type=self.__validate_language,
        help='Language packages to uninstall in the format of "<from language>_<to language>" in ISO 639 format',
    )

    parser.add_argument(
        "--noinput",
        "--no-input",
        action="store_false",
        dest="interactive",
        help="Do not prompt the user for confirmation",
        required=False,
    )

    parser.add_argument(
        "--all",
        action="store_true",
        help="Uninstall all installed language packages",
        required=False,
    )

handle

handle(*args, **options)
Source code in hypha/apply/translate/management/commands/uninstall_languages.py
def handle(self, *args, **options):
    interactive = options["interactive"]
    packages = options["languages"]
    verbosity = options["verbosity"]

    # Require either languages or "--all" to be specified
    if not bool(packages) ^ bool(all):
        raise argparse.ArgumentTypeError("A language selection must be specified")

    if all:
        packages = self.installed_packages

    if verbosity > 1:
        self.stdout.write(
            f"The following package{'s' if len(packages) > 1 else ''} will be uninstalled:"
        )
        self.__print_package_list(packages)
    elif (
        interactive
    ):  # Only log what will be uninstalled if prompting the user to confirm
        self.stdout.write(
            f"{len(packages)} package{'s' if len(packages) > 1 else ''} will be uninstalled."
        )

    if interactive:
        confirm = input(
            "Are you sure you want to do this?\n\nType 'yes' to continue, or 'no' to cancel: "
        )
    else:
        confirm = "yes"

    if confirm == "yes":
        for package in packages:
            argostranslate.package.uninstall(package)

        successful_uninstalls = len(self.installed_packages) - len(
            argostranslate.package.get_installed_packages()
        )

        self.stdout.write(
            f"{successful_uninstalls} package{'s' if successful_uninstalls > 1 else ''} uninstalled."
        )
    else:
        self.stdout.write("Removal cancelled.")