summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2007-07-31 13:43:09 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2007-07-31 13:43:09 +0200
commita7da352b92726adf18f121de2711976f356ded29 (patch)
treee1eae8b17d2fcecb704805a46753867d58986538 /apt
parent254c868e6e5e536eecdafc27c546b036397c2dc5 (diff)
parente124705b95abb6ea3c4c6f96ed5559dac8a2c697 (diff)
downloadpython-apt-a7da352b92726adf18f121de2711976f356ded29.tar.gz
* apt/debfile.py:
- added wrapper around apt_inst.debExtract() - support dictionary like access * python/apt_instmodule.cc: - added arCheckMember() * build with latest python-distutils-extra (thanks to doko for notifiying about the problem) * apt/package.py: - added Record class that can be accessed like a dictionary and return it in candidateRecord and installedRecord (thanks to Alexander Sack for discussing this with me) * doc/examples/records.py: - added example how to use the new Records class * apt/cache.py: - throw FetchCancelleException, FetchFailedException, LockFailedException exceptions when something goes wrong - generalized some code, bringing it into the Distribution class, and wrote some missing methods for the DebianDistribution one (thanks to Gustavo Noronha Silva) - updated for python-distutils-extra (>= 1.9.0) - fix i18n files - increase str buffer in PackageIndexFileRepr * python/package.py: * python/cache.py:
Diffstat (limited to 'apt')
-rw-r--r--apt/debfile.py58
1 files changed, 58 insertions, 0 deletions
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)
+