def manageService(self, services, service_action, pkg_dps, host): try: for service in services: # check if package dependencies are already installed. If not, install them now if service_action == 'start' or 'restart': p = Packages() pkgs_to_install = [] print("\n\n*** Checking dependencies...") for pkg in pkg_dps: if p.check_if_package_installed(pkg, host): pass else: pkgs_to_install.append(pkg) p.install_package(host, pkgs_to_install) if service_action == 'stop': pass print("\n\n*** {}ing {} service on {}".format(service_action, service, host)) cmd = "service {} {}".format(service, service_action) c = SshConnection() output, error = c.run_command(cmd, host) if error == []: for o in output: print(o.strip('\n')) else: raise Exception(error[0]) except Exception as e: print(e)
service_pkg_deps = parsed['action']['pkg_deps'] try: c = SshConnection() s = Service() for host in hosts: if commands: for command in commands: output, error = c.run_command(command, host) if error != []: raise Exception(error[0]) else: print("\n*** Output of '{}' on '{}'".format(command, host)) for o in output: print(o.strip('\n')) elif install_pkgs: p = Packages() p.install_package(host, install_pkgs) s = Service() s.manageService(pkg_service_deps, 'restart', service_pkg_deps, host) elif uninstall_pkgs: p = Packages() p.uninstall_package(host, uninstall_pkgs) elif upgrade_pkgs: p = Packages() p.upgrade_package(host, upgrade_pkgs) elif file_data and file_metadata: f = File() f.create_file(host, file_data, file_metadata) elif not file_data and file_metadata: f = File() f.delete_file(host, file_metadata)
def do_packages(self, _args): """ Get information about packages installed on the device """ subconsole = Packages(self.session) subconsole.cmdloop()
'dependencies', help='find dependencies for given packages') dep_parser.add_argument('packages', nargs='*') dep_parser.add_argument('-o', '--or-dependency', help='''allow choosing the or dependencies of the package''', action='store_true') dep_parser.add_argument('-f', '--facultative-package', help='''pick also the falcultative package''', action='store_true') args = parser.parse_args() pkg_handler = Packages() lastweek = time.time() - 7 * 24 * 3600 if args.update or not os.path.exists(PACKAGE_FILE_NAME) \ or os.stat(PACKAGE_FILE_NAME).st_mtime < lastweek: sys.stdout.write('Downloading packages information... ') download_packages_file() print('Done') sys.stdout.write('Beginning initializing... ') pkg_handler.parse(read_packages_file()) print('Done\n') if args.action == 'search': for pkg in args.packages: try:
def main(): packages = Packages(output_package_info) packages.check_for_updates() if not updated: print("Everything up-to-date.")