~doctormo/apt-cat/trunk

« back to all changes in this revision

Viewing changes to AptCategory/__init__.py

  • Committer: Martin Owens
  • Date: 2010-10-31 22:44:01 UTC
  • Revision ID: doctormo@gmail.com-20101031224401-1rix63auw5d4jfy8
Add in sub-category support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    pass
48
48
 
49
49
 
50
 
class Category(object):
51
 
    """A package category"""
52
 
    def __init__(self, apt_package):
53
 
        self._pkg = apt_package
54
 
        self._cand = self._pkg.candidate
55
 
 
56
 
    @property
57
 
    def name(self):
58
 
        """Return the summary as the name"""
59
 
        return self._cand.summary.title()
60
 
 
61
 
    @property
62
 
    def cid(self):
63
 
        """Return the part of the package name as the category id"""
64
 
        return self._pkg.name.split('-')[-1]
65
 
 
66
 
    @property
67
 
    def pid(self):
68
 
        """Return the package name and the package id"""
69
 
        return self._pkg.name
70
 
 
71
 
 
72
50
class Package(object):
73
51
    """Cover an installable package."""
74
52
    def __init__(self, apt_package):
100
78
        return self._pkg.is_installed
101
79
 
102
80
 
 
81
class Category(Package):
 
82
    """A package category"""
 
83
    @property
 
84
    def name(self):
 
85
        """Return the summary as the name"""
 
86
        return self._cand.summary.title()
 
87
 
 
88
    @property
 
89
    def cid(self):
 
90
        """Return the part of the package name as the category id"""
 
91
        return self.pid.split('-')[-1]
 
92
 
103
93
 
104
94
def _it_rev_dep(package_name, relationship, installed=None):
105
95
    """Iterate over reverse dependancies"""
116
106
                yield pkg
117
107
 
118
108
 
119
 
def iterate_categories(installed=None):
 
109
def iterate_categories(installed=None, category='apt-cat'):
120
110
    """Iterate over available/installed package categories"""
121
111
    pkg = None
122
112
    try:
123
 
        for pkg in _it_rev_dep('apt-cat', 'Depends', installed):
 
113
        # apt-cat is the root category
 
114
        for pkg in _it_rev_dep(category, 'Depends', installed):
124
115
            yield Category(pkg)
125
116
    except KeyError:
126
117
        raise NoPackageError("Apt-cat isn't installed. Please install first.")