Example #1
0
    def search_for_packages(self, search_key: str):
        command_str = f'{self.cache_name} search {search_key}'
        out, err = EXE.execute_command(command_str, False)

        installed_packages = []
        installed, _ = EXE.execute_command('dpkg --get-selections', False)
        for line in installed:
            installed_packages.append(line.split(':', 1)[0])

        if err != 0:
            return None, out, err
        else:
            lines = out.splitlines()
            pkg_names = []
            pkg_descs = {}
            for line in lines:
                if len(line.strip()) == 0:
                    pass
                else:
                    pkg = line.strip().split(' - ', 1)
                    pkg_name = pkg[0]
                    pkg_desc = pkg[1]
                    pkg_names.append(pkg_name)
                    pkg_descs[pkg_name] = pkg_desc
            actual_pkgs = self.get_best_match_packages(pkg_names, search_key)
            packages = []
            for pkg_name in actual_pkgs:

                pkg_desc = pkg_descs[pkg_name]
                #_, ret_installed = EXE.execute_command(
                #    f'dpkg -l {pkg[0]}', False)
                is_installed = False
                if pkg_name in installed_packages:
                    is_installed = True

                if is_installed:
                    packages.insert(
                        0,
                        PKG.AptitudePackage(pkg_name, '', pkg_desc,
                                            is_installed))
                else:
                    packages.append(
                        PKG.AptitudePackage(pkg_name, '', pkg_desc,
                                            is_installed))

            return packages, '', 0
Example #2
0
    def get_info(self) -> str:
        pkg_info, _ = EXE.execute_command(f'apt-cache show {self.name}', False)
        pkg_info_lines = pkg_info.splitlines()
        for pkg_info_line in pkg_info_lines:
            if pkg_info_line.startswith('Version:'):
                self.version = pkg_info_line.split('Version:', 1)[1].strip()
                break

        return f'{self.name:<32} | {self.version:<8} | {self.description}'
Example #3
0
 def list_packages(self) -> (List[PKG.PipPackage], int):
     command_str = f'{self.name} list --format=freeze'
     out, err = EXE.execute_command(command_str, False)
     if err != 0:
         return None, out, err
     else:
         lines = out.splitlines()
         packages = []
         for line in lines:
             if len(line) > 0:
                 name_ver = line.strip().split('==')
                 packages.append(
                     PKG.PipPackage(name_ver[0], name_ver[1], '', True))
         return packages, err
Example #4
0
    def search_for_packages(self,
                            search_key: str) -> (List[PKG.PipPackage], int):
        command_str = f'{self.name} search {search_key}'
        out, err = EXE.execute_command(command_str, False)

        if err != 0:
            return None, err
        else:
            lines = out.splitlines()
            packages = []
            for line in lines:
                if len(line.strip()) == 0:
                    pass
                elif 'INSTALLED' in line:
                    packages[len(packages) - 1].installed = True
                elif ' - ' in line:
                    name = line.split(' ')[0].strip()
                    version = line.split(' ')[1].strip()[1:-1]
                    description = line.split(' - ', 1)[-1].strip()
                    packages.append(
                        PKG.PipPackage(name, version, description, False))
            return packages, '', 0
Example #5
0
 def check_exists(self) -> bool:
     command = f'{self.installer_name} --version'
     _, err = EXE.execute_command(command, False)
     if err == 0:
         return True
     return False
Example #6
0
 def remove_package(self, package, password, as_admin=False) -> None:
     command_str = f'{self.installer_name} uninstall -y {package.name}'
     return EXE.execute_command(command_str,
                                as_admin,
                                passwd=password,
                                expect='Password:')
Example #7
0
 def update_package(self, package, password, as_admin=False) -> (str, str):
     command_str = f'{self.name} install --upgrade {package.name}'
     return EXE.execute_command(command_str, False)