コード例 #1
0
ファイル: ListCommand.py プロジェクト: parsampsh/cati
    def show_once(self, package: Pkg):
        """
        show once item in loaded packages list
        """
        if self.has_option('-q') or self.has_option('--quiet'):
            pr.p(package.data['name'])
            return
        output = ansi.green + package.data[
            'name'] + ansi.reset + '/' + ansi.yellow + package.data[
                'version'] + ansi.reset
        if package.installed():
            if package.is_installed_manual(package.data['name']):
                output += '/Installed-Manual:' + ansi.blue + package.installed(
                ).strip() + ansi.reset
            else:
                output += '/Installed:' + ansi.blue + package.installed(
                ).strip() + ansi.reset
        output += '/[' + package.data['repo'] + ']'

        # if verbose output wanted, show first line of description
        if self.is_verbose():
            try:
                description_summary = package.data['description'].split(
                    '\n')[0]
                if description_summary != '':
                    output += '/ ' + ansi.header + description_summary + ansi.reset
            except:
                pass

        pr.p(output)
コード例 #2
0
    def find_unused_packages(self):
        """ finds unused packages """
        all_packages = Pkg.all_list()['list']

        for pkg in all_packages:
            try:
                if Pkg.is_installed(pkg.data['name']):
                    if not Pkg.is_installed_manual(pkg.data['name']):
                        has_any_reverse_depends = False
                        reverse_depends = Pkg.load_version(
                            pkg.data['name'],
                            Pkg.installed_version(
                                pkg.data['name'])).get_reverse_depends()
                        for rdep in reverse_depends:
                            if rdep.installed():
                                rdep_is_in_unused_packages = False
                                for upkg in self.unused_packages:
                                    if upkg.data['name'] == rdep.data['name']:
                                        rdep_is_in_unused_packages = True
                                if not rdep_is_in_unused_packages:
                                    has_any_reverse_depends = True
                        if not has_any_reverse_depends:
                            self.unused_packages.append(pkg)
            except:
                pass
コード例 #3
0
ファイル: ListCommand.py プロジェクト: parsampsh/cati
    def run(self):
        """ Run command """

        if not self.has_option('-q') and not self.has_option('--quiet'):
            pr.p('Loading packages list...')
            pr.p('========================')
        # load list of packages
        if self.has_option('--installed'):
            # just list installed packages
            packages = Pkg.installed_list()
        elif self.has_option('--installed-manual'):
            packages = Pkg.installed_list()
            packages_list = [
                tmp_pkg for tmp_pkg in packages['list']
                if Pkg.is_installed_manual(tmp_pkg.data['name'])
            ]
            packages['list'] = packages_list
        else:
            packages = Pkg.all_list()

        for error in packages['errors']:
            self.message(error + ansi.reset, True, before=ansi.red)

        # load filter options
        wanted_authors = []
        if self.has_option('--author'):
            wanted_authors = self.option_value('--author').strip().split('|')
            wanted_authors = [author.strip() for author in wanted_authors]
        wanted_maintainers = []
        if self.has_option('--maintainer'):
            wanted_maintainers = self.option_value(
                '--maintainer').strip().split('|')
            wanted_maintainers = [
                maintainer.strip() for maintainer in wanted_maintainers
            ]
        wanted_categories = []
        if self.has_option('--category'):
            wanted_categories = self.option_value('--category').strip().split(
                '|')
            wanted_categories = [
                category.strip() for category in wanted_categories
            ]
        search_query = self.option_value('--search')
        if search_query:
            search_query_words = search_query.strip().split(' ')
            search_query_words = [word.strip() for word in search_query_words]
        else:
            search_query_words = []

        for package in packages['list']:
            # check filters
            if wanted_authors:
                try:
                    if not package.data['author'].strip() in wanted_authors:
                        continue
                except:
                    continue
            if wanted_maintainers:
                try:
                    if not package.data['maintainer'].strip(
                    ) in wanted_maintainers:
                        continue
                except:
                    continue
            if wanted_categories:
                try:
                    if not package.data['category'].strip(
                    ) in wanted_categories:
                        continue
                except:
                    continue
            if search_query:
                is_math_with_query = False
                for word in search_query_words:
                    if word in package.data['name']:
                        is_math_with_query = True
                try:
                    if search_query in package.data['description']:
                        is_math_with_query = True
                except:
                    pass
                if not is_math_with_query:
                    continue

            if self.has_option('--upgradable'):
                if package.installed():
                    if Pkg.compare_version(package.data['version'],
                                           package.installed()) != 1:
                        continue
                else:
                    continue
            # show item
            self.show_once(package)
コード例 #4
0
ファイル: test_install.py プロジェクト: parsampsh/cati
    def run(self):
        """ Run test """
        repo1 = "file://" + os.getcwd(
        ) + '/repository name=test arch=all pkg=cati'
        repo2 = "file://" + os.getcwd(
        ) + '/repository name=test arch=i386 pkg=cati'

        self.assert_equals(
            self.run_command('repo',
                             ['--scan', os.getcwd() + '/repository']), 0)

        self.assert_equals(self.run_command('repo', ['--add', repo1]), 0)
        self.assert_equals(self.run_command('repo', ['--add', repo2]), 0)
        self.assert_equals(self.run_command('update'), 0)

        self.assert_equals(self.run_command('install', ['testpkg10', '-y']), 0)

        self.assert_true(Pkg.is_installed('testpkg10'))
        self.assert_true(Pkg.is_installed('testpkg11'))

        self.assert_equals(self.run_command('install', ['testpkgb', '-y']), 0)

        self.assert_true(Pkg.is_installed('testpkgb'))
        self.assert_true(Pkg.is_installed('testpkgc'))
        self.assert_true(not Pkg.is_installed_manual('testpkgc'))

        self.assert_equals(self.run_command('install', ['testpkgz', '-y']), 0)

        self.assert_true(not Pkg.is_installed('testpkgb'))
        self.assert_true(not Pkg.is_installed('testpkgc'))
        self.assert_true(Pkg.is_installed('testpkgz'))

        self.assert_equals(self.run_command('install', ['testpkgb', '-y']), 0)

        self.assert_true(Pkg.is_installed('testpkgb'))
        self.assert_true(Pkg.is_installed('testpkgc'))
        self.assert_true(not Pkg.is_installed('testpkgz'))

        self.assert_equals(
            self.run_command('remove', ['testpkgb', 'testpkgc', '-y']), 0)

        # test upgrade
        self.assert_equals(self.run_command('install', ['testpkgc=1.0', '-y']),
                           0)

        testpkgc = Pkg.load_last('testpkgc')
        self.assert_equals(testpkgc.installed(), '1.0')

        self.assert_equals(self.run_command('upgrade', ['-y']), 0)

        testpkgc = Pkg.load_last('testpkgc')
        self.assert_equals(testpkgc.installed(), '2.0')

        # test recommends
        self.refresh_env()

        self.assert_equals(
            self.run_command('repo', [
                '--add', 'file://' + os.getcwd() +
                '/repository/test-repository arch=all,i386 name=test pkg=cati'
            ]), 0)
        self.assert_equals(self.run_command('update'), 0)
        self.assert_equals(self.run_command('install', ['testpkgr', '-y']), 0)
        self.assert_true(Pkg.is_installed('testpkgr'))
        self.assert_true(Pkg.is_installed('testpkgc'))
        self.assert_true(not Pkg.is_installed('testpkg11'))

        self.refresh_env()

        self.assert_equals(
            self.run_command('repo', [
                '--add', 'file://' + os.getcwd() +
                '/repository/test-repository arch=all,i386 name=test pkg=cati'
            ]), 0)
        self.assert_equals(self.run_command('update'), 0)
        self.assert_equals(
            self.run_command('install',
                             ['testpkgr', '-y', '--with-recommends']), 0)
        self.assert_true(Pkg.is_installed('testpkgr'))
        self.assert_true(Pkg.is_installed('testpkgc'))
        self.assert_true(Pkg.is_installed('testpkg11'))
コード例 #5
0
ファイル: PackageShower.py プロジェクト: parsampsh/cati
def show(data: dict):
    """
    shows package information from data dictonary.
    
    Args:
        data: (dict) package data dictonary
    """
    output = ''
    output += 'Name: ' + ansi.green + data['name'] + ansi.reset + '\n'
    output += 'Version: ' + ansi.blue + data['version'] + ansi.reset + '\n'
    output += 'Arch: ' + ansi.yellow + data['arch'] + ansi.reset + '\n'
    try:
        author = data['author']
        output += 'Author: ' + ansi.header + author + ansi.reset + '\n'
    except:
        pass
    try:
        maintainer = data['maintainer']
        output += 'Maintainer: ' + ansi.cyan + maintainer + ansi.reset + '\n'
    except:
        pass
    try:
        changed_by = data['changed-by']
        output += 'Changed-By: ' + changed_by + '\n'
    except:
        pass
    try:
        uploaders = data['uploaders']
    except:
        uploaders = []
    if uploaders:
        output += 'Uploaders: '
        for uploader in uploaders:
            output += uploader + ', '
        output = output[:len(output) - 2]
        output += '\n'
    try:
        channel = data['channel']
        output += 'Channel: ' + ansi.red + channel + ansi.reset + '\n'
    except:
        pass
    try:
        homepage = data['homepage']
        output += 'Homepage: ' + ansi.blue + homepage + ansi.reset + '\n'
    except:
        pass
    try:
        category = data['category']
        if category:
            output += 'Categories: '
            i = 0
            while i < len(category):
                output += ansi.bold + category[i] + ansi.reset
                if i < len(category) - 1:
                    output += ', '
                i += 1
            output += '\n'
    except:
        pass
    try:
        description = data['description']
        output += 'Description: ' + description + '\n'
    except:
        pass
    try:
        changes = data['changes']
        output += 'Changes: ' + description + '\n'
    except:
        pass
    try:
        date = data['date']
        output += 'Last-Update-Date: ' + date + '\n'
    except:
        pass
    try:
        urgency = data['urgency']
        output += 'Update-Level: ' + urgency + '\n'
    except:
        pass
    try:
        essential = data['essential']
        if essential:
            essential = 'Yes'
        else:
            essential = 'No'
        output += 'Essential: ' + essential + '\n'
    except:
        pass
    try:
        file_size = Pkg.get_download_size_str(data['file_size'])
        output += 'Download-Size: ' + str(file_size) + '\n'
    except:
        pass
    try:
        installed_size = Pkg.get_download_size_str(data['installed-size'])
        output += 'Installed-Size: ' + str(installed_size) + '\n'
    except:
        pass
    try:
        repo = data['repo']
        output += 'Repository: ' + repo + '\n'
    except:
        pass
    try:
        depends = data['depends']
    except:
        depends = []
    if depends:
        output += 'Depends: '
        for dep in depends:
            output += ansi.bold + dep + ansi.reset + ', '
        output = output[:len(output) - 2]
        output += '\n'
    try:
        recommends = data['recommends']
    except:
        recommends = []
    if recommends:
        output += 'Recommends: '
        for rec in recommends:
            output += ansi.bold + rec + ansi.reset + ', '
        output = output[:len(output) - 2]
        output += '\n'
    try:
        conflicts = data['conflicts']
    except:
        conflicts = []
    if conflicts:
        output += 'Conflicts: '
        for conflict in conflicts:
            output += ansi.bold + conflict + ansi.reset + ', '
        output = output[:len(output) - 2]
        output += '\n'
    try:
        suggests = data['suggests']
    except:
        suggests = []
    if suggests:
        output += 'Suggests: '
        for suggest in suggests:
            output += ansi.bold + suggest + ansi.reset + ', '
        output = output[:len(output) - 2]
        output += '\n'
    try:
        enhances = data['enhances']
    except:
        enhances = []
    if enhances:
        output += 'Enhances: '
        for enhance in enhances:
            output += ansi.bold + enhance + ansi.reset + ', '
        output = output[:len(output) - 2]
        output += '\n'
    try:
        provides = data['provides']
    except:
        provides = []
    if provides:
        output += 'Provides: '
        for provide in provides:
            output += ansi.bold + provide + ansi.reset + ', '
        output = output[:len(output) - 2]
        output += '\n'
    if Pkg.is_installed(data['name']):
        installed_version = Pkg.installed_version(data['name'])
        if Pkg.is_installed_manual(data['name']):
            output += 'Installed-Manual: ' + installed_version + '\n'
        else:
            output += 'Installed: ' + installed_version + '\n'

    # show user defined fields
    for k in data:
        if k[0] == 'x' or k[0] == 'X':
            # that fields start with `x` character are user defined fields
            output += '\n' + k + ': ' + data[k]

    if output[-1] == '\n':
        output = output[:len(output) - 1]
    pr.p(output.strip())