~doctormo/apt-cat/trunk

« back to all changes in this revision

Viewing changes to AptCategory/__init__.py

  • Committer: Martin Owens
  • Date: 2010-10-31 23:28:30 UTC
  • Revision ID: doctormo@gmail.com-20101031232830-gy5xnyx9m04drwbv
Allow sub categories

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
                yield pkg
107
107
 
108
108
 
109
 
def iterate_categories(installed=None, category='apt-cat'):
 
109
def iterate_categories(installed=None, category=None):
110
110
    """Iterate over available/installed package categories"""
111
111
    pkg = None
112
112
    try:
113
113
        # apt-cat is the root category
114
 
        for pkg in _it_rev_dep(category, 'Depends', installed):
 
114
        cat_pkg = category_package(category, 'apt-cat')
 
115
        # It's a strong dependancy
 
116
        for pkg in _it_rev_dep(cat_pkg, 'Depends', installed):
115
117
            yield Category(pkg)
116
118
    except KeyError:
117
 
        raise NoPackageError("Apt-cat isn't installed. Please install first.")
 
119
        if not category:
 
120
            raise NoPackageError("Apt-cat isn't installed. Please install first.")
 
121
        else:
 
122
            raise NoCategoryError("Category %s not found." % category)
118
123
    if not pkg:
119
124
        raise NoCategoriesError("No categories found")
120
125
 
 
126
def category_package(category, instead=None):
 
127
    """Return the package name for a given category name"""
 
128
    if category == None and instead:
 
129
        return instead
 
130
    if isinstance(category, Category):
 
131
        return category.pid
 
132
    else:
 
133
        return PKG_TEMP % category
121
134
 
122
135
def iterate_packages(categories, installed=None):
123
136
    """Iterate over packages available in the given category."""
126
139
    dep = None
127
140
    category = None
128
141
    for category in categories:
129
 
        if isinstance(category, Category):
130
 
            pkg = category.pid
131
 
        else:
132
 
            pkg = PKG_TEMP % category
 
142
        pkg = category_package(category)
133
143
        try:
134
144
            for dep in _it_rev_dep(pkg, 'Enhances', installed):
135
145
                yield Package(dep)