diff options
| author | Michael Vogt <egon@bottom> | 2007-05-02 18:43:13 +0200 |
|---|---|---|
| committer | Michael Vogt <egon@bottom> | 2007-05-02 18:43:13 +0200 |
| commit | 500e805d3fa7faee957e67410f525435224f1e21 (patch) | |
| tree | fad6c63e9aa28d7df2effe7d378923e05cf2db10 | |
| parent | a231ca12f5fbb6adb55142973eb4d7a284763ace (diff) | |
| parent | cccfb88edd8dd82348ff89f96a0b26ac815b483c (diff) | |
| download | python-apt-500e805d3fa7faee957e67410f525435224f1e21.tar.gz | |
* merged from python-apt--mvo
| -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 | 27 | ||||
| -rw-r--r-- | debian/changelog | 53 | ||||
| -rw-r--r-- | debian/control | 2 | ||||
| -rwxr-xr-x | debian/rules | 3 | ||||
| -rw-r--r-- | doc/examples/inst.py | 5 | ||||
| -rw-r--r-- | doc/examples/sources.py | 2 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 8 | ||||
| -rw-r--r-- | python/cache.cc | 8 | ||||
| -rw-r--r-- | python/configuration.cc | 2 | ||||
| -rw-r--r-- | python/generic.h | 8 | ||||
| -rw-r--r-- | python/pkgmanager.cc | 2 | ||||
| -rw-r--r-- | python/pkgrecords.cc | 2 | ||||
| -rw-r--r-- | python/progress.cc | 10 | ||||
| -rw-r--r-- | python/string.cc | 6 | ||||
| -rw-r--r-- | python/tag.cc | 4 | ||||
| -rwxr-xr-x | tests/memleak.py | 14 |
20 files changed, 244 insertions, 39 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 4119067c..bb1bce35 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,16 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import sys, apt_pkg, os, fcntl, string, re +import sys +import os +import re +import fcntl +import string +from errno import * +import select +import apt_pkg + +import apt class OpProgress(object): """ Abstract class to implement reporting on cache opening @@ -139,6 +148,7 @@ class InstallProgress(DumbInstallProgress): """ def __init__(self): DumbInstallProgress.__init__(self) + self.selectTimeout = 0.1 (read, write) = os.pipe() self.writefd=write self.statusfd = os.fdopen(read, "r") @@ -162,12 +172,17 @@ class InstallProgress(DumbInstallProgress): self.read += os.read(self.statusfd.fileno(),1) except OSError, (errno,errstr): # resource temporarly unavailable is ignored - if errno != 11: + if errno != EAGAIN and errnor != EWOULDBLOCK: print errstr if self.read.endswith("\n"): s = self.read #print s - (status, pkg, percent, status_str) = string.split(s, ":") + try: + (status, pkg, percent, status_str) = string.split(s, ":",3) + except ValueError, e: + # silently ignore lines that can't be parsed + self.read = "" + return #print "percent: %s %s" % (pkg, float(percent)/100.0) if status == "pmerror": self.error(pkg,status_str) @@ -184,22 +199,22 @@ class InstallProgress(DumbInstallProgress): self.percent = float(percent) self.status = string.strip(status_str) self.read = "" - def fork(self): return os.fork() def waitChild(self): while True: + select.select([self.statusfd],[],[], self.selectTimeout) + self.updateInterface() (pid, res) = os.waitpid(self.child_pid,os.WNOHANG) if pid == self.child_pid: break - self.updateInterface() return os.WEXITSTATUS(res) def run(self, pm): pid = self.fork() if pid == 0: # child res = pm.DoInstall(self.writefd) - sys.exit(res) + os._exit(res) self.child_pid = pid res = self.waitChild() return res diff --git a/debian/changelog b/debian/changelog index b210fb24..09cd5139 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,55 @@ -python-apt (0.6.19exp1) experimental; urgency=low +python-apt (0.7.0) experimental; urgency=low + + * python/apt_pkgmodule.cc: + - added pkgCache::State::PkgCurrentState enums + + -- Michael Vogt <mvo@debian.org> Wed, 2 May 2007 18:41:53 +0200 + +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: + - fix incorrect use of PyMem_DEL(), use pyObject_DEL() + instead. This fixes a nasty segfault with python2.5 + (lp: 63226) + * python/pkgrecords.cc: + - export SHA1Hash() as well + * debian/rules: Remove dh_python call. + * apt/progress.cc: + - protect against not-parsable strings send from dpkg (lp: 68553) + * python/pkgmanager.cc: + - fix typo (closes: #382853) + * debian/control: + - tightend dependency (closes: #383478) + * apt/progress.py: + - use os._exit() in the child (lp: #53298) + - use select() when checking for statusfd (lp: #53282) + * acknoledge NMU (closes: #378048, #373512) + * python/apt_pkgmodule.cc: + - fix missing docstring (closes: #368907), + Thanks to Josh Triplett + * make it build against python2.5 + * python/progress.cc: + - fix memleak (lp: #43096) + + -- Michael Vogt <mvo@debian.org> Tue, 19 Dec 2006 13:32:11 +0100 + +python-apt (0.6.19) unstable; urgency=low [ Michael Vogt ] * doc/examples/print_uris.py: diff --git a/debian/control b/debian/control index 5fa1bc83..e2f97b78 100644 --- a/debian/control +++ b/debian/control @@ -5,7 +5,7 @@ Maintainer: APT Development Team <deity@lists.debian.org> Uploaders: Matt Zimmerman <mdz@debian.org>, Michael Vogt <mvo@debian.org> Standards-Version: 3.6.2.0 XS-Python-Version: all -Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.6.40), apt-utils, python-all-dev, python-central +Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.6.45), apt-utils, python-all-dev, python-central Package: python-apt Architecture: any diff --git a/debian/rules b/debian/rules index ee159b89..7299f554 100755 --- a/debian/rules +++ b/debian/rules @@ -49,12 +49,11 @@ binary-arch: build for PY in $(PYTHON); do \ /usr/bin/$$PY setup.py install --prefix=`pwd`/debian/python-apt/usr; \ done - + dh_installdocs dh_installchangelogs dh_installexamples dh_pycentral - dh_python dh_strip dh_compress dh_fixperms diff --git a/doc/examples/inst.py b/doc/examples/inst.py index 0e91c28f..ff9d452c 100644 --- a/doc/examples/inst.py +++ b/doc/examples/inst.py @@ -29,10 +29,7 @@ cache = apt.Cache(apt.progress.OpTextProgress()) fprogress = apt.progress.TextFetchProgress() iprogress = TextInstallProgress() -pkg = cache["test-package"] -pkg.markUpgrade() -cache.commit(fprogress,iprogress) -sys.exit(1) +pkg = cache["3dchess"] # install or remove, the importend thing is to keep us busy :) if pkg.isInstalled: diff --git a/doc/examples/sources.py b/doc/examples/sources.py index c12c6f15..b48c0ba5 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -12,4 +12,4 @@ sources.Restart() while sources.Lookup('hello'): print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` print sources.Files - print sources.Index.ArchiveURI("") + print sources.Index.ArchiveURI(sources.Files[0][2]) diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index b1c5c2a5..627eaced 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -440,7 +440,7 @@ static PyMethodDef methods[] = {"GetPkgAcqFile",(PyCFunction)GetPkgAcqFile,METH_KEYWORDS|METH_VARARGS,"GetPkgAcquireFile() -> pkgAcquireFile"}, // PkgManager - {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager() -> PackageManager"}, + {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager(DepCache) -> PackageManager"}, {} }; @@ -502,6 +502,12 @@ extern "C" void initapt_pkg() AddInt(Dict,"PriOptional",pkgCache::State::Optional); AddInt(Dict,"PriExtra",pkgCache::State::Extra); + AddInt(Dict,"CurStateNotInstalled",pkgCache::State::NotInstalled); + AddInt(Dict,"CurStateUnPacked",pkgCache::State::UnPacked); + AddInt(Dict,"CurStateHalfConfigured",pkgCache::State::HalfConfigured); + AddInt(Dict,"CurStateHalfInstalled",pkgCache::State::HalfInstalled); + AddInt(Dict,"CurStateConfigFiles",pkgCache::State::ConfigFiles); + AddInt(Dict,"CurStateInstalled",pkgCache::State::Installed); } /*}}}*/ diff --git a/python/cache.cc b/python/cache.cc index 174423c2..b6278de0 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -287,12 +287,12 @@ PyTypeObject PkgCacheFileType = /*}}}*/ // Package List Class /*{{{*/ // --------------------------------------------------------------------- -static int PkgListLen(PyObject *Self) +static Py_ssize_t PkgListLen(PyObject *Self) { return GetCpp<PkgListStruct>(Self).Iter.Cache()->HeaderP->PackageCount; } -static PyObject *PkgListItem(PyObject *iSelf,int Index) +static PyObject *PkgListItem(PyObject *iSelf,Py_ssize_t Index) { PkgListStruct &Self = GetCpp<PkgListStruct>(iSelf); if (Index < 0 || (unsigned)Index >= Self.Iter.Cache()->HeaderP->PackageCount) @@ -815,12 +815,12 @@ PyTypeObject DependencyType = /*}}}*/ // Reverse Dependency List Class /*{{{*/ // --------------------------------------------------------------------- -static int RDepListLen(PyObject *Self) +static Py_ssize_t RDepListLen(PyObject *Self) { return GetCpp<RDepListStruct>(Self).Len; } -static PyObject *RDepListItem(PyObject *iSelf,int Index) +static PyObject *RDepListItem(PyObject *iSelf,Py_ssize_t Index) { RDepListStruct &Self = GetCpp<RDepListStruct>(iSelf); if (Index < 0 || (unsigned)Index >= Self.Len) diff --git a/python/configuration.cc b/python/configuration.cc index 6cf33581..55eac1bf 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -490,7 +490,7 @@ PyTypeObject ConfigurationPtrType = sizeof(CppPyObject<Configuration *>), // tp_basicsize 0, // tp_itemsize // Methods - (destructor)PyMem_Free, // tp_dealloc + (destructor)PyObject_Free, // tp_dealloc 0, // tp_print CnfGetAttr, // tp_getattr 0, // tp_setattr diff --git a/python/generic.h b/python/generic.h index a808e28d..a1b662bb 100644 --- a/python/generic.h +++ b/python/generic.h @@ -31,6 +31,10 @@ #include <string> #include <new> +#if PYTHON_API_VERSION < 1013 +typedef int Py_ssize_t; +#endif + template <class T> struct CppPyObject : public PyObject { // We are only using CppPyObject and friends as dumb structs only, ie the @@ -109,7 +113,7 @@ template <class T> void CppDealloc(PyObject *Obj) { GetCpp<T>(Obj).~T(); - PyMem_DEL(Obj); + PyObject_DEL(Obj); } template <class T> @@ -119,7 +123,7 @@ void CppOwnedDealloc(PyObject *iObj) Obj->Object.~T(); if (Obj->Owner != 0) Py_DECREF(Obj->Owner); - PyMem_DEL(Obj); + PyObject_DEL(Obj); } inline PyObject *CppPyString(std::string Str) diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index bcd4c45b..9670f238 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -68,7 +68,7 @@ static PyObject *PkgManagerFixMissing(PyObject *Self,PyObject *Args) static PyMethodDef PkgManagerMethods[] = { - {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archvies into the fetcher"}, + {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, {"DoInstall",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, {"FixMissing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, {} diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index ec78f554..4a5556f2 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -63,6 +63,8 @@ static PyObject *PkgRecordsAttr(PyObject *Self,char *Name) return CppPyString(Struct.Last->FileName()); else if (strcmp("MD5Hash",Name) == 0) return CppPyString(Struct.Last->MD5Hash()); + else if (strcmp("SHA1Hash",Name) == 0) + return CppPyString(Struct.Last->SHA1Hash()); else if (strcmp("SourcePkg",Name) == 0) return CppPyString(Struct.Last->SourcePkg()); else if (strcmp("Maintainer",Name) == 0) diff --git a/python/progress.cc b/python/progress.cc index f00058c9..df9c2ec1 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -18,8 +18,10 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, PyObject *arglist, PyObject **res) { - if(callbackInst == 0) + if(callbackInst == 0) { + Py_XDECREF(arglist); return false; + } PyObject *method = PyObject_GetAttrString(callbackInst,(char*) method_name); if(method == NULL) { @@ -49,22 +51,24 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, // OpProgress interface -// FIXME: add "string Op, string SubOp" as attribute to the callbackInst void PyOpProgress::Update() { - PyObject *o; o = Py_BuildValue("s", Op.c_str()); PyObject_SetAttrString(callbackInst, "op", o); + Py_XDECREF(o); o = Py_BuildValue("s", SubOp.c_str()); PyObject_SetAttrString(callbackInst, "subOp", o); + Py_XDECREF(o); o = Py_BuildValue("b", MajorChange); PyObject_SetAttrString(callbackInst, "majorChange", o); + Py_XDECREF(o); // Build up the argument list... PyObject *arglist = Py_BuildValue("(f)", Percent); if(CheckChange(0.05)) RunSimpleCallback("update", arglist); + Py_XDECREF(arglist); }; void PyOpProgress::Done() 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; diff --git a/python/tag.cc b/python/tag.cc index 41db059c..d0d862c9 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -68,7 +68,7 @@ void TagFileFree(PyObject *Obj) Self->Object.~pkgTagFile(); Self->Fd.~FileFd(); Py_DECREF(Self->File); - PyMem_DEL(Obj); + PyObject_DEL(Obj); } /*}}}*/ @@ -132,7 +132,7 @@ static PyObject *TagSecMap(PyObject *Self,PyObject *Arg) } // len() operation -static int TagSecLength(PyObject *Self) +static Py_ssize_t TagSecLength(PyObject *Self) { pkgTagSection &Sec = GetCpp<pkgTagSection>(Self); return Sec.Count(); diff --git a/tests/memleak.py b/tests/memleak.py index 3e59cbb7..b5d05afc 100755 --- a/tests/memleak.py +++ b/tests/memleak.py @@ -10,11 +10,15 @@ import sys cache = apt.Cache() # memleak -#for i in range(100): -# cache.open(None) -# print cache["apt"].name -# time.sleep(1) -# gc.collect() +for i in range(100): + cache.open(None) + print cache["apt"].name + time.sleep(1) + gc.collect() + f = open("%s" % i,"w") + for obj in gc.get_objects(): + f.write("%s\n" % str(obj)) + f.close() # memleak #for i in range(100): |
