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')
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)))
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)))
def __init__(self): super().__init__() # Update package definitions from remote package.update_package_index() # Load available packages from local package index available_packages = package.load_available_packages() # Packages table self.packages_table = PackagesTable(PackagesTable.TableContent.AVAILABLE, [PackagesTable.AvailableActions.INSTALL]) self.packages_table.packages_changed.connect(self.packages_changed.emit) self.packages_table.populate() self.packages_layout = QVBoxLayout() self.packages_layout.addWidget(self.packages_table) # Layout self.layout = QVBoxLayout() self.layout.addLayout(self.packages_layout) self.layout.addStretch() self.setLayout(self.layout)
def update_index(args): """Update the package index.""" package.update_package_index()