def main(self): pretty.install() install() shell = AutoShell() self.init(shell) out_list = [] if self.all_flag: for PM in self.PMs: pm = PM() out_list.extend(pm.get_all_packages()) else: for package_name in self.known_packages.keys(): try: package = UniversalePackage( package_name, shell=shell, pms_classes=self.PMs, # не работает как надо! known_packages=self.known_packages, ) except PackageManagerNotInatalled: continue if package.is_installed(): ver = package.info.get("version", None) if not ver: out_list.append(f"{package_name}") else: out_list.append(f"{package_name}@{ver}") for line in out_list: print(line) if self.output != None: data = {"packages": out_list} with open(self.output, 'w+') as f: yaml.dump(data, f, default_flow_style=False)
def __init__(self, package_name: str, shell: Shell = None): if shell == None: self.shell = AutoShell() else: self.shell = shell self.package_name = package_name self.pm = self.pm_class(shell=self.shell) self.logger = logger.getChild(self.__class__.__name__)
def get_installed_pms(shell: AutoShell = None) -> List[PackageManager]: pms_list = [] if not shell: shell = AutoShell() for cls in inheritors(PackageManager): obj = cls(shell=shell) if obj.is_installed(): pms_list.append(cls) pm_names = [pm.name for pm in pms_list] logger.info(f"Installed packege managers: {pm_names}") return pms_list
def main(self, package_name: str): pretty.install() install() shell = AutoShell() self.init(shell) package = UniversalePackage( package_name, shell=shell, pms_classes=self.PMs, auto_update_conf=not self.no_auto_update_conf) package.install()
def main(self, package_name: str): pretty.install() install() shell = AutoShell() self.init(shell) data = {} for pm in self.PMs: try: out = pm(shell=shell).search(package_name) if out != {}: data[pm.name] = out except NotImplementedError as e: logger.warning( f"{pm.name} not have search method!") # , exc_info=True) if self.list_mode: print_search_results(data) else: print_info(data)
def __init__( self, package_name, shell=None, pms_classes: List[PackageManager] = None, known_packages: dict() = None, offline=False, auto_update_conf=True, ): self.package_name = package_name self.logger = logger.getChild(self.__class__.__name__) self.logger.debug( f"Args:\n\tpackage_name = {package_name}\n\tshell = {shell}\n\tpms_classes = {pms_classes}\n\toffline = {offline}\n\tauto_update_conf = {auto_update_conf}\n\tis_known_packages = {known_packages != None}" ) self.auto_update_conf = auto_update_conf if shell == None: self.shell = AutoShell() else: self.shell = shell if not known_packages: known_packages = get_known_packages(offline=offline) if package_name in known_packages: logger.info(f"Package '{package_name}' found in known_packages") self.config = known_packages[package_name] self.dependences_order = get_packages_dependences_order( known_packages, package_name) else: self.dependences_order = [package_name] if not pms_classes: self.pms_classes = get_installed_pms(shell=self.shell) else: self.pms_classes = pms_classes self.update_package_info()
class PackageManager: @property def name(self) -> str: return self.__class__.__name__.lower() def __init__(self, shell: Shell = None): self.logger = logger.getChild(self.__class__.__name__) if shell == None: self.shell = AutoShell() else: self.shell = shell def __str__(self): return f"{self.name}" def search(self, package_name: str) -> dict: """ Поиск пакета по имени """ raise NotImplementedError() def is_installed(self) -> bool: return self.shell.check_command(self.name)
def main(self, package_name): pretty.install() install() shell = AutoShell() self.init(shell) logger.debug( f"Args:\n\tpackage_name = {package_name},\n\tpm_names = {self.pm_names}\n\tall = {self.all_flag}\n\toffline = {self.offline}" ) package = UniversalePackage(package_name, shell=shell, pms_classes=self.PMs, known_packages=self.known_packages) package.update_package_info(all_pm=self.all_flag) info = package.info if info == {}: logger.error("Package Does Not Found") return print_info(info) if package_name not in self.known_packages: update_user_known_package(package_name, package.config)
def __init__(self, shell: Shell = None): self.logger = logger.getChild(self.__class__.__name__) if shell == None: self.shell = AutoShell() else: self.shell = shell