Skip to content

Commit

Permalink
Add UrpmiPackage class
Browse files Browse the repository at this point in the history
Add UrpmiPackage class to access package information from the urpmi
cache.

- Add packages property to urpmi to return the a generator of packages
  as UrpmiPackage objects.
  • Loading branch information
J. Victor Martins committed Apr 4, 2011
1 parent 926fd9a commit ebb1e38
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion mdvpkg/repo.py
Expand Up @@ -195,6 +195,40 @@ def __repr__(self):
self.epoch)


class UrpmiPackage(object):
def __init__(self,
urpmi,
name):
self._urpmi = urpmi
self.name = name

@property
def status(self):
if self._urpmi._cache[self.name]['new']:
return 'new'
else:
return 'current'

@property
def upgrades(self):
if self.status == 'new':
raise AttributeError, "UrpmiPackage status == 'new'"
return self._installed_updates('upgrade')

@property
def downgrades(self):
if self.status == 'new':
raise AttributeError, "UrpmiPackage status == 'new'"
return self._installed_updates('downgrade')

@property
def versions(self):
return self._urpmi._cache[self.name][self.status].values()

def _installed_updates(self, update_type):
return self._urpmi._cache[self.name][update_type].values()


class URPMI(object):
""" Represents a urpmi database. """

Expand All @@ -219,11 +253,12 @@ def medias(self):
def medias(self):
self._medias = None


@property
def packages(self):
if not self._cache:
self.load_db()
for name in self._cache.keys():
yield UrpmiPackage(self, name)

def load_db(self):
self._cache = {}
Expand Down

0 comments on commit ebb1e38

Please sign in to comment.