diff options
Diffstat (limited to 'apt')
| -rw-r--r-- | apt/cache.py | 22 | ||||
| -rw-r--r-- | apt/debfile.py | 58 | ||||
| -rw-r--r-- | apt/package.py | 21 |
3 files changed, 94 insertions, 7 deletions
diff --git a/apt/cache.py b/apt/cache.py index 9e682bd8..65f3c9d9 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -25,6 +25,16 @@ import apt.progress import os import sys +class FetchCancelledException(IOError): + " Exception that is thrown when the user cancels a fetch operation " + pass +class FetchFailedException(IOError): + " Exception that is thrown when fetching fails " + pass +class LockFailedException(IOError): + " Exception that is thrown when locking fails " + pass + class Cache(object): """ Dictionary-like package cache This class has all the packages that are available in it's @@ -129,9 +139,11 @@ class Cache(object): errMsg += "Failed to fetch %s %s\n" % (item.DescURI,item.ErrorText) failed = True - # we raise a exception if the download failed - if failed: - raise IOError, errMsg + # we raise a exception if the download failed or it was cancelt + if res == fetcher.ResultCancelled: + raise FetchCancelledException, errMsg + elif failed: + raise FetchFailedException, errMsg return res def _fetchArchives(self, fetcher, pm): @@ -141,7 +153,7 @@ class Cache(object): lockfile = apt_pkg.Config.FindDir("Dir::Cache::Archives") + "lock" lock = apt_pkg.GetLock(lockfile) if lock < 0: - raise IOError, "Failed to lock %s" % lockfile + raise LockFailedException, "Failed to lock %s" % lockfile try: # this may as well throw a SystemError exception @@ -157,7 +169,7 @@ class Cache(object): lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" lock = apt_pkg.GetLock(lockfile) if lock < 0: - raise IOError, "Failed to lock %s" % lockfile + raise LockFailedException, "Failed to lock %s" % lockfile try: if fetchProgress == None: diff --git a/apt/debfile.py b/apt/debfile.py new file mode 100644 index 00000000..ddde5bf1 --- /dev/null +++ b/apt/debfile.py @@ -0,0 +1,58 @@ +import apt_inst +import apt_pkg +from apt_inst import arCheckMember + +from gettext import gettext as _ + +class NoDebArchiveException(IOError): + pass + +class DebPackage(object): + + _supported_data_members = ("data.tar.gz", "data.tar.bz2", "data.tar.lzma") + + def __init__(self, filename=None): + self._section = {} + if filename: + self.open(filename) + + def open(self, filename): + " open given debfile " + self.filename = filename + if not arCheckMember(open(self.filename), "debian-binary"): + raise NoDebArchiveException, _("This is not a valid DEB archive, missing '%s' member" % "debian-binary") + control = apt_inst.debExtractControl(open(self.filename)) + self._sections = apt_pkg.ParseSection(control) + self.pkgname = self._sections["Package"] + + def __getitem__(self, key): + return self._sections[key] + + def filelist(self): + """ return the list of files in the deb """ + files = [] + def extract_cb(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor): + #print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\ + # % (What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor) + files.append(Name) + for member in self._supported_data_members: + if arCheckMember(open(self.filename), member): + try: + apt_inst.debExtract(open(self.filename), extract_cb, member) + break + except SystemError, e: + return [_("List of files for '%s'could not be read" % self.filename)] + return files + filelist = property(filelist) + + + +if __name__ == "__main__": + import sys + + d = DebPackage(sys.argv[1]) + print d["Section"] + print d["Maintainer"] + print "Files:" + print "\n".join(d.filelist) + diff --git a/apt/package.py b/apt/package.py index b82f1aa0..4524a47d 100644 --- a/apt/package.py +++ b/apt/package.py @@ -40,6 +40,23 @@ class Dependency(object): def __init__(self, alternatives): self.or_dependencies = alternatives +class Record(object): + """ represents a pkgRecord, can be accessed like a + dictionary and gives the original package record + if accessed as a string """ + def __init__(self, s): + self._str = s + self._rec = apt_pkg.ParseSection(s) + def __str__(self): + return self._str + def __getitem__(self, key): + k = self._rec.get(key) + if k is None: + raise KeyError + return k + def has_key(self, key): + return self._rec.has_key(key) + class Package(object): """ This class represents a package in the cache """ @@ -244,14 +261,14 @@ class Package(object): " return the full pkgrecord as string of the candidate version " if not self._lookupRecord(True): return None - return self._records.Record + return Record(self._records.Record) candidateRecord = property(candidateRecord) def installedRecord(self): " return the full pkgrecord as string of the installed version " if not self._lookupRecord(False): return None - return self._records.Record + return Record(self._records.Record) installedRecord = property(installedRecord) # depcache states |
