def main(): arguments = docopt( __doc__.format( default_config_dir=constants.config_dir, default_root=constants.install_root, default_repository=constants.repository_base, ), ) umask(0o022) # NOTE: Changing root or repository will likely break actually running packages. install = Install( os.path.abspath(arguments['--root']), os.path.abspath(arguments['--config-dir']), arguments['--rooted-systemd'], not arguments['--no-systemd'], not arguments['--no-block-systemd'], manage_users=True, add_users=not os.path.exists('/etc/mesosphere/manual_host_users'), manage_state_dir=True) repository = Repository(os.path.abspath(arguments['--repository'])) try: if arguments['setup']: actions.setup(install, repository) sys.exit(0) if arguments['list']: print_repo_list(repository.list()) sys.exit(0) if arguments['active']: for pkg in sorted(install.get_active()): print(pkg) sys.exit(0) if arguments['add']: actions.add_package_file(repository, arguments['<package-tarball>']) sys.exit(0) if arguments['fetch']: for package_id in arguments['<id>']: actions.fetch_package(repository, arguments['--repository-url'], package_id, os.getcwd()) sys.exit(0) if arguments['activate']: actions.activate_packages(install, repository, arguments['<id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['swap']: actions.swap_active_package(install, repository, arguments['<package-id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['remove']: for package_id in arguments['<id>']: try: actions.remove_package(install, repository, package_id) except PackageNotFound: pass sys.exit(0) if arguments['uninstall']: uninstall(install, repository) sys.exit(0) if arguments['check']: checks = find_checks(install, repository) if arguments['--list']: list_checks(checks) sys.exit(0) # Run all checks sys.exit(run_checks(checks, install, repository)) except ValidationError as ex: print("Validation Error: {0}".format(ex), file=sys.stderr) sys.exit(1) except PackageError as ex: print("Package Error: {0}".format(ex), file=sys.stderr) sys.exit(1) except Exception as ex: print("ERROR: {0}".format(ex), file=sys.stderr) sys.exit(1) print("unknown command", file=sys.stderr) sys.exit(1)
def main(): arguments = docopt(__doc__, version="Pkpganda Package Manager") umask(0o022) # NOTE: Changing root or repository will likely break actually running packages. install = Install( os.path.abspath(arguments['--root']), os.path.abspath(arguments['--config-dir']), arguments['--rooted-systemd'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) repository = Repository(os.path.abspath(arguments['--repository'])) try: if arguments['setup']: actions.setup(install, repository) sys.exit(0) if arguments['list']: print_repo_list(repository.list()) sys.exit(0) if arguments['active']: for pkg in sorted(install.get_active()): print(pkg) sys.exit(0) if arguments['add']: actions.add_package_file(repository, arguments['<package-tarball>']) sys.exit(0) if arguments['fetch']: for package_id in arguments['<id>']: actions.fetch_package( repository, arguments['--repository-url'], package_id, os.getcwd()) sys.exit(0) if arguments['activate']: actions.activate_packages( install, repository, arguments['<id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['swap']: actions.swap_active_package( install, repository, arguments['<package-id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['remove']: for package_id in arguments['<id>']: actions.remove_package(install, repository, package_id) sys.exit(0) if arguments['uninstall']: uninstall(install, repository) sys.exit(0) if arguments['check']: checks = find_checks(install, repository) if arguments['--list']: list_checks(checks) sys.exit(0) # Run all checks sys.exit(run_checks(checks, install, repository)) except Exception as ex: print("ERROR: {0}".format(ex)) sys.exit(1) except ValidationError as ex: print("Validation Error: {0}".format(ex)) sys.exit(1) except PackageError as ex: print("Package Error: {0}".format(ex)) sys.exit(1) print("unknown command") sys.exit(1)
def main(): arguments = docopt(__doc__, version="Pkpganda Package Manager") umask(0o022) # NOTE: Changing root or repository will likely break actually running packages. install = Install( os.path.abspath(arguments['--root']), os.path.abspath(arguments['--config-dir']), arguments['--rooted-systemd'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) repository = Repository(os.path.abspath(arguments['--repository'])) if arguments['setup']: try: setup(install, repository) except ValidationError as ex: print("Validation Error: {0}".format(ex)) sys.exit(1) sys.exit(0) if arguments['list']: print_repo_list(repository.list()) sys.exit(0) if arguments['active']: for pkg in sorted(install.get_active()): print(pkg) sys.exit(0) if arguments['add']: add_to_repository(repository, arguments['<package-tarball>']) sys.exit(0) if arguments['fetch']: def fetcher(id, target): return requests_fetcher(arguments['--repository-url'], id, target, os.getcwd()) for pkg_id in arguments['<id>']: # TODO(cmaloney): Make this not use escape sequences when not at a # `real` terminal. sys.stdout.write("\rFetching: {0}".format(pkg_id)) sys.stdout.flush() try: repository.add(fetcher, pkg_id) except FetchError as ex: print("\nUnable to fetch package {0}: {1}".format(pkg_id, ex)) sys.exit(1) sys.stdout.write("\rFetched: {0}\n".format(pkg_id)) sys.stdout.flush() sys.exit(0) if arguments['activate']: do_activate(install, repository, arguments['<id>'], arguments['--no-systemd'], arguments['--no-block-systemd']) sys.exit(0) if arguments['swap']: active = install.get_active() # TODO(cmaloney): I guarantee there is a better way to write this and # I've written the same logic before... packages_by_name = dict() for id_str in active: pkg_id = PackageId(id_str) packages_by_name[pkg_id.name] = pkg_id new_id = PackageId(arguments['<package-id>']) if new_id.name not in packages_by_name: print("ERROR: No package with name {} currently active to swap with.".format(new_id.name)) packages_by_name[new_id.name] = new_id new_active = list(map(str, packages_by_name.values())) # Activate with the new package name do_activate(install, repository, new_active, arguments['--no-systemd'], arguments['--no-block-systemd']) sys.exit(0) if arguments['remove']: # Make sure none of the packages are active active_packages = install.get_active() active = active_packages.intersection(set(arguments['<id>'])) if len(active) > 0: print("Refusing to remove active packages {0}".format(" ".join(sorted(list(active))))) sys.exit(1) for pkg_id in arguments['<id>']: sys.stdout.write("\rRemoving: {0}".format(pkg_id)) sys.stdout.flush() try: # Validate package id, that package is installed. PackageId(pkg_id) repository.remove(pkg_id) except ValidationError: print("\nInvalid package id {0}".format(pkg_id)) sys.exit(1) except OSError as ex: print("\nError removing package {0}".format(pkg_id)) print(ex) sys.exit(1) sys.stdout.write("\rRemoved: {0}\n".format(pkg_id)) sys.stdout.flush() sys.exit(0) if arguments['uninstall']: uninstall(install, repository) sys.exit(0) if arguments['check']: checks = find_checks(install, repository) if arguments['--list']: list_checks(checks) sys.exit(0) # Run all checks sys.exit(run_checks(checks, install, repository)) print("unknown command") sys.exit(1)
def main(): arguments = docopt(__doc__, version="Pkpganda Package Manager") umask(0o022) # NOTE: Changing root or repository will likely break actually running packages. install = Install(os.path.abspath(arguments['--root']), os.path.abspath(arguments['--config-dir']), arguments['--rooted-systemd'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) repository = Repository(os.path.abspath(arguments['--repository'])) try: if arguments['setup']: actions.setup(install, repository) sys.exit(0) if arguments['list']: print_repo_list(repository.list()) sys.exit(0) if arguments['active']: for pkg in sorted(install.get_active()): print(pkg) sys.exit(0) if arguments['add']: actions.add_package_file(repository, arguments['<package-tarball>']) sys.exit(0) if arguments['fetch']: for package_id in arguments['<id>']: actions.fetch_package(repository, arguments['--repository-url'], package_id, os.getcwd()) sys.exit(0) if arguments['activate']: actions.activate_packages(install, repository, arguments['<id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['swap']: actions.swap_active_package(install, repository, arguments['<package-id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['remove']: for package_id in arguments['<id>']: actions.remove_package(install, repository, package_id) sys.exit(0) if arguments['uninstall']: uninstall(install, repository) sys.exit(0) if arguments['check']: checks = find_checks(install, repository) if arguments['--list']: list_checks(checks) sys.exit(0) # Run all checks sys.exit(run_checks(checks, install, repository)) except Exception as ex: print("ERROR: {0}".format(ex)) sys.exit(1) except ValidationError as ex: print("Validation Error: {0}".format(ex)) sys.exit(1) except PackageError as ex: print("Package Error: {0}".format(ex)) sys.exit(1) print("unknown command") sys.exit(1)
def main(): arguments = docopt(__doc__, version="Pkpganda Package Manager") umask(0o022) # NOTE: Changing root or repository will likely break actually running packages. install = Install(os.path.abspath(arguments['--root']), os.path.abspath(arguments['--config-dir']), arguments['--rooted-systemd'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) repository = Repository(os.path.abspath(arguments['--repository'])) if arguments['setup']: try: setup(install, repository) except ValidationError as ex: print("Validation Error: {0}".format(ex)) sys.exit(1) sys.exit(0) if arguments['list']: print_repo_list(repository.list()) sys.exit(0) if arguments['active']: for pkg in sorted(install.get_active()): print(pkg) sys.exit(0) if arguments['add']: add_to_repository(repository, arguments['<package-tarball>']) sys.exit(0) if arguments['fetch']: def fetcher(id, target): return requests_fetcher(arguments['--repository-url'], id, target, os.getcwd()) for pkg_id in arguments['<id>']: # TODO(cmaloney): Make this not use escape sequences when not at a # `real` terminal. sys.stdout.write("\rFetching: {0}".format(pkg_id)) sys.stdout.flush() try: repository.add(fetcher, pkg_id) except FetchError as ex: print("\nUnable to fetch package {0}: {1}".format(pkg_id, ex)) sys.exit(1) sys.stdout.write("\rFetched: {0}\n".format(pkg_id)) sys.stdout.flush() sys.exit(0) if arguments['activate']: do_activate(install, repository, arguments['<id>'], arguments['--no-systemd'], arguments['--no-block-systemd']) sys.exit(0) if arguments['swap']: active = install.get_active() # TODO(cmaloney): I guarantee there is a better way to write this and # I've written the same logic before... packages_by_name = dict() for id_str in active: pkg_id = PackageId(id_str) packages_by_name[pkg_id.name] = pkg_id new_id = PackageId(arguments['<package-id>']) if new_id.name not in packages_by_name: print( "ERROR: No package with name {} currently active to swap with." .format(new_id.name)) packages_by_name[new_id.name] = new_id new_active = list(map(str, packages_by_name.values())) # Activate with the new package name do_activate(install, repository, new_active, arguments['--no-systemd'], arguments['--no-block-systemd']) sys.exit(0) if arguments['remove']: # Make sure none of the packages are active active_packages = install.get_active() active = active_packages.intersection(set(arguments['<id>'])) if len(active) > 0: print("Refusing to remove active packages {0}".format(" ".join( sorted(list(active))))) sys.exit(1) for pkg_id in arguments['<id>']: sys.stdout.write("\rRemoving: {0}".format(pkg_id)) sys.stdout.flush() try: # Validate package id, that package is installed. PackageId(pkg_id) repository.remove(pkg_id) except ValidationError: print("\nInvalid package id {0}".format(pkg_id)) sys.exit(1) except OSError as ex: print("\nError removing package {0}".format(pkg_id)) print(ex) sys.exit(1) sys.stdout.write("\rRemoved: {0}\n".format(pkg_id)) sys.stdout.flush() sys.exit(0) if arguments['uninstall']: uninstall(install, repository) sys.exit(0) if arguments['check']: checks = find_checks(install, repository) if arguments['--list']: list_checks(checks) sys.exit(0) # Run all checks sys.exit(run_checks(checks, install, repository)) print("unknown command") sys.exit(1)
def main(): arguments = docopt( __doc__.format( default_config_dir=constants.config_dir, default_root=constants.install_root, default_repository=constants.repository_base, ), ) umask(0o022) # NOTE: Changing root or repository will likely break actually running packages. install = Install( os.path.abspath(arguments['--root']), os.path.abspath(arguments['--config-dir']), arguments['--rooted-systemd'], not arguments['--no-systemd'], not arguments['--no-block-systemd'], manage_users=True, add_users=not os.path.exists('/etc/mesosphere/manual_host_users'), manage_state_dir=True) repository = Repository(os.path.abspath(arguments['--repository'])) try: if arguments['setup']: actions.setup(install, repository) sys.exit(0) if arguments['list']: print_repo_list(repository.list()) sys.exit(0) if arguments['active']: for pkg in sorted(install.get_active()): print(pkg) sys.exit(0) if arguments['add']: actions.add_package_file(repository, arguments['<package-tarball>']) sys.exit(0) if arguments['fetch']: for package_id in arguments['<id>']: actions.fetch_package( repository, arguments['--repository-url'], package_id, os.getcwd()) sys.exit(0) if arguments['activate']: actions.activate_packages( install, repository, arguments['<id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['swap']: actions.swap_active_package( install, repository, arguments['<package-id>'], not arguments['--no-systemd'], not arguments['--no-block-systemd']) sys.exit(0) if arguments['remove']: for package_id in arguments['<id>']: try: actions.remove_package(install, repository, package_id) except PackageNotFound: pass sys.exit(0) if arguments['uninstall']: uninstall(install, repository) sys.exit(0) if arguments['check']: checks = find_checks(install, repository) if arguments['--list']: list_checks(checks) sys.exit(0) # Run all checks sys.exit(run_checks(checks, install, repository)) except ValidationError as ex: print("Validation Error: {0}".format(ex)) sys.exit(1) except PackageError as ex: print("Package Error: {0}".format(ex)) sys.exit(1) except Exception as ex: print("ERROR: {0}".format(ex)) sys.exit(1) print("unknown command") sys.exit(1)