diff options
| -rw-r--r-- | apt/__init__.py | 1 | ||||
| -rw-r--r-- | apt/cache.py | 3 | ||||
| -rw-r--r-- | apt/cdrom.py | 48 | ||||
| -rw-r--r-- | apt/package.py | 75 | ||||
| -rw-r--r-- | apt/progress.py | 2 | ||||
| -rw-r--r-- | debian/changelog | 16 | ||||
| -rw-r--r-- | python/string.cc | 6 |
7 files changed, 146 insertions, 5 deletions
diff --git a/apt/__init__.py b/apt/__init__.py index 15df6990..c6a2ff39 100644 --- a/apt/__init__.py +++ b/apt/__init__.py @@ -7,6 +7,7 @@ import os from apt.package import Package from apt.cache import Cache from apt.progress import OpProgress, FetchProgress, InstallProgress, CdromProgress +from apt.cdrom import Cdrom from apt_pkg import SizeToStr, TimeToStr, VersionCompare # init the package system diff --git a/apt/cache.py b/apt/cache.py index 690510e3..9e682bd8 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -33,11 +33,10 @@ class Cache(object): def __init__(self, progress=None, rootdir=None): self._callbacks = {} - self.open(progress) - if rootdir: apt_pkg.Config.Set("Dir", rootdir) apt_pkg.Config.Set("Dir::State::status", rootdir + "/var/lib/dpkg/status") + self.open(progress) def _runCallbacks(self, name): """ internal helper to run a callback """ diff --git a/apt/cdrom.py b/apt/cdrom.py new file mode 100644 index 00000000..8d73339c --- /dev/null +++ b/apt/cdrom.py @@ -0,0 +1,48 @@ + +import apt_pkg +from progress import CdromProgress + +class Cdrom(object): + def __init__(self, progress=None, mountpoint=None, nomount=True): + """ Support for apt-cdrom like features. + Options: + - progress: optional progress.CdromProgress() subclass + - mountpoint: optional alternative mountpoint + - nomount: do not mess with mount/umount the CD + """ + self._cdrom = apt_pkg.GetCdrom() + if progress is None: + self._progress = CdromProgress() + else: + self._progress = progress + # see if we have a alternative mountpoint + if mountpoint is not None: + apt_pkg.Config.Set("Acquire::cdrom::mount",mountpoint) + # do not mess with mount points by default + if nomount is True: + apt_pkg.Config.Set("APT::CDROM::NoMount", "true") + else: + apt_pkg.Config.Set("APT::CDROM::NoMount", "false") + def add(self): + " add cdrom to the sources.list " + return self._cdrom.Add(self._progress) + def ident(self): + " identify the cdrom " + (res, ident) = self._cdrom.Ident(self._progress) + if res: + return ident + return None + @property + def inSourcesList(self): + " check if the cdrom is already in the current sources.list " + cdid = self.ident() + if cdid is None: + # FIXME: throw exception instead + return False + # FIXME: check sources.list.d/ as well + for line in open(apt_pkg.Config.FindFile("Dir::Etc::sourcelist")): + line = line.strip() + if not line.startswith("#") and cdid in line: + return True + return False + diff --git a/apt/package.py b/apt/package.py index 0d1145ea..13481be3 100644 --- a/apt/package.py +++ b/apt/package.py @@ -24,6 +24,17 @@ import sys import random import string +class BaseDependency(object): + " a single dependency " + def __init__(self, name, rel, ver, pre): + self.name = name + self.relation = rel + self.version = ver + self.preDepend = pre + +class Dependency(object): + def __init__(self, alternatives): + self.or_dependencies = alternatives class Package(object): """ This class represents a package in the cache @@ -94,6 +105,44 @@ class Package(object): return None candidateVersion = property(candidateVersion) + def _getDependencies(self, ver): + depends_list = [] + depends = ver.DependsList + for t in ["PreDepends", "Depends"]: + if not depends.has_key(t): + continue + for depVerList in depends[t]: + base_deps = [] + for depOr in depVerList: + base_deps.append(BaseDependency(depOr.TargetPkg.Name, depOr.TargetVer, depOr.CompType, (t == "PreDepends"))) + depends_list.append(Dependency(base_deps)) + return depends_list + + def candidateDependencies(self): + """ return a list of candidate dependencies """ + candver = self._depcache.GetCandidateVer(self._pkg) + if candver == None: + return [] + return self._getDependencies(candver) + candidateDependencies = property(candidateDependencies) + + def installedDependencies(self): + """ return a list of installed dependencies """ + ver = self._pkg.CurrentVer + if ver == None: + return [] + return self._getDependencies(ver) + installedDependencies = property(installedDependencies) + + def architecture(self): + if not self._lookupRecord(): + return None + sec = apt_pkg.ParseSection(self._records.Record) + if sec.has_key("Architecture"): + return sec["Architecture"] + return None + architecture = property(architecture) + def _downloadable(self, useCandidate=True): """ helper, return if the version is downloadable """ if useCandidate: @@ -159,7 +208,11 @@ class Package(object): if not self._lookupRecord(): return "" desc = "" - for line in string.split(self._records.LongDesc, "\n"): + try: + tmp = unicode(self._records.LongDesc) + except UnicodeDecodeError: + tmp = "Invalid unicode in description" + for line in string.split(tmp, "\n"): tmp = string.strip(line) if tmp == ".": desc += "\n" @@ -175,6 +228,19 @@ class Package(object): return self._records.LongDesc rawDescription = property(rawDescription) + def candidateRecord(self): + " return the full pkgrecord as string of the candidate version " + if not self._lookupRecord(True): + return None + return 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 + installedRecord = property(installedRecord) # depcache states def markedInstall(self): @@ -238,6 +304,8 @@ class Package(object): def installedSize(self): """ The size of the currently installed package """ ver = self._pkg.CurrentVer + if ver is None: + return 0 return ver.InstalledSize installedSize = property(installedSize) @@ -344,6 +412,11 @@ if __name__ == "__main__": print "Description (unformated):\n%s" % pkg.rawDescription print "InstalledSize: %s " % pkg.installedSize print "PackageSize: %s " % pkg.packageSize + print "Dependencies: %s" % pkg.installedDependencies + for dep in pkg.candidateDependencies: + print ",".join(["%s (%s) (%s) (%s)" % (o.name,o.version,o.relation, o.preDepend) for o in dep.or_dependencies]) + print "arch: %s" % pkg.architecture + print "rec: ",pkg.candidateRecord # now test install/remove import apt diff --git a/apt/progress.py b/apt/progress.py index 5169adf7..bb1bce35 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -28,6 +28,8 @@ from errno import * import select import apt_pkg +import apt + class OpProgress(object): """ Abstract class to implement reporting on cache opening Subclass this class to implement simple Operation progress reporting diff --git a/debian/changelog b/debian/changelog index 1084928b..01ca6da5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,19 @@ +python-apt (0.6.21) unstable; urgency=low + + * apt/cdrom.py: + - better cdrom handling support + * apt/package.py: + - added candidateDependencies, installedDependencies + - SizeToString supports PyLong too + - support pkg.architecture + - support candidateRecord, installedRecord + * apt/cache.py: + - fix rootdir + * apt/cdrom.py: + - fix bug in cdrom mountpoint handling + + -- Michael Vogt <mvo@debian.org> Tue, 24 Apr 2007 21:24:28 +0200 + python-apt (0.6.20) unstable; urgency=low * python/generic.h: diff --git a/python/string.cc b/python/string.cc index 16adc8cd..d0926da5 100644 --- a/python/string.cc +++ b/python/string.cc @@ -53,9 +53,11 @@ PyObject *StrSizeToStr(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"O",&Obj) == 0) return 0; if (PyInt_Check(Obj)) - return CppPyString(SizeToStr(PyInt_AS_LONG(Obj))); + return CppPyString(SizeToStr(PyInt_AsLong(Obj))); + if (PyLong_Check(Obj)) + return CppPyString(SizeToStr(PyLong_AsLong(Obj))); if (PyFloat_Check(Obj)) - return CppPyString(SizeToStr(PyFloat_AS_DOUBLE(Obj))); + return CppPyString(SizeToStr(PyFloat_AsDouble(Obj))); PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); return 0; |
