Exemple #1
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
Exemple #2
0
    def run(self):
        """ Run test """
        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkgc-2.0.cati']),
            0)

        state_f = open(Env.state_file(), 'w')
        state_f.write(f'install%testpackage1%1.0%amd64\nremove%anotherpackage')
        state_f.close()

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

        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkgc-2.0.cati']),
            1)

        # tests for cli `state` command
        self.assert_equals(self.run_command('state'), 1)
        self.assert_equals(self.run_command('state', ['--abort', '-y']), 0)
        self.assert_equals(self.run_command('state'), 0)

        self.refresh_env()

        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkgc-2.0.cati']),
            0)
        self.assert_true(Pkg.is_installed('testpkgc'))
        state_f = open(Env.state_file(), 'w')
        state_f.write(f'remove%testpkgc')
        state_f.close()
        self.assert_equals(self.run_command('state'), 1)
        self.assert_equals(self.run_command('state', ['--complete']), 0)
        self.assert_equals(self.run_command('state'), 0)
        self.assert_true(not Pkg.is_installed('testpkgc'))
Exemple #3
0
    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'))
Exemple #4
0
    def run(self):
        """ Run test """
        self.assert_equals(self.run_command('autoremove', []), 0)

        self.assert_equals(self.run_command('pkg', [
            'install',
            'repository/test-repository/testpkg11.cati',
            '--auto'
        ]), 0)

        self.assert_equals(self.run_command('pkg', [
            'install',
            'repository/test-repository/testpkg10.cati',
        ]), 0)

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

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

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

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

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

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

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

        self.refresh_env()

        self.assert_equals(self.run_command('pkg', [
            'install',
            'repository/test-repository/testpkg11.cati',
            'repository/test-repository/testpkg10.cati',
            '--auto',
        ]), 0)

        self.assert_equals(self.run_command('pkg', [
            'install',
            'repository/test-repository/testpkg9.cati',
        ]), 0)

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

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

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

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

        self.assert_true(not Pkg.is_installed('testpkg11'))
        self.assert_true(not Pkg.is_installed('testpkg10'))
        self.assert_true(not Pkg.is_installed('testpkg9'))
Exemple #5
0
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())
Exemple #6
0
    def run(self):
        """ Run test """
        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkg10.cati']), 1)

        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkg11.cati']), 0)

        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkg10.cati']), 0)

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

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

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

        self.assert_equals(
            self.run_command(
                'pkg',
                ['install', 'repository/test-repository/testpkg10.cati']), 0)

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

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

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

        self.refresh_env()

        self.assert_equals(
            self.run_command('pkg', [
                'install', 'repository/test-repository/essential-package.cati'
            ]), 0)

        self.assert_true(Pkg.is_installed('essential-package'))

        self.assert_equals(
            self.run_command('remove', ['essential-package', '-y']), 1)

        self.assert_true(Pkg.is_installed('essential-package'))

        self.assert_equals(
            self.run_command('remove', ['essential-package', '-y', '--force']),
            0)

        self.assert_true(not Pkg.is_installed('essential-package'))