コード例 #1
0
ファイル: test_update_system.py プロジェクト: parsampsh/cati
    def run(self):
        """ Run test """
        self.assert_equals(self.run_command('update'), 0)

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

        f = open(self.env() + '/etc/cati/repos.list', 'w')
        f.write('''
        file://''' + os.getcwd() +
                '''/repository/test-repository name=main arch=i386 pkg=cati
        ''')
        f.close()

        self.assert_equals(len(Pkg.all_list()['list']), 0)

        self.assert_equals(self.run_command('update'), 0)

        try:
            pkg_count = len(Pkg.all_list()['list'])
            self.assert_true(pkg_count >= 9 and pkg_count <= 13)
        except:
            print('Packages count:', pkg_count)
            raise

        f = open(self.env() + '/etc/cati/repos.list.d/repo-b', 'w')
        f.write('''
        file://''' + os.getcwd() +
                '''/repository/test-repository name=main-2 arch=all pkg=cati
        ''')
        f.close()

        try:
            pkg_count = len(Pkg.all_list()['list'])
            self.assert_true(pkg_count >= 9 and pkg_count <= 13)
        except:
            print('Packages count:', pkg_count)
            raise

        self.assert_equals(self.run_command('update'), 0)

        try:
            pkg_count = len(Pkg.all_list()['list'])
            self.assert_true(pkg_count >= 15 and pkg_count <= 19)
        except:
            print('Packages count:', pkg_count)
            raise
コード例 #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)