Beispiel #1
0
 def add_packages(self):
     file_dialog = QFileDialog()
     filepaths = file_dialog.getOpenFileNames(
         self, 'Select .argosmodel package files', str(Path.home()),
         'Argos Models (*.argosmodel)')[0]
     if len(filepaths) > 0:
         for file_path in filepaths:
             package.install_from_path(file_path)
         self.packages_changed.emit()
         self.packages_table.populate()
Beispiel #2
0
def main():
    commands = ['update', 'install', 'list', 'remove']

    # Parse args
    parser = argparse.ArgumentParser()
    parser.add_argument('command', help=', '.join(commands))
    parser.add_argument('argument', nargs='?', help='Argument for command')
    args = parser.parse_args()

    # Parse command
    command = args.command
    if command not in commands:
        print(f'Unrecognized command {args.command}')
        print(f'Valid commands {commands}')
        exit(1)

    if command == 'update':
        package.update_package_index()

    elif command == 'install':
        available_packages = package.get_available_packages()
        package_name = args.argument
        package_found = False
        for available_package in available_packages:
            name = name_of_package(available_package)
            if name == package_name:
                download_path = available_package.download()
                package.install_from_path(download_path)
                print(f'Installed package to path {download_path}')
                package_found = True
                break
        if not package_found:
            print('Package not found')

    elif command == 'list':
        installed_packages = package.get_installed_packages()
        for installed_package in installed_packages:
            print(name_of_package(installed_package))

    elif command == 'remove':
        installed_packages = package.get_installed_packages()
        package_name = args.argument
        package_found = False
        for installed_package in installed_packages:
            name = name_of_package(installed_package)
            if name == package_name:
                installed_package.remove()
                print(f'Removed package {name}')
                package_found = True
                break
        if not package_found:
            print('Package not found')
Beispiel #3
0
def install_package(args):
    """Install package."""
    available_packages = package.get_available_packages()
    package_name = args.name
    for available_package in available_packages:
        name = package.argospm_package_name(available_package)
        if name == package_name:
            download_path = available_package.download()
            package.install_from_path(download_path)
            print(f"Installed package to path {download_path}")
            break
    else:
        print("Package not found")
Beispiel #4
0
def check_and_install_models(force=False):
    if len(package.get_installed_packages()) < 2 or force:
        # Update package definitions from remote
        print("Updating language models")
        package.update_package_index()

        # Load available packages from local package index
        available_packages = package.load_available_packages()
        print("Found %s models" % len(available_packages))

        # Download and install all available packages
        for available_package in available_packages:
            print("Downloading %s (%s) ..." %
                  (available_package, available_package.package_version))
            download_path = available_package.download()
            package.install_from_path(download_path)

        print("Loaded support for %s languages (%s models total)!" % (len(
            translate.load_installed_languages()), len(available_packages)))
Beispiel #5
0
def check_and_install_models(force=False, load_only_lang_codes=None):
    if len(package.get_installed_packages()) < 2 or force:
        # Update package definitions from remote
        print("Updating language models")
        package.update_package_index()

        # Load available packages from local package index
        available_packages = package.load_available_packages()
        print("Found %s models" % len(available_packages))

        if load_only_lang_codes is not None:
            # load_only_lang_codes: List[str] (codes)
            # Ensure the user does not use any unavailable language code.
            unavailable_lang_codes = set(load_only_lang_codes)
            for pack in available_packages:
                unavailable_lang_codes -= {pack.from_code, pack.to_code}
            if unavailable_lang_codes:
                raise ValueError("Unavailable language codes: %s." %
                                 ",".join(sorted(unavailable_lang_codes)))
            # Keep only the packages that have both from_code and to_code in our list.
            available_packages = [
                pack for pack in available_packages
                if pack.from_code in load_only_lang_codes
                and pack.to_code in load_only_lang_codes
            ]
            if not available_packages:
                raise ValueError("no available package")
            print("Keep %s models" % len(available_packages))

        # Download and install all available packages
        for available_package in available_packages:
            print("Downloading %s (%s) ..." %
                  (available_package, available_package.package_version))
            download_path = available_package.download()
            package.install_from_path(download_path)

        # reload installed languages
        app.language.languages = translate.load_installed_languages()
        print("Loaded support for %s languages (%s models total)!" % (len(
            translate.load_installed_languages()), len(available_packages)))
Beispiel #6
0
 def install_package(self, pkg):
     download_path = pkg.download()
     package.install_from_path(download_path)
     os.remove(download_path)
     self.packages_changed.emit()
def install_package_print_path(available_package):
    download_path = available_package.download()
    print(f"Downloaded package {download_path}")
    package.install_from_path(download_path)
    print(f"Installed package to {settings.package_data_dir}")
Beispiel #8
0
 def install_package(pkg):
     download_path = pkg.download()
     package.install_from_path(download_path)
     os.remove(download_path)