From ccd98916ba50c7583f354e0d3487ffb0830103f0 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Apr 2009 20:00:09 +0200 Subject: * python/configuration.cc: Support the 'in' operator for Configuration Support the replacement of mapping.has_key() for Configuration,ConfigurationPtr and ConfigurationSub objects. This is implemented by extending the various types with the tp_as_sequence slot, which refers to a PySequenceMethods containing only this method. The CnfGetAttr() function has been removed and replaced by the use of the tp_method slot. This helps the py3k port because the previously used Py_FindMethod() is not avilable anymore. This completes the support of the 'in' operator in all python-apt objects, which makes it even easier to convert python-apt-using applications to py3k once python-apt supports it, as 2to3 converts 'm.has_key(k)' to 'k in m'. Also finalize the types in apt_pkgmodule.cc and add the new 'key in conf' description to the documentation. --- python/configuration.cc | 70 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 15 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/configuration.cc b/python/configuration.cc index 21f70bc1..a95ac029 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -128,6 +128,11 @@ static PyObject *CnfExists(PyObject *Self,PyObject *Args) return Py_BuildValue("i",(int)GetSelf(Self).Exists(Name)); } +static int CnfContains(PyObject *Self,PyObject *Arg) +{ + return (int)GetSelf(Self).Exists(PyString_AsString(Arg)); +} + static char *doc_Clear = "Clear(Name) -> None"; static PyObject *CnfClear(PyObject *Self,PyObject *Args) { @@ -470,34 +475,41 @@ static PyMethodDef CnfMethods[] = {} }; -// CnfGetAttr - Get an attribute - variable/method /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static PyObject *CnfGetAttr(PyObject *Self,char *Name) -{ - return Py_FindMethod(CnfMethods,Self,Name); -} - // Type for a Normal Configuration object +static PySequenceMethods ConfigurationSeq = {0,0,0,0,0,0,0,CnfContains,0,0}; static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; PyTypeObject ConfigurationType = { PyObject_HEAD_INIT(&PyType_Type) - 0, // ob_size + 0, // ob_size "Configuration", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods CppDealloc, // tp_dealloc 0, // tp_print - CnfGetAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // tp_as_number - 0, // tp_as_sequence + &ConfigurationSeq, // tp_as_sequence &ConfigurationMap, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "Configuration Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + CnfMethods, // tp_methods }; PyTypeObject ConfigurationPtrType = @@ -510,14 +522,28 @@ PyTypeObject ConfigurationPtrType = // Methods (destructor)PyObject_Free, // tp_dealloc 0, // tp_print - CnfGetAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // tp_as_number - 0, // tp_as_sequence + &ConfigurationSeq, // tp_as_sequence &ConfigurationMap, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "ConfigurationPtr Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + CnfMethods, // tp_methods }; PyTypeObject ConfigurationSubType = @@ -530,13 +556,27 @@ PyTypeObject ConfigurationSubType = // Methods CnfSubFree, // tp_dealloc 0, // tp_print - CnfGetAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // tp_as_number - 0, // tp_as_sequence + &ConfigurationSeq, // tp_as_sequence &ConfigurationMap, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "ConfigurationSub Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + CnfMethods, // tp_methods }; -- cgit v1.2.3 From 8413810c46f802490280b0be1beebaaadf1aa9f2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Apr 2009 00:47:23 +0200 Subject: * Remove any trailing whitespace --- apt/package.py | 3 +-- doc/source/apt_pkg/index.rst | 2 +- python/apt_pkgmodule.cc | 2 +- python/cache.cc | 2 +- python/cdrom.cc | 6 +++--- python/configuration.cc | 18 +++++++++--------- python/depcache.cc | 12 ++++++------ python/progress.cc | 2 +- python/tag.cc | 12 ++++++------ python/tar.cc | 2 +- tests/getcache_mem_corruption.py | 6 +++--- 11 files changed, 33 insertions(+), 34 deletions(-) (limited to 'python/configuration.cc') diff --git a/apt/package.py b/apt/package.py index 5adef15c..3ea1105d 100644 --- a/apt/package.py +++ b/apt/package.py @@ -639,7 +639,6 @@ class Package(object): def installedPriority(self): """Return the priority (of the installed version). - .. deprecated:: 0.7.9 """ return getattr(self.installed, 'priority', None) @@ -800,7 +799,7 @@ class Package(object): contain multiple named variables which will be substitued. These variables are (src_section, prefix, src_pkg, src_ver). An example is the Ubuntu changelog:: - + "http://changelogs.ubuntu.com/changelogs/pool" \\ "/%(src_section)s/%(prefix)s/%(src_pkg)s" \\ "/%(src_pkg)s_%(src_ver)s/changelog" diff --git a/doc/source/apt_pkg/index.rst b/doc/source/apt_pkg/index.rst index 38310bb5..60c3ba9b 100644 --- a/doc/source/apt_pkg/index.rst +++ b/doc/source/apt_pkg/index.rst @@ -252,7 +252,7 @@ Dependencies >>> apt_pkg.ParseDepends("PkgA (>= VerA) | PkgB (>= VerB)") [[('PkgA', 'VerA', '>='), ('PkgB', 'VerB', '>=')]] - + Furthemore, this function also supports to limit the architectures, as used in e.g. Build-Depends:: diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 5d0b2c0a..145a2bab 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -481,7 +481,7 @@ extern "C" void initapt_pkg() if (PyType_Ready(&PkgCdromType) == -1) return; if (PyType_Ready(&PkgProblemResolverType) == -1) return; if (PyType_Ready(&PkgActionGroupType) == -1) return; - + // Initialize the module PyObject *Module = Py_InitModule("apt_pkg",methods); diff --git a/python/cache.cc b/python/cache.cc index 4db097c7..31d8c45d 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -951,7 +951,7 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) progress.setCallbackInst(pyCallbackInst); if (Cache->Open(progress,false) == false) return HandleErrors(); - } + } else { OpTextProgress Prog; if (Cache->Open(Prog,false) == false) diff --git a/python/cdrom.cc b/python/cdrom.cc index 1278d6b7..0816d93e 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -84,16 +84,16 @@ PyTypeObject PkgCdromType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "Cdrom Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext PkgCdromMethods, // tp_methods }; diff --git a/python/configuration.cc b/python/configuration.cc index a95ac029..b4adf357 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -498,16 +498,16 @@ PyTypeObject ConfigurationType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "Configuration Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods }; @@ -532,16 +532,16 @@ PyTypeObject ConfigurationPtrType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ConfigurationPtr Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods }; @@ -566,16 +566,16 @@ PyTypeObject ConfigurationSubType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ConfigurationSub Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods }; diff --git a/python/depcache.cc b/python/depcache.cc index b23eecd9..2c73a1a9 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -769,16 +769,16 @@ PyTypeObject PkgProblemResolverType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ProblemResolver Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext PkgProblemResolverMethods, // tp_methods }; @@ -825,16 +825,16 @@ PyTypeObject PkgActionGroupType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "ActionGroup Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext PkgActionGroupMethods, // tp_methods }; diff --git a/python/progress.cc b/python/progress.cc index c5a1c138..bec40ce9 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -185,7 +185,7 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) bool res = true; if(!PyArg_Parse(result, "b", &res)) { - // most of the time the user who subclasses the pulse() + // most of the time the user who subclasses the pulse() // method forgot to add a return {True,False} so we just // assume he wants a True return true; diff --git a/python/tag.cc b/python/tag.cc index baf97b59..cdea3e03 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -401,16 +401,16 @@ PyTypeObject TagSecType = 0, // tp_hash 0, // tp_call TagSecStr, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "TagSection Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext TagSecMethods // tp_methods }; @@ -459,16 +459,16 @@ PyTypeObject TagFileType = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + 0, // tp_getattro 0, // tp_setattro - 0, // tp_as_buffer + 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags "TagFile Object", // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter + 0, // tp_iter 0, // tp_iternext TagFileMethods, // tp_methods 0, // tp_members diff --git a/python/tar.cc b/python/tar.cc index f0d57823..217554c2 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -111,7 +111,7 @@ PyObject *tarExtract(PyObject *Self,PyObject *Args) int fileno = PyObject_AsFileDescriptor(File); if (fileno == -1) return 0; - + FileFd Fd(fileno,false); ExtractTar Tar(Fd,0xFFFFFFFF,Comp); if (_error->PendingError() == true) diff --git a/tests/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py index 42e9af00..c3f6eff3 100644 --- a/tests/getcache_mem_corruption.py +++ b/tests/getcache_mem_corruption.py @@ -6,16 +6,16 @@ import re import unittest class TestGetCache(unittest.TestCase): - + def setUp(self): apt_pkg.InitConfig() apt_pkg.InitSystem() - + def testWrongInvocation(self): # wrongly invoke GetCache() rather than GetDepCache() apt_cache = apt_pkg.GetCache() self.assertRaises(ValueError, apt_pkg.GetCache, apt_cache) - + def testProperInvocation(self): apt_cache = apt_pkg.GetCache(apt.progress.OpTextProgress()) apt_depcache = apt_pkg.GetDepCache(apt_cache) -- cgit v1.2.3 From c876c5095673a2f1c0f2c0eef6eadef2ce200e19 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Apr 2009 16:19:12 +0200 Subject: * Introduce support for Python 3 (Closes: #523645) This is the first initial port to Python 3. The API is almost completely identical to the one found in Python 2, except that functions working with binary data require bytes (md5sum,sha1sum,sha256sum,Base64Encode). Using setup3.py to install the modules will not work, because the apt package still has to be converted to Python 3. For the package, we call 2to3-3.1 in debian/rules to do this automatically. --- apt/package.py | 6 +++- debian/changelog | 2 ++ debian/control | 2 ++ debian/rules | 26 +++++++++++++-- po/python-apt.pot | 10 +++--- python/acquire.cc | 6 ++++ python/apt_instmodule.cc | 35 ++++++++++++++++++- python/apt_pkgmodule.cc | 87 +++++++++++++++++++++++++++++++++++------------- python/cache.cc | 18 ++++++++++ python/cdrom.cc | 2 ++ python/configuration.cc | 6 ++++ python/depcache.cc | 6 ++++ python/generic.h | 25 ++++++++++++++ python/indexfile.cc | 2 ++ python/metaindex.cc | 2 ++ python/pkgmanager.cc | 2 ++ python/pkgrecords.cc | 2 ++ python/pkgsrcrecords.cc | 2 ++ python/sourcelist.cc | 2 ++ python/string.cc | 16 ++++++++- python/tag.cc | 4 +++ setup3.py | 77 ++++++++++++++++++++++++++++++++++++++++++ 22 files changed, 307 insertions(+), 33 deletions(-) create mode 100644 setup3.py (limited to 'python/configuration.cc') diff --git a/apt/package.py b/apt/package.py index 3ea1105d..f12f5559 100644 --- a/apt/package.py +++ b/apt/package.py @@ -272,8 +272,12 @@ class Version(object): """ self.summary # This does the lookup for us. desc = '' + + dsc = self.package._pcache._records.LongDesc try: - dsc = unicode(self.package._pcache._records.LongDesc, "utf-8") + if not isinstance(dsc, unicode): + # Only convert where needed (i.e. Python 2.X) + dsc = unicode(dsc, "utf-8") except UnicodeDecodeError, err: return _("Invalid unicode in description for '%s' (%s). " "Please report.") % (self.package.name, err) diff --git a/debian/changelog b/debian/changelog index 6cbdaac7..a9518d7d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,7 @@ python-apt (0.7.11) UNRELEASED; urgency=low + * Introduce support for Python 3 (Closes: #523645) + * Support the 'in' operator (e.g. "k in d") in Configuration{,Ptr,Sub} objects (e.g. apt_pkg.Config) and in TagSections (apt_pkg.ParseSection()) * Replace support for file objects with a more generic support for any object diff --git a/debian/control b/debian/control index 72476c58..08ee329f 100644 --- a/debian/control +++ b/debian/control @@ -11,6 +11,8 @@ Build-Depends: apt-utils, libapt-pkg-dev (>= 0.7.10), python-all-dbg, python-all-dev, + python3.1-dev, + python3.1-dbg, python-central (>= 0.5), python-distutils-extra (>= 1.9.0), python-gtk2, diff --git a/debian/rules b/debian/rules index 6d709ecd..7de945f2 100755 --- a/debian/rules +++ b/debian/rules @@ -11,22 +11,44 @@ DEB_PYTHON_PACKAGES_EXCLUDE=python-apt-dbg include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk +PY3K = y PKG=python-apt DEBVER=$(shell dpkg-parsechangelog |sed -n -e '/^Version:/s/^Version: //p') DEB_COMPRESS_EXCLUDE:=.html .js _static/* _sources/* _sources/*/* .inv DEB_BUILD_PROG:=debuild --preserve-envvar PATH --preserve-envvar CCACHE_DIR -us -uc $(DEB_BUILD_PROG_OPTS) export DEBVER + +ifeq ($(PY3K),y) +build/python-apt:: + python3.1 setup3.py build + +install/python-apt:: + python3.1 ./setup3.py install --root $(CURDIR)/debian/python-apt \ + --install-layout=deb --no-compile + + find $(CURDIR)/debian/python-apt/usr/lib/python3.1/dist-packages/ -name '*.py' \ + | xargs 2to3-3.1 | patch -p0 +endif + build/python-apt-dbg:: set -e; \ for i in $(cdbs_python_build_versions); do \ python$$i-dbg ./setup.py build; \ done + ifeq($(PY3K),y) + python3.1-dbg ./setup3.py build + endif install/python-apt-dbg:: for i in $(cdbs_python_build_versions); do \ - python$$i-dbg ./setup.py install --root $(CURDIR)/debian/python-apt-dbg; \ + python$$i-dbg ./setup.py install --root $(CURDIR)/debian/python-apt-dbg \ + --no-compile; \ done + ifeq($(PY3K),y) + python3.1-dbg ./setup3.py install --root $(CURDIR)/debian/python-apt-dbg \ + --install-layout=deb --no-compile + endif find debian/python-apt-dbg \ ! -type d ! -name '*_d.so' | xargs rm -f find debian/python-apt-dbg -depth -empty -exec rmdir {} \; @@ -39,4 +61,4 @@ binary-predeb/python-apt-dbg:: ln -s python-apt debian/python-apt-dbg/usr/share/doc/python-apt-dbg clean:: - rm -rf build/lib* build/temp* + rm -rf build/lib* build/temp* build diff --git a/po/python-apt.pot b/po/python-apt.pot index 9c23c579..d12ae967 100644 --- a/po/python-apt.pot +++ b/po/python-apt.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-04-12 19:07+0200\n" +"POT-Creation-Date: 2009-04-15 16:10+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -354,16 +354,16 @@ msgstr "" msgid "Complete" msgstr "" -#: ../apt/package.py:278 +#: ../apt/package.py:282 #, python-format msgid "Invalid unicode in description for '%s' (%s). Please report." msgstr "" -#: ../apt/package.py:745 ../apt/package.py:849 +#: ../apt/package.py:830 ../apt/package.py:934 msgid "The list of changes is not available" msgstr "" -#: ../apt/package.py:853 +#: ../apt/package.py:938 #, python-format msgid "" "The list of changes is not available yet.\n" @@ -372,7 +372,7 @@ msgid "" "until the changes become available or try again later." msgstr "" -#: ../apt/package.py:859 +#: ../apt/package.py:944 msgid "" "Failed to download the list of changes. \n" "Please check your Internet connection." diff --git a/python/acquire.cc b/python/acquire.cc index d39ee495..053753cd 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -72,7 +72,9 @@ static PyObject *AcquireItemRepr(PyObject *Self) PyTypeObject AcquireItemType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgAcquire::ItemIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -175,7 +177,9 @@ static PyGetSetDef PkgAcquireGetSet[] = { PyTypeObject PkgAcquireType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "Acquire", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize @@ -234,7 +238,9 @@ PyObject *GetAcquire(PyObject *Self,PyObject *Args) PyTypeObject PkgAcquireFileType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgAcquireFile", // tp_name sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index a9d81be4..09e3937e 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -162,8 +162,41 @@ static PyMethodDef methods[] = {} }; +#if PY_MAJOR_VERSION >= 3 +struct module_state { + PyObject *error; +}; +#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) + +static int apt_inst_traverse(PyObject *m, visitproc visit, void *arg) { + Py_VISIT(GETSTATE(m)->error); + return 0; +} + +static int apt_inst_clear(PyObject *m) { + Py_CLEAR(GETSTATE(m)->error); + return 0; +} + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "apt_inst", + NULL, + sizeof(struct module_state), + methods, + NULL, + apt_inst_traverse, + apt_inst_clear, + NULL +}; + +extern "C" PyObject * PyInit_apt_inst() +{ + return PyModule_Create(&moduledef); +} +#else extern "C" void initapt_inst() { Py_InitModule("apt_inst",methods); } - /*}}}*/ +#endif /*}}}*/ diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index fe6a739e..e71d8ee6 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -173,12 +173,12 @@ static PyObject *md5sum(PyObject *Self,PyObject *Args) return 0; // Digest of a string. - if (PyString_Check(Obj) != 0) + if (PyBytes_Check(Obj) != 0) { char *s; Py_ssize_t len; MD5Summation Sum; - PyString_AsStringAndSize(Obj, &s, &len); + PyBytes_AsStringAndSize(Obj, &s, &len); Sum.Add((const unsigned char*)s, len); return CppPyString(Sum.Result().Value()); } @@ -213,12 +213,12 @@ static PyObject *sha1sum(PyObject *Self,PyObject *Args) return 0; // Digest of a string. - if (PyString_Check(Obj) != 0) + if (PyBytes_Check(Obj) != 0) { char *s; Py_ssize_t len; SHA1Summation Sum; - PyString_AsStringAndSize(Obj, &s, &len); + PyBytes_AsStringAndSize(Obj, &s, &len); Sum.Add((const unsigned char*)s, len); return CppPyString(Sum.Result().Value()); } @@ -253,12 +253,12 @@ static PyObject *sha256sum(PyObject *Self,PyObject *Args) return 0; // Digest of a string. - if (PyString_Check(Obj) != 0) + if (PyBytes_Check(Obj) != 0) { char *s; Py_ssize_t len; SHA256Summation Sum; - PyString_AsStringAndSize(Obj, &s, &len); + PyBytes_AsStringAndSize(Obj, &s, &len); Sum.Add((const unsigned char*)s, len); return CppPyString(Sum.Result().Value()); } @@ -470,30 +470,68 @@ static void AddInt(PyObject *Dict,const char *Itm,unsigned long I) Py_DECREF(Obj); } +#if PY_MAJOR_VERSION >= 3 +struct module_state { + PyObject *error; +}; + +#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) + +static int apt_inst_traverse(PyObject *m, visitproc visit, void *arg) { + Py_VISIT(GETSTATE(m)->error); + return 0; +} + +static int apt_inst_clear(PyObject *m) { + Py_CLEAR(GETSTATE(m)->error); + return 0; +} + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "apt_inst", + NULL, + sizeof(struct module_state), + methods, + NULL, + apt_inst_traverse, + apt_inst_clear, + NULL +}; + +#define INIT_ERROR return 0 +extern "C" PyObject * PyInit_apt_pkg() +#else +#define INIT_ERROR return extern "C" void initapt_pkg() +#endif { // Finalize our types to add slots, etc. - if (PyType_Ready(&TagSecType) == -1) return; - if (PyType_Ready(&TagFileType) == -1) return; - if (PyType_Ready(&ConfigurationType) == -1) return; - if (PyType_Ready(&ConfigurationPtrType) == -1) return; - if (PyType_Ready(&ConfigurationSubType) == -1) return; - if (PyType_Ready(&PkgCdromType) == -1) return; - if (PyType_Ready(&PkgProblemResolverType) == -1) return; - if (PyType_Ready(&PkgActionGroupType) == -1) return; - if (PyType_Ready(&PkgSourceListType) == -1) return; - if (PyType_Ready(&PkgCacheType) == -1) return; - if (PyType_Ready(&DependencyType) == -1) return; - if (PyType_Ready(&PkgDepCacheType) == -1) return; - if (PyType_Ready(&PkgAcquireType) == -1) return; - if (PyType_Ready(&PackageIndexFileType) == -1) return; - if (PyType_Ready(&PkgManagerType) == -1) return; - if (PyType_Ready(&PkgSrcRecordsType) == -1) return; - if (PyType_Ready(&PkgRecordsType) == -1) return; + if (PyType_Ready(&TagSecType) == -1) INIT_ERROR; + if (PyType_Ready(&TagFileType) == -1) INIT_ERROR; + if (PyType_Ready(&ConfigurationType) == -1) INIT_ERROR; + if (PyType_Ready(&ConfigurationPtrType) == -1) INIT_ERROR; + if (PyType_Ready(&ConfigurationSubType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgCdromType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgProblemResolverType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgActionGroupType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgSourceListType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgCacheType) == -1) INIT_ERROR; + if (PyType_Ready(&DependencyType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgDepCacheType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgAcquireType) == -1) INIT_ERROR; + if (PyType_Ready(&PackageIndexFileType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgManagerType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgSrcRecordsType) == -1) INIT_ERROR; + if (PyType_Ready(&PkgRecordsType) == -1) INIT_ERROR; // Initialize the module + #if PY_MAJOR_VERSION >= 3 + PyObject *Module = PyModule_Create(&moduledef); + #else PyObject *Module = Py_InitModule("apt_pkg",methods); + #endif PyObject *Dict = PyModule_GetDict(Module); // Global variable linked to the global configuration class @@ -549,6 +587,9 @@ extern "C" void initapt_pkg() AddInt(Dict,"InstStateReInstReq",pkgCache::State::ReInstReq); AddInt(Dict,"InstStateHold",pkgCache::State::Hold); AddInt(Dict,"InstStateHoldReInstReq",pkgCache::State::HoldReInstReq); + #if PY_MAJOR_VERSION >= 3 + return Module; + #endif } /*}}}*/ diff --git a/python/cache.cc b/python/cache.cc index 2d8b8db7..957681ba 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -239,7 +239,9 @@ static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -277,7 +279,9 @@ PyTypeObject PkgCacheType = PyTypeObject PkgCacheFileType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCacheFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -345,7 +349,9 @@ static PySequenceMethods PkgListSeq = PyTypeObject PkgListType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::PkgIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -435,7 +441,9 @@ static PyObject *PackageRepr(PyObject *Self) PyTypeObject PackageType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::Package", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -498,7 +506,9 @@ static PyObject *DescriptionRepr(PyObject *Self) PyTypeObject DescriptionType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::DescIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -684,7 +694,9 @@ static PyObject *VersionRepr(PyObject *Self) PyTypeObject VersionType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::VerIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -759,7 +771,9 @@ static PyObject *PackageFileRepr(PyObject *Self) PyTypeObject PackageFileType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::PkgFileIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -905,7 +919,9 @@ static PyGetSetDef DependencyGetSet[] = { PyTypeObject DependencyType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::DepIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -991,7 +1007,9 @@ static PySequenceMethods RDepListSeq = PyTypeObject RDepListType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgCache::DepIterator", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/cdrom.cc b/python/cdrom.cc index 0816d93e..b3a38438 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -67,7 +67,9 @@ static PyMethodDef PkgCdromMethods[] = PyTypeObject PkgCdromType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "Cdrom", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/configuration.cc b/python/configuration.cc index b4adf357..eaac48ec 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -481,7 +481,9 @@ static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; PyTypeObject ConfigurationType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "Configuration", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize @@ -515,7 +517,9 @@ PyTypeObject ConfigurationType = PyTypeObject ConfigurationPtrType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "ConfigurationPtr", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize @@ -549,7 +553,9 @@ PyTypeObject ConfigurationPtrType = PyTypeObject ConfigurationSubType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "ConfigurationSub", // tp_name sizeof(SubConfiguration), // tp_basicsize 0, // tp_itemsize diff --git a/python/depcache.cc b/python/depcache.cc index ade3d4f5..1c9eeff7 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -594,7 +594,9 @@ static PyGetSetDef PkgDepCacheGetSet[] = { PyTypeObject PkgDepCacheType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgDepCache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -773,7 +775,9 @@ static PyMethodDef PkgProblemResolverMethods[] = PyTypeObject PkgProblemResolverType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgProblemResolver", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -829,7 +833,9 @@ static PyMethodDef PkgActionGroupMethods[] = PyTypeObject PkgActionGroupType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgActionGroup", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/generic.h b/python/generic.h index ce79a54c..6e66d24c 100644 --- a/python/generic.h +++ b/python/generic.h @@ -35,6 +35,31 @@ typedef int Py_ssize_t; #endif +/* Define compatibility for Python 3. + * + * We will use the names PyString_* to refer to the default string type + * of the current Python version (PyString on 2.X, PyUnicode on 3.X). + * + * When we really need unicode strings, we will use PyUnicode_* directly, as + * long as it exists in Python 2 and Python 3. + * + * When we want bytes in Python 3, we use PyBytes*_ instead of PyString_* and + * define aliases from PyBytes_* to PyString_* for Python 2. + */ + +#if PY_MAJOR_VERSION >= 3 +#define PyString_Check PyUnicode_Check +#define PyString_FromString PyUnicode_FromString +#define PyString_FromStringAndSize PyUnicode_FromStringAndSize +#define PyString_AsString(op) PyBytes_AsString(PyUnicode_AsUTF8String(op)) +#define PyInt_Check PyLong_Check +#define PyInt_AsLong PyLong_AsLong +#else +#define PyBytes_Check PyString_Check +#define PyBytes_AsString PyString_AsString +#define PyBytes_AsStringAndSize PyString_AsStringAndSize +#endif + template struct CppPyObject : public PyObject { // We are only using CppPyObject and friends as dumb structs only, ie the diff --git a/python/indexfile.cc b/python/indexfile.cc index dc55634f..bb40cdd0 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -81,7 +81,9 @@ static PyGetSetDef PackageIndexFileGetSet[] = { PyTypeObject PackageIndexFileType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgIndexFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/metaindex.cc b/python/metaindex.cc index efbc38af..cbaeafbd 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -59,7 +59,9 @@ static PyObject *MetaIndexRepr(PyObject *Self) PyTypeObject MetaIndexType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "metaIndex", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 52f86228..8f56cddc 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -95,7 +95,9 @@ static PyGetSetDef PkgManagerGetSet[] = { PyTypeObject PkgManagerType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "PackageManager", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 577aaf1c..978de6b7 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -135,7 +135,9 @@ static PyGetSetDef PkgRecordsGetSet[] = { PyTypeObject PkgRecordsType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgRecords", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index c830f8d2..97667d7a 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -183,7 +183,9 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { PyTypeObject PkgSrcRecordsType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgSrcRecords", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 9f8f8878..48b3b7c8 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -100,7 +100,9 @@ static PyGetSetDef PkgSourceListGetSet[] = { PyTypeObject PkgSourceListType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "pkgSourceList", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/string.cc b/python/string.cc index 8168ea5b..b95ee3eb 100644 --- a/python/string.cc +++ b/python/string.cc @@ -38,7 +38,21 @@ PyObject *Python(PyObject *Self,PyObject *Args) \ } MkStr(StrDeQuote,DeQuoteString); -MkStr(StrBase64Encode,Base64Encode); + +/* + * Input bytes(Py3k)/str(Py2), output str. + */ +PyObject *StrBase64Encode(PyObject *Self,PyObject *Args) { + char *Str = 0; + #if PY_MAJOR_VERSION >= 3 + if (PyArg_ParseTuple(Args,"y",&Str) == 0) + #else + if (PyArg_ParseTuple(Args,"s",&Str) == 0) + #endif + return 0; + return CppPyString(Base64Encode(Str)); +} + MkStr(StrURItoFileName,URItoFileName); //MkFloat(StrSizeToStr,SizeToStr); diff --git a/python/tag.cc b/python/tag.cc index cdea3e03..18d08580 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -384,7 +384,9 @@ PyMappingMethods TagSecMapMeth = {TagSecLength,TagSecMap,0}; PyTypeObject TagSecType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "TagSection", // tp_name sizeof(TagSecData), // tp_basicsize 0, // tp_itemsize @@ -442,7 +444,9 @@ static PyGetSetDef TagFileGetSet[] = { PyTypeObject TagFileType = { PyObject_HEAD_INIT(&PyType_Type) + #if PY_MAJOR_VERSION < 3 0, // ob_size + #endif "TagFile", // tp_name sizeof(TagFileData), // tp_basicsize 0, // tp_itemsize diff --git a/setup3.py b/setup3.py new file mode 100644 index 00000000..a3cbdc8e --- /dev/null +++ b/setup3.py @@ -0,0 +1,77 @@ +#! /usr/bin/env python3 +# $Id: setup.py,v 1.2 2002/01/08 07:13:21 jgg Exp $ +import glob +import os +import shutil +import sys + +from distutils.core import setup, Extension +from distutils.sysconfig import parse_makefile +#from DistUtilsExtra.command import build_extra, build_i18n + + +# The apt_pkg module +files = ["python/"+source for source in parse_makefile("python/makefile")["APT_PKG_SRC"].split()] +apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) + +# The apt_inst module +files = ["python/"+source for source in parse_makefile("python/makefile")["APT_INST_SRC"].split()] +apt_inst = Extension("apt_inst", files, libraries=["apt-pkg", "apt-inst"]) + +# Replace the leading _ that is used in the templates for translation +templates = [] + +# build doc +if len(sys.argv) > 1 and sys.argv[1] == "build": + if not os.path.exists("build/data/templates/"): + os.makedirs("build/data/templates") + for template in glob.glob('data/templates/*.info.in'): + source = open(template, "r") + build = open(os.path.join("build", template[:-3]), "w") + lines = source.readlines() + for line in lines: + build.write(line.lstrip("_")) + source.close() + build.close() + + +if len(sys.argv) > 1 and sys.argv[1] == "clean" and '-a' in sys.argv: + for dirname in "build/doc", "doc/build", "build/data", "build/mo": + if os.path.exists(dirname): + print("Removing", dirname) + shutil.rmtree(dirname) + else: + print("Not removing", dirname, "because it does not exist") + +setup(name="python-apt", + description="Python bindings for APT", + version=os.environ.get('DEBVER'), + author="APT Development Team", + author_email="deity@lists.debian.org", + ext_modules=[apt_pkg, apt_inst], + packages=['apt', 'apt.progress', 'aptsources'], + data_files = [('share/python-apt/templates', + glob.glob('build/data/templates/*.info')), + ('share/python-apt/templates', + glob.glob('data/templates/*.mirrors'))], +# cmdclass = {"build": build_extra.build_extra, +# "build_i18n": build_i18n.build_i18n}, + license = 'GNU GPL', + platforms = 'posix') + +if len(sys.argv) > 1 and sys.argv[1] == "build": + try: + import sphinx + except ImportError: + print(('W: Sphinx not available - Not building' + 'documentation'), file=sys.stderr) + try: + import pygtk + except ImportError: + print(('W: Not building documentation because python-' + 'gtk2 is not available at the moment.'), file=sys.stderr) + sys.exit(0) + sphinx.main(["sphinx", "-b", "html", "-d", "build/doc/doctrees", + os.path.abspath("doc/source"), "build/doc/html"]) + sphinx.main(["sphinx", "-b", "text", "-d", "build/doc/doctrees", + os.path.abspath("doc/source"), "build/doc/text"]) -- cgit v1.2.3 From 45cdd4f2c6b04bfdfd37ef0e1a6358b29680afb8 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 19 Apr 2009 15:17:32 +0200 Subject: * python/*.cc: Export all types and add a __new__() method to them. Some names may be changed before the release, but this is a good draft. --- python/acquire.cc | 119 ++++++++++++++++++++++++++++++++-------- python/apt_pkgmodule.cc | 49 +++++++++++++++++ python/apt_pkgmodule.h | 1 + python/cache.cc | 125 ++++++++++++++++++++++++------------------ python/cdrom.cc | 38 +++++++++---- python/configuration.cc | 23 ++++++-- python/depcache.cc | 140 +++++++++++++++++++++++++++++++++--------------- python/indexfile.cc | 2 +- python/metaindex.cc | 2 +- python/pkgmanager.cc | 52 +++++++++++------- python/pkgrecords.cc | 31 ++++++++--- python/pkgsrcrecords.cc | 18 ++++++- python/sourcelist.cc | 18 ++++++- python/tag.cc | 75 ++++++++++++++++++++------ 14 files changed, 519 insertions(+), 174 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index abd3884d..1cdf0cb9 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -194,13 +194,41 @@ static PyGetSetDef PkgAcquireGetSet[] = { {} }; +static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { + pkgAcquire *fetcher; + + PyObject *pyFetchProgressInst = NULL; + static char *kwlist[] = {"progress", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"|O",kwlist,&pyFetchProgressInst) == 0) + return 0; + + if (pyFetchProgressInst != NULL) { + // FIXME: memleak? + PyFetchProgress *progress = new PyFetchProgress(); + progress->setCallbackInst(pyFetchProgressInst); + fetcher = new pkgAcquire(progress); + } else { + fetcher = new pkgAcquire(); + } + + CppPyObject *FetcherObj = + CppPyObject_NEW(type, fetcher); + + return FetcherObj; +} + +static const char *doc_PkgAcquire = "Acquire(progress) -> Acquire() object.\n\n" + "Create a new acquire object. The parameter *progress* can be used to\n" + "specify a apt.progress.FetchProgress() object, which will display the\n" + "progress of the fetching."; + PyTypeObject PkgAcquireType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "Acquire", // tp_name + "apt_pkg.Acquire", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -220,7 +248,7 @@ PyTypeObject PkgAcquireType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "pkgAcquire Object", // tp_doc + doc_PkgAcquire, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -230,38 +258,66 @@ PyTypeObject PkgAcquireType = PkgAcquireMethods, // tp_methods 0, // tp_members PkgAcquireGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgAcquireNew, // tp_new }; + PyObject *GetAcquire(PyObject *Self,PyObject *Args) { - pkgAcquire *fetcher; + return PkgAcquireNew(&PkgAcquireType,Args,0); +} - PyObject *pyFetchProgressInst = NULL; - if (PyArg_ParseTuple(Args,"|O",&pyFetchProgressInst) == 0) - return 0; +static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject * kwds) +{ + PyObject *pyfetcher; + char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + int size = 0; + uri = md5 = descr = shortDescr = destDir = destFile = ""; - if (pyFetchProgressInst != NULL) { - // FIXME: memleak? - PyFetchProgress *progress = new PyFetchProgress(); - progress->setCallbackInst(pyFetchProgressInst); - fetcher = new pkgAcquire(progress); - } else { - fetcher = new pkgAcquire(); - } + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortdescr", + "destdir", "destfile", NULL}; - CppPyObject *FetcherObj = - CppPyObject_NEW(&PkgAcquireType, fetcher); + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PkgAcquireType, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, &destFile) == 0) + return 0; - return FetcherObj; + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, + destDir, + destFile); // short-desc + CppPyObject *AcqFileObj = CppPyObject_NEW(type); + AcqFileObj->Object = af; + + return AcqFileObj; } + +static const char *doc_PkgAcquireFile = + "AcquireFile(owner, uri[, md5, size, descr, short_descr, dest_dir," + "dest_file]) -> New AcquireFile() object\n\n" + "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" + "*destdir* OR *destfile* to specify the destination directory/file."; + PyTypeObject PkgAcquireFileType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgAcquireFile", // tp_name + "apt_pkg.AcquireFile", // tp_name sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods @@ -275,6 +331,30 @@ PyTypeObject PkgAcquireFileType = 0, // tp_as_sequence 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + doc_PkgAcquireFile, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgAcquireFileNew, // tp_new }; char *doc_GetPkgAcqFile = @@ -308,6 +388,3 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) return AcqFileObj; } - - - /*}}}*/ diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 0fcf1f29..a54b3922 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -385,14 +385,18 @@ static PyObject *PkgSystemUnLock(PyObject *Self,PyObject *Args) static PyMethodDef methods[] = { // Constructors + #ifdef COMPAT_0_7 {"newConfiguration",newConfiguration,METH_VARARGS,doc_newConfiguration}, + #endif {"init",Init,METH_VARARGS,doc_Init}, {"InitConfig",InitConfig,METH_VARARGS,doc_InitConfig}, {"InitSystem",InitSystem,METH_VARARGS,doc_InitSystem}, // Tag File + #ifdef COMPAT_0_7 {"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection}, {"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile}, + #endif {"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection}, // Locking @@ -433,6 +437,7 @@ static PyMethodDef methods[] = {"StrToTime",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, // Cache + #ifdef COMPAT_0_7 {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, {"GetDepCache",GetDepCache,METH_VARARGS,"GetDepCache(Cache) -> DepCache"}, {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, @@ -452,11 +457,16 @@ static PyMethodDef methods[] = // PkgManager {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager(DepCache) -> PackageManager"}, + #endif {} }; +#define ADDTYPE(mod,name,type) { Py_INCREF(type); \ + PyModule_AddObject(mod,name,(PyObject *)type); } + + #if PY_MAJOR_VERSION >= 3 struct module_state { PyObject *error; @@ -527,6 +537,45 @@ extern "C" void initapt_pkg() Config->Object = _config; PyModule_AddObject(Module,"Config",Config); + // Add our classes. + /* ============================ tag.cc ============================ */ + ADDTYPE(Module,"TagSection",&TagSecType); + ADDTYPE(Module,"TagFile",&TagFileType); + /* ============================ acquire.cc ============================ */ + ADDTYPE(Module,"Acquire",&PkgAcquireType); + ADDTYPE(Module,"AcquireFile",&PkgAcquireFileType); + ADDTYPE(Module,"AcquireItem",&AcquireItemType); // NO __new__() + /* ============================ cache.cc ============================ */ + ADDTYPE(Module,"Cache",&PkgCacheType); + ADDTYPE(Module,"Dependency",&DependencyType); // NO __new__() + ADDTYPE(Module,"Description",&DescriptionType); // NO __new__() + ADDTYPE(Module,"PackageFile",&PackageFileType); // NO __new__() + //ADDTYPE(Module,"PackageList",&PkgListType); // NO __new__(), internal + //ADDTYPE(Module,"DependencyList",&RDepListType); // NO __new__(), internal + ADDTYPE(Module,"Package",&PackageType); // NO __new__() + ADDTYPE(Module,"Version",&VersionType); // NO __new__() + /* ============================ cdrom.cc ============================ */ + ADDTYPE(Module,"Cdrom",&PkgCdromType); + /* ========================= configuration.cc ========================= */ + ADDTYPE(Module,"Configuration",&ConfigurationType); + //ADDTYPE(Module,"ConfigurationSub",&ConfigurationSubType); // NO __new__() + //ADDTYPE(Module,"ConfigurationPtr",&ConfigurationPtrType); // NO __new__() + /* ========================= depcache.cc ========================= */ + ADDTYPE(Module,"ActionGroup",&PkgActionGroupType); + ADDTYPE(Module,"DepCache",&PkgDepCacheType); + ADDTYPE(Module,"ProblemResolver",&PkgProblemResolverType); + /* ========================= indexfile.cc ========================= */ + ADDTYPE(Module,"PackageIndexFile",&PackageIndexFileType); // NO __new__() + /* ========================= metaindex.cc ========================= */ + ADDTYPE(Module,"MetaIndex",&MetaIndexType); // NO __new__() + /* ========================= pkgmanager.cc ========================= */ + ADDTYPE(Module,"PackageManager",&PkgManagerType); + /* ========================= pkgrecords.cc ========================= */ + ADDTYPE(Module,"PackageRecords",&PkgRecordsType); + /* ========================= pkgsrcrecords.cc ========================= */ + ADDTYPE(Module,"SourceRecords",&PkgSrcRecordsType); + /* ========================= sourcelist.cc ========================= */ + ADDTYPE(Module,"SourceList",&PkgSourceListType); // Tag file constants PyModule_AddObject(Module,"RewritePackageOrder", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 424c4788..f7ef63c2 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -80,6 +80,7 @@ PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire extern PyTypeObject AcquireItemType; extern PyTypeObject PkgAcquireType; +extern PyTypeObject PkgAcquireFileType; extern char *doc_GetPkgAcqFile; PyObject *GetAcquire(PyObject *Self,PyObject *Args); PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); diff --git a/python/cache.cc b/python/cache.cc index 92e064b2..0862cd77 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -235,6 +235,61 @@ void PkgCacheFileDealloc(PyObject *Self) CppOwnedDealloc(Self); } +static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *pyCallbackInst = 0; + static char *kwlist[] = {"progress", 0}; + if (PyArg_ParseTupleAndKeywords (Args, kwds, "|O", kwlist, &pyCallbackInst) == 0) + return 0; + + if (_system == 0) { + PyErr_SetString(PyExc_ValueError,"_system not initialized"); + return 0; + } + + pkgCacheFile *Cache = new pkgCacheFile(); + + if(pyCallbackInst != 0) { + // sanity check for the progress object, see #497049 + if (PyObject_HasAttrString(pyCallbackInst, "done") != true) { + PyErr_SetString(PyExc_ValueError, + "OpProgress object must implement done()"); + return 0; + } + if (PyObject_HasAttrString(pyCallbackInst, "update") != true) { + PyErr_SetString(PyExc_ValueError, + "OpProgress object must implement update()"); + return 0; + } + PyOpProgress progress; + progress.setCallbackInst(pyCallbackInst); + if (Cache->Open(progress,false) == false) + return HandleErrors(); + } + else { + OpTextProgress Prog; + if (Cache->Open(Prog,false) == false) + return HandleErrors(); + } + + CppOwnedPyObject *CacheFileObj = + CppOwnedPyObject_NEW(0,&PkgCacheFileType, Cache); + + CppOwnedPyObject *CacheObj = + CppOwnedPyObject_NEW(CacheFileObj,type, + (pkgCache *)(*Cache)); + + //Py_DECREF(CacheFileObj); + return CacheObj; +} + +static const char *doc_PkgCache = "Cache([progress]) -> Cache() object.\n\n" + "The cache provides access to the packages and other stuff.\n\n" + "The optional parameter *progress* can be used to specify an \n" + "apt.progress.OpProgress() object (or similar) which displays\n" + "the opening progress.\n\n" + "If not specified, the progress is displayed in simple text form."; + static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { @@ -242,7 +297,7 @@ PyTypeObject PkgCacheType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache", // tp_name + "apt_pkg.Cache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -262,7 +317,7 @@ PyTypeObject PkgCacheType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT , // tp_flags - "Cache Object", // tp_doc + doc_PkgCache, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -272,6 +327,14 @@ PyTypeObject PkgCacheType = PkgCacheMethods, // tp_methods 0, // tp_members PkgCacheGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgCacheNew, // tp_new }; /*}}}*/ // PkgCacheFile Class /*{{{*/ @@ -352,7 +415,7 @@ PyTypeObject PkgListType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::PkgIterator", // tp_name + "apt_pkg.PackageList", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -452,7 +515,7 @@ PyTypeObject PackageType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::Package", // tp_name + "apt_pkg.Package", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -539,7 +602,7 @@ PyTypeObject DescriptionType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::DescIterator", // tp_name + "apt_pkg.Description", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -743,7 +806,7 @@ PyTypeObject VersionType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::VerIterator", // tp_name + "apt_pkg.Version", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -820,7 +883,7 @@ PyTypeObject PackageFileType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::PkgFileIterator", // tp_name + "apt_pkg.PackageFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -968,7 +1031,7 @@ PyTypeObject DependencyType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::DepIterator", // tp_name + "apt_pkg.Dependency", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -1056,7 +1119,7 @@ PyTypeObject RDepListType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::DepIterator", // tp_name + "apt_pkg.DependencyList", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -1078,47 +1141,5 @@ PyTypeObject RDepListType = PyObject *TmpGetCache(PyObject *Self,PyObject *Args) { - PyObject *pyCallbackInst = 0; - if (PyArg_ParseTuple(Args, "|O", &pyCallbackInst) == 0) - return 0; - - if (_system == 0) { - PyErr_SetString(PyExc_ValueError,"_system not initialized"); - return 0; - } - - pkgCacheFile *Cache = new pkgCacheFile(); - - if(pyCallbackInst != 0) { - // sanity check for the progress object, see #497049 - if (PyObject_HasAttrString(pyCallbackInst, "done") != true) { - PyErr_SetString(PyExc_ValueError, - "OpProgress object must implement done()"); - return 0; - } - if (PyObject_HasAttrString(pyCallbackInst, "update") != true) { - PyErr_SetString(PyExc_ValueError, - "OpProgress object must implement update()"); - return 0; - } - PyOpProgress progress; - progress.setCallbackInst(pyCallbackInst); - if (Cache->Open(progress,false) == false) - return HandleErrors(); - } - else { - OpTextProgress Prog; - if (Cache->Open(Prog,false) == false) - return HandleErrors(); - } - - CppOwnedPyObject *CacheFileObj = - CppOwnedPyObject_NEW(0,&PkgCacheFileType, Cache); - - CppOwnedPyObject *CacheObj = - CppOwnedPyObject_NEW(CacheFileObj,&PkgCacheType, - (pkgCache *)(*Cache)); - - //Py_DECREF(CacheFileObj); - return CacheObj; + return PkgCacheNew(&PkgCacheType,Args,0); } diff --git a/python/cdrom.cc b/python/cdrom.cc index b3a38438..bf94a390 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -58,19 +58,34 @@ static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) static PyMethodDef PkgCdromMethods[] = { - {"Add",PkgCdromAdd,METH_VARARGS,"Add a cdrom"}, - {"Ident",PkgCdromIdent,METH_VARARGS,"Ident a cdrom"}, + {"Add",PkgCdromAdd,METH_VARARGS,"Add(progress) -> Add a cdrom"}, + {"Ident",PkgCdromIdent,METH_VARARGS,"Ident(progress) -> Ident a cdrom"}, {} }; +static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + pkgCdrom *cdrom = new pkgCdrom(); + + static char *kwlist[] = {}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"",kwlist) == 0) + return 0; + + CppOwnedPyObject *CdromObj = + CppOwnedPyObject_NEW(0,type, *cdrom); + + return CdromObj; +} + + PyTypeObject PkgCdromType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "Cdrom", // tp_name + "apt_pkg.Cdrom", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -98,16 +113,21 @@ PyTypeObject PkgCdromType = 0, // tp_iter 0, // tp_iternext PkgCdromMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgCdromNew, // tp_new }; PyObject *GetCdrom(PyObject *Self,PyObject *Args) { - pkgCdrom *cdrom = new pkgCdrom(); - - CppOwnedPyObject *CdromObj = - CppOwnedPyObject_NEW(0,&PkgCdromType, *cdrom); - - return CdromObj; + return PkgCdromNew(&PkgCdromType,Args,0); } diff --git a/python/configuration.cc b/python/configuration.cc index eaac48ec..abbed6d9 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -475,6 +475,13 @@ static PyMethodDef CnfMethods[] = {} }; +static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {}; + if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) + return 0; + return CppPyObject_NEW(type); +} + // Type for a Normal Configuration object static PySequenceMethods ConfigurationSeq = {0,0,0,0,0,0,0,CnfContains,0,0}; static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; @@ -484,7 +491,7 @@ PyTypeObject ConfigurationType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "Configuration", // tp_name + "apt_pkg.Configuration", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -512,6 +519,16 @@ PyTypeObject ConfigurationType = 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + CnfNew, // tp_new }; PyTypeObject ConfigurationPtrType = @@ -520,7 +537,7 @@ PyTypeObject ConfigurationPtrType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "ConfigurationPtr", // tp_name + "apt_pkg.ConfigurationPtr", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -556,7 +573,7 @@ PyTypeObject ConfigurationSubType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "ConfigurationSub", // tp_name + "apt_pkg.ConfigurationSub", // tp_name sizeof(SubConfiguration), // tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/depcache.cc b/python/depcache.cc index 1c9eeff7..0cadee64 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -591,13 +591,39 @@ static PyGetSetDef PkgDepCacheGetSet[] = { {} }; +static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + static char *kwlist[] = {"cache", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + &Owner) == 0) + return 0; + + + // the owner of the Python cache object is a cachefile object, get it + PyObject *CacheFilePy = GetOwner(Owner); + // get the pkgCacheFile from the cachefile + pkgCacheFile *CacheF = GetCpp(CacheFilePy); + // and now the depcache + pkgDepCache *depcache = (pkgDepCache *)(*CacheF); + + CppOwnedPyObject *DepCachePyObj; + DepCachePyObj = CppOwnedPyObject_NEW(Owner,type,depcache); + HandleErrors(DepCachePyObj); + + return DepCachePyObj; +} + +static const char *doc_PkgDepCache = "DepCache(cache) -> DepCache() object\n\n" + "A DepCache() holds extra information on the state of the packages.\n\n" + "The parameter *cache* refers to an apt_pkg.Cache() object."; PyTypeObject PkgDepCacheType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgDepCache", // tp_name + "apt_pkg.DepCache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -617,7 +643,7 @@ PyTypeObject PkgDepCacheType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "pkgDepCache Object", // tp_doc + doc_PkgDepCache, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -627,30 +653,20 @@ PyTypeObject PkgDepCacheType = PkgDepCacheMethods, // tp_methods 0, // tp_members PkgDepCacheGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgDepCacheNew, // tp_new }; PyObject *GetDepCache(PyObject *Self,PyObject *Args) { - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) - return 0; - - - // the owner of the Python cache object is a cachefile object, get it - PyObject *CacheFilePy = GetOwner(Owner); - // get the pkgCacheFile from the cachefile - pkgCacheFile *CacheF = GetCpp(CacheFilePy); - // and now the depcache - pkgDepCache *depcache = (pkgDepCache *)(*CacheF); - - CppOwnedPyObject *DepCachePyObj; - DepCachePyObj = CppOwnedPyObject_NEW(Owner, - &PkgDepCacheType, - depcache); - HandleErrors(DepCachePyObj); - - return DepCachePyObj; + return PkgDepCacheNew(&PkgDepCacheType,Args,0); } @@ -661,26 +677,28 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) // pkgProblemResolver Class /*{{{*/ // --------------------------------------------------------------------- - - -PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) +static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) + static char *kwlist[] = {"depcache",0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + &Owner) == 0) return 0; pkgDepCache *depcache = GetCpp(Owner); pkgProblemResolver *fixer = new pkgProblemResolver(depcache); CppOwnedPyObject *PkgProblemResolverPyObj; PkgProblemResolverPyObj = CppOwnedPyObject_NEW(Owner, - &PkgProblemResolverType, + type, fixer); HandleErrors(PkgProblemResolverPyObj); return PkgProblemResolverPyObj; - } +PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) { + return PkgProblemResolverNew(&PkgProblemResolverType,Args,0); +} static PyObject *PkgProblemResolverResolve(PyObject *Self,PyObject *Args) { @@ -778,7 +796,7 @@ PyTypeObject PkgProblemResolverType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgProblemResolver", // tp_name + "apt_pkg.ProblemResolver", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -806,6 +824,16 @@ PyTypeObject PkgProblemResolverType = 0, // tp_iter 0, // tp_iternext PkgProblemResolverMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgProblemResolverNew, // tp_new }; /*}}}*/ @@ -830,13 +858,40 @@ static PyMethodDef PkgActionGroupMethods[] = {} }; +static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + static char *kwlist[] = {"depcache", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + &Owner) == 0) + return 0; + + pkgDepCache *depcache = GetCpp(Owner); + pkgDepCache::ActionGroup *group = new pkgDepCache::ActionGroup(*depcache); + CppOwnedPyObject *PkgActionGroupPyObj; + PkgActionGroupPyObj = CppOwnedPyObject_NEW(Owner, + type, + group); + HandleErrors(PkgActionGroupPyObj); + + return PkgActionGroupPyObj; + +} + +static const char *doc_PkgActionGroup = "ActionGroup(depcache)\n\n" + "Create a new ActionGroup() object. ActionGroups disable certain cleanup\n" + "actions, so modifying many packages is much faster.\n\n" + "Creating an ActionGroup() makes it active, use release() to disable it\n" + "again.\n\n" + "The parameter *depcache* refers to an apt_pkg.DepCache() object."; + PyTypeObject PkgActionGroupType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgActionGroup", // tp_name + "apt_pkg.ActionGroup", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -856,7 +911,7 @@ PyTypeObject PkgActionGroupType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "ActionGroup Object", // tp_doc + doc_PkgActionGroup, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -864,24 +919,21 @@ PyTypeObject PkgActionGroupType = 0, // tp_iter 0, // tp_iternext PkgActionGroupMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgActionGroupNew, // tp_new }; PyObject *GetPkgActionGroup(PyObject *Self,PyObject *Args) { - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) - return 0; - - pkgDepCache *depcache = GetCpp(Owner); - pkgDepCache::ActionGroup *group = new pkgDepCache::ActionGroup(*depcache); - CppOwnedPyObject *PkgActionGroupPyObj; - PkgActionGroupPyObj = CppOwnedPyObject_NEW(Owner, - &PkgActionGroupType, - group); - HandleErrors(PkgActionGroupPyObj); - - return PkgActionGroupPyObj; - + return PkgActionGroupNew(&PkgActionGroupType,Args,0); } diff --git a/python/indexfile.cc b/python/indexfile.cc index bb40cdd0..600dc853 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -84,7 +84,7 @@ PyTypeObject PackageIndexFileType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgIndexFile", // tp_name + "apt_pkg.PackageIndexFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/metaindex.cc b/python/metaindex.cc index cbaeafbd..557aacd8 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -62,7 +62,7 @@ PyTypeObject MetaIndexType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "metaIndex", // tp_name + "apt_pkg.MetaIndex", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 8f56cddc..781acc8b 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -15,8 +15,32 @@ #include #include #include +#include +#include + #include +static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + char *kwlist[] = {"depcache",0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + &Owner) == 0) + return 0; + + pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); + + CppPyObject *PkgManagerObj = + CppPyObject_NEW(type,pm); + + return PkgManagerObj; +} + +PyObject *GetPkgManager(PyObject *Self,PyObject *Args) +{ + return PkgManagerNew(&PkgManagerType,Args,0); +} + static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) { @@ -98,7 +122,7 @@ PyTypeObject PkgManagerType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "PackageManager", // tp_name + "apt_pkg.PackageManager", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -128,26 +152,16 @@ PyTypeObject PkgManagerType = PkgManagerMethods, // tp_methods 0, // tp_members PkgManagerGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgManagerNew, // tp_new }; -#include -#include - -PyObject *GetPkgManager(PyObject *Self,PyObject *Args) -{ - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) - return 0; - - pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); - - CppPyObject *PkgManagerObj = - CppPyObject_NEW(&PkgManagerType,pm); - - return PkgManagerObj; -} - - /*}}}*/ diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 978de6b7..1cccfce2 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -132,13 +132,25 @@ static PyGetSetDef PkgRecordsGetSet[] = { {} }; +static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + char *kwlist[] = {"cache",0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + &Owner) == 0) + return 0; + + return HandleErrors(CppOwnedPyObject_NEW(Owner,type, + GetCpp(Owner))); +} + PyTypeObject PkgRecordsType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgRecords", // tp_name + "apt_pkg.PackageRecords", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -168,17 +180,22 @@ PyTypeObject PkgRecordsType = PkgRecordsMethods, // tp_methods 0, // tp_members PkgRecordsGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgRecordsNew, // tp_new }; /*}}}*/ + + PyObject *GetPkgRecords(PyObject *Self,PyObject *Args) { - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) - return 0; - - return HandleErrors(CppOwnedPyObject_NEW(Owner,&PkgRecordsType, - GetCpp(Owner))); + return PkgRecordsNew(&PkgRecordsType,Args,0); } diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 97667d7a..8b4dce3e 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -180,13 +180,21 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { {} }; +static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kwds) { + char *kwlist[] = {0}; + if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) + return 0; + + return HandleErrors(CppPyObject_NEW(type)); +} + PyTypeObject PkgSrcRecordsType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgSrcRecords", // tp_name + "apt_pkg.SourceRecords", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -216,6 +224,14 @@ PyTypeObject PkgSrcRecordsType = PkgSrcRecordsMethods, // tp_methods 0, // tp_members PkgSrcRecordsGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgSrcRecordsNew, // tp_new }; /*}}}*/ diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 48b3b7c8..15311e94 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -97,13 +97,21 @@ static PyGetSetDef PkgSourceListGetSet[] = { {} }; +static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kwds) +{ + char *kwlist[] = {0}; + if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) + return 0; + return CppPyObject_NEW(type,new pkgSourceList()); +} + PyTypeObject PkgSourceListType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgSourceList", // tp_name + "apt_pkg.SourceList", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -133,6 +141,14 @@ PyTypeObject PkgSourceListType = PkgSourceListMethods, // tp_methods 0, // tp_members PkgSourceListGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgSourceListNew, // tp_new }; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) diff --git a/python/tag.cc b/python/tag.cc index 18d08580..007a6122 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -239,15 +239,14 @@ static PyObject *TagFileJump(PyObject *Self,PyObject *Args) /*}}}*/ // ParseSection - Parse a single section from a tag file /*{{{*/ // --------------------------------------------------------------------- -char *doc_ParseSection ="ParseSection(Text) -> SectionObject"; -PyObject *ParseSection(PyObject *self,PyObject *Args) -{ +static PyObject *TagSecNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { char *Data; - if (PyArg_ParseTuple(Args,"s",&Data) == 0) + static char *kwlist[] = {"text", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"s",kwlist,&Data) == 0) return 0; // Create the object.. - TagSecData *New = PyObject_NEW(TagSecData,&TagSecType); + TagSecData *New = PyObject_NEW(TagSecData,type); new (&New->Object) pkgTagSection(); New->Data = new char[strlen(Data)+2]; snprintf(New->Data,strlen(Data)+2,"%s\n",Data); @@ -264,21 +263,28 @@ PyObject *ParseSection(PyObject *self,PyObject *Args) return New; } + +char *doc_ParseSection ="ParseSection(Text) -> TagSection() object. Deprecated."; +PyObject *ParseSection(PyObject *self,PyObject *Args) +{ + return TagSecNew(&TagSecType,Args,0); +} /*}}}*/ // ParseTagFile - Parse a tagd file /*{{{*/ // --------------------------------------------------------------------- /* This constructs the parser state. */ -char *doc_ParseTagFile = "ParseTagFile(File) -> TagFile"; -PyObject *ParseTagFile(PyObject *self,PyObject *Args) + +static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *File; - if (PyArg_ParseTuple(Args,"O",&File) == 0) + static char *kwlist[] = {"file", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O",kwlist,&File) == 0) return 0; int fileno = PyObject_AsFileDescriptor(File); if (fileno == -1) return 0; - TagFileData *New = PyObject_NEW(TagFileData,&TagFileType); + TagFileData *New = PyObject_NEW(TagFileData,type); new (&New->Fd) FileFd(fileno,false); New->File = File; Py_INCREF(New->File); @@ -290,6 +296,10 @@ PyObject *ParseTagFile(PyObject *self,PyObject *Args) New->Section->Data = 0; return HandleErrors(New); +} +char *doc_ParseTagFile = "ParseTagFile(File) -> TagFile() object. Deprecated."; +PyObject *ParseTagFile(PyObject *self,PyObject *Args) { + return TagFileNew(&TagFileType,Args,0); } /*}}}*/ // RewriteSection - Rewrite a section.. /*{{{*/ @@ -381,13 +391,20 @@ static PyMethodDef TagSecMethods[] = PySequenceMethods TagSecSeqMeth = {0,0,0,0,0,0,0,TagSecContains,0,0}; PyMappingMethods TagSecMapMeth = {TagSecLength,TagSecMap,0}; + + +static const char *doc_TagSec = "TagSection(text) -> Create a new object.\n\n" + "TagSection() objects provide methods to access rfc822-style formatted\n" + "header sections, like those in debian/control or Packages files.\n\n" + "TagSection() behave like read-only dictionaries and also provide access\n" + "to the functions provided by the C++ class (e.g. Find)"; PyTypeObject TagSecType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "TagSection", // tp_name + "apt_pkg.TagSection", // tp_name sizeof(TagSecData), // tp_basicsize 0, // tp_itemsize // Methods @@ -407,14 +424,24 @@ PyTypeObject TagSecType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "TagSection Object", // tp_doc + doc_TagSec, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter 0, // tp_iternext - TagSecMethods // tp_methods + TagSecMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + TagSecNew, // tp_new }; // Method table for the Tag File object @@ -440,6 +467,15 @@ static PyGetSetDef TagFileGetSet[] = { {} }; +static const char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" + "TagFile() objects provide access to debian control files, which consists\n" + "of multiple RFC822-like formatted sections.\n\n" + "A file may consists of multiple sections, and you can use Step() to move\n" + "forward. The current TagSection() is available via the attribute section" + ".\n\n" + "The parameter *file* refers to an object providing a fileno() method or\n" + "a file descriptor (an integer)"; + // Type for a Tag File PyTypeObject TagFileType = { @@ -447,7 +483,7 @@ PyTypeObject TagFileType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "TagFile", // tp_name + "apt_pkg.TagFile", // tp_name sizeof(TagFileData), // tp_basicsize 0, // tp_itemsize // Methods @@ -467,7 +503,7 @@ PyTypeObject TagFileType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "TagFile Object", // tp_doc + doc_TagFile, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -476,5 +512,14 @@ PyTypeObject TagFileType = 0, // tp_iternext TagFileMethods, // tp_methods 0, // tp_members - TagFileGetSet // tp_getset + TagFileGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + TagFileNew, // tp_new + }; -- cgit v1.2.3 From 7051066cf258caa2a3fd45271faa3d46b8a6d98a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 3 Jun 2009 17:27:33 +0200 Subject: python/: Convert most names to PEP8 naming conventions (except Version,PackageFile,MetaIndex). On our way to close Bug#481061, this converts almost all names to PEP 8 naming conventions. Missing are now apt_pkg.Version, apt_pkg.PackageFile, apt_pkg.MetaIndex and apt.progress.*. In case of the missing apt_pkg classes, they are not converted yet because they do not use getset descriptors yet. apt.progress.* has not been converted yet because the extension interacts with it, and we first need to modify the extension to recognize the new names, as well as the old names (old applications shouldn't break). --- python/acquire.cc | 29 +++++++++++++++ python/apt_instmodule.cc | 21 +++++++---- python/apt_pkgmodule.cc | 94 ++++++++++++++++++++++++++++++++++++++++++++++-- python/cache.cc | 49 ++++++++++++++++++++++++- python/cdrom.cc | 4 +++ python/configuration.cc | 21 +++++++++-- python/depcache.cc | 57 ++++++++++++++++++++++++----- python/indexfile.cc | 11 ++++++ python/pkgmanager.cc | 10 ++++++ python/pkgrecords.cc | 17 +++++++++ python/pkgsrcrecords.cc | 15 ++++++++ python/sourcelist.cc | 8 +++++ python/tag.cc | 15 ++++++++ 13 files changed, 329 insertions(+), 22 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index ccd3a479..6cb2130c 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -38,6 +38,21 @@ MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthE #undef MkGet static PyGetSetDef AcquireItemGetSet[] = { + {"complete",AcquireItemGetComplete}, + {"descuri",AcquireItemGetDescURI}, + {"destfile",AcquireItemGetDestFile}, + {"errortext",AcquireItemGetErrorText}, + {"filesize",AcquireItemGetFileSize}, + {"is",AcquireItemGetID}, + {"is_trusted",AcquireItemGetIsTrusted}, + {"local",AcquireItemGetLocal}, + {"status",AcquireItemGetStatus}, + {"stat_idle",AcquireItemGetStatIdle}, + {"stat_fetching",AcquireItemGetStatFetching}, + {"stat_done",AcquireItemGetStatDone}, + {"stat_error",AcquireItemGetStatError}, + {"stat_auth_error",AcquireItemGetStatAuthError}, +#ifdef COMPAT_0_7 {"Complete",AcquireItemGetComplete}, {"DescURI",AcquireItemGetDescURI}, {"DestFile",AcquireItemGetDestFile}, @@ -52,6 +67,7 @@ static PyGetSetDef AcquireItemGetSet[] = { {"StatDone",AcquireItemGetStatDone}, {"StatError",AcquireItemGetStatError}, {"StatAuthError",AcquireItemGetStatAuthError}, +#endif {} }; @@ -140,8 +156,12 @@ static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) static PyMethodDef PkgAcquireMethods[] = { + {"run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, + {"shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, + #ifdef COMPAT_0_7 {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, + #endif {} }; @@ -184,6 +204,14 @@ static PyObject *PkgAcquireGetResultCancelled(PyObject *Self,void*) { } static PyGetSetDef PkgAcquireGetSet[] = { + {"fetch_needed",PkgAcquireGetFetchNeeded}, + {"items",PkgAcquireGetItems}, + {"partial_present",PkgAcquireGetPartialPresent}, + {"result_cancelled",PkgAcquireGetResultCancelled}, + {"result_continue",PkgAcquireGetResultContinue}, + {"result_failed",PkgAcquireGetResultFailed}, + {"total_needed",PkgAcquireGetTotalNeeded}, + #ifdef COMPAT_0_7 {"FetchNeeded",PkgAcquireGetFetchNeeded}, {"Items",PkgAcquireGetItems}, {"PartialPresent",PkgAcquireGetPartialPresent}, @@ -191,6 +219,7 @@ static PyGetSetDef PkgAcquireGetSet[] = { {"ResultContinue",PkgAcquireGetResultContinue}, {"ResultFailed",PkgAcquireGetResultFailed}, {"TotalNeeded",PkgAcquireGetTotalNeeded}, + #endif {} }; diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index 09e3937e..84479fcb 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -29,7 +29,7 @@ expose the full range of the apt-inst .deb processing will join it some day. */ static char *doc_debExtractControl = -"debExtractControl(File[,Member]) -> String\n" +"deb_extract_control(file[,member]) -> String\n" "Returns the indicated file from the control tar. The default is 'control'\n"; static PyObject *debExtractControl(PyObject *Self,PyObject *Args) { @@ -72,7 +72,7 @@ static PyObject *debExtractControl(PyObject *Self,PyObject *Args) // debExtractArchive - Exctract the archive /*{{{*/ // --------------------------------------------------------------------- static char *doc_debExtractArchive = -"debExtractArchve(File,rootdir) -> Bool\n" +"deb_extract_archive(File,rootdir) -> Bool\n" "Extracts the Archive into the given root dir"; static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) { @@ -118,7 +118,7 @@ static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) // arFindMember - Find member in AR archive /*{{{*/ // --------------------------------------------------------------------- static char *doc_arCheckMember = -"arCheckMember(File, membername) -> Bool\n"; +"ar_check_member(file, membername) -> Bool\n"; static PyObject *arCheckMember(PyObject *Self,PyObject *Args) { char *Member = NULL; @@ -149,16 +149,23 @@ static PyObject *arCheckMember(PyObject *Self,PyObject *Args) static PyMethodDef methods[] = { // access to ar files - {"arCheckMember", arCheckMember, METH_VARARGS, doc_arCheckMember}, + {"ar_check_member", arCheckMember, METH_VARARGS, doc_arCheckMember}, // access to deb files - {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, - {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, + {"deb_extract_control",debExtractControl,METH_VARARGS,doc_debExtractControl}, + {"deb_extract_archive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, // access to tar streams + {"tar_extract",tarExtract,METH_VARARGS,doc_tarExtract}, + {"deb_extract",debExtract,METH_VARARGS,doc_debExtract}, + +#ifdef COMPAT_0_7 + {"arCheckMember", arCheckMember, METH_VARARGS, doc_arCheckMember}, + {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, + {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract}, {"debExtract",debExtract,METH_VARARGS,doc_debExtract}, - +#endif {} }; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index bdea5fae..ddd6d38b 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -389,35 +389,60 @@ static PyMethodDef methods[] = {"newConfiguration",newConfiguration,METH_VARARGS,doc_newConfiguration}, #endif {"init",Init,METH_VARARGS,doc_Init}, + {"init_config",InitConfig,METH_VARARGS,doc_InitConfig}, + {"init_system",InitSystem,METH_VARARGS,doc_InitSystem}, + #ifdef COMPAT_0_7 {"InitConfig",InitConfig,METH_VARARGS,doc_InitConfig}, {"InitSystem",InitSystem,METH_VARARGS,doc_InitSystem}, + #endif // Tag File #ifdef COMPAT_0_7 {"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection}, {"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile}, - #endif {"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection}, + #endif + {"rewrite_section",RewriteSection,METH_VARARGS,doc_RewriteSection}, // Locking + {"get_lock",GetLock,METH_VARARGS,doc_GetLock}, + {"pkgsystem_lock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, + {"pkgsystem_unlock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, + #ifdef COMPAT_0_7 {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, {"PkgSystemUnLock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, + #endif // Command line + {"read_configfile",LoadConfig,METH_VARARGS,doc_LoadConfig}, + {"read_configdir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, + {"read_configfile_isc",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, + {"parse_commandline",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, + #ifdef COMPAT_0_7 {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, {"ReadConfigFileISC",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, {"ParseCommandLine",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, + #endif // Versioning + {"version_compare",VersionCompare,METH_VARARGS,doc_VersionCompare}, + {"check_dep",CheckDep,METH_VARARGS,doc_CheckDep}, + {"upstream_version",UpstreamVersion,METH_VARARGS,doc_UpstreamVersion}, + #ifdef COMPAT_0_7 {"VersionCompare",VersionCompare,METH_VARARGS,doc_VersionCompare}, {"CheckDep",CheckDep,METH_VARARGS,doc_CheckDep}, {"UpstreamVersion",UpstreamVersion,METH_VARARGS,doc_UpstreamVersion}, + #endif // Depends + {"parse_depends",ParseDepends,METH_VARARGS,doc_ParseDepends}, + {"parse_srcdepends",ParseSrcDepends,METH_VARARGS,doc_ParseDepends}, + #ifdef COMPAT_0_7 {"ParseDepends",ParseDepends,METH_VARARGS,doc_ParseDepends}, {"ParseSrcDepends",ParseSrcDepends,METH_VARARGS,doc_ParseDepends}, + #endif // Stuff {"md5sum",md5sum,METH_VARARGS,doc_md5sum}, @@ -425,6 +450,17 @@ static PyMethodDef methods[] = {"sha256sum",sha256sum,METH_VARARGS,doc_sha256sum}, // Strings + {"check_domainlist",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, + {"quote_string",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, + {"dequote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, + {"size_to_str",StrSizeToStr,METH_VARARGS,"SizeToStr(int) -> String"}, + {"time_to_str",StrTimeToStr,METH_VARARGS,"TimeToStr(int) -> String"}, + {"uri_to_filename",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, + {"base64_encode",StrBase64Encode,METH_VARARGS,"Base64Encode(String) -> String"}, + {"string_to_bool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, + {"time_rfc1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, + {"str_to_time",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, + #ifdef COMPAT_0_7 {"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, {"QuoteString",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, {"DeQuoteString",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, @@ -435,6 +471,7 @@ static PyMethodDef methods[] = {"StringToBool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, {"TimeRFC1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, {"StrToTime",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, + #endif // Cache #ifdef COMPAT_0_7 @@ -535,7 +572,10 @@ extern "C" void initapt_pkg() // Global variable linked to the global configuration class CppPyObject *Config = CppPyObject_NEW(&ConfigurationPtrType); Config->Object = _config; + PyModule_AddObject(Module,"config",Config); + #ifdef COMPAT_0_7 PyModule_AddObject(Module,"Config",Config); + #endif // Add our classes. /* ============================ tag.cc ============================ */ @@ -577,20 +617,40 @@ extern "C" void initapt_pkg() /* ========================= sourcelist.cc ========================= */ ADDTYPE(Module,"SourceList",&PkgSourceListType); // Tag file constants + PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", + CharCharToList(TFRewritePackageOrder)); + + PyModule_AddObject(Module,"REWRITE_SOURCE_ORDER", + CharCharToList(TFRewriteSourceOrder)); +#ifdef COMPAT_0_7 PyModule_AddObject(Module,"RewritePackageOrder", CharCharToList(TFRewritePackageOrder)); PyModule_AddObject(Module,"RewriteSourceOrder", CharCharToList(TFRewriteSourceOrder)); +#endif // Version.. + PyModule_AddStringConstant(Module,"VERSION",(char *)pkgVersion); + PyModule_AddStringConstant(Module,"LIB_VERSION",(char *)pkgLibVersion); + PyModule_AddStringConstant(Module,"DATE",__DATE__); + PyModule_AddStringConstant(Module,"TIME",__TIME__); +#ifdef COMPAT_0_7 PyModule_AddStringConstant(Module,"Version",(char *)pkgVersion); PyModule_AddStringConstant(Module,"LibVersion",(char *)pkgLibVersion); PyModule_AddStringConstant(Module,"Date",__DATE__); PyModule_AddStringConstant(Module,"Time",__TIME__); +#endif // My constants - + PyModule_AddIntConstant(Module,"DEP_DEPENDS",pkgCache::Dep::Depends); + PyModule_AddIntConstant(Module,"DEP_PREDEPENDS",pkgCache::Dep::PreDepends); + PyModule_AddIntConstant(Module,"DEP_SUGGESTS",pkgCache::Dep::Suggests); + PyModule_AddIntConstant(Module,"DEP_RECOMMENDS",pkgCache::Dep::Recommends); + PyModule_AddIntConstant(Module,"DEP_CONFLICTS",pkgCache::Dep::Conflicts); + PyModule_AddIntConstant(Module,"DEP_REPLACES",pkgCache::Dep::Replaces); + PyModule_AddIntConstant(Module,"DEP_OBSOLTES",pkgCache::Dep::Obsoletes); +#ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"DepDepends",pkgCache::Dep::Depends); PyModule_AddIntConstant(Module,"DepPreDepends",pkgCache::Dep::PreDepends); PyModule_AddIntConstant(Module,"DepSuggests",pkgCache::Dep::Suggests); @@ -598,13 +658,40 @@ extern "C" void initapt_pkg() PyModule_AddIntConstant(Module,"DepConflicts",pkgCache::Dep::Conflicts); PyModule_AddIntConstant(Module,"DepReplaces",pkgCache::Dep::Replaces); PyModule_AddIntConstant(Module,"DepObsoletes",pkgCache::Dep::Obsoletes); +#endif + PyModule_AddIntConstant(Module,"PRI_IMPORTANT",pkgCache::State::Important); + PyModule_AddIntConstant(Module,"PRI_REQUIRED",pkgCache::State::Required); + PyModule_AddIntConstant(Module,"PRI_STANDARD",pkgCache::State::Standard); + PyModule_AddIntConstant(Module,"PRI_OPTIONAL",pkgCache::State::Optional); + PyModule_AddIntConstant(Module,"PRI_EXTRA",pkgCache::State::Extra); +#ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"PriImportant",pkgCache::State::Important); PyModule_AddIntConstant(Module,"PriRequired",pkgCache::State::Required); PyModule_AddIntConstant(Module,"PriStandard",pkgCache::State::Standard); PyModule_AddIntConstant(Module,"PriOptional",pkgCache::State::Optional); PyModule_AddIntConstant(Module,"PriExtra",pkgCache::State::Extra); - +#endif + // CurState + PyModule_AddIntConstant(Module,"STATE_NOTINSTALLED",pkgCache::State::NotInstalled); + PyModule_AddIntConstant(Module,"STATE_UNPACKED",pkgCache::State::UnPacked); + PyModule_AddIntConstant(Module,"STATE_HALFCONFIGURED",pkgCache::State::HalfConfigured); + PyModule_AddIntConstant(Module,"STATE_HALFINSTALLED",pkgCache::State::HalfInstalled); + PyModule_AddIntConstant(Module,"STATE_CONFIGFILES",pkgCache::State::ConfigFiles); + PyModule_AddIntConstant(Module,"STATE_INSTALLED",pkgCache::State::Installed); + // SelState + PyModule_AddIntConstant(Module,"STATE_UNKNOWN",pkgCache::State::Unknown); + PyModule_AddIntConstant(Module,"STATE_INSTALL",pkgCache::State::Install); + PyModule_AddIntConstant(Module,"STATE_HOLD",pkgCache::State::Hold); + PyModule_AddIntConstant(Module,"STATE_DEINSTALL",pkgCache::State::DeInstall); + PyModule_AddIntConstant(Module,"STATE_PURGE",pkgCache::State::Purge); + // InstState + PyModule_AddIntConstant(Module,"STATE_OK",pkgCache::State::Ok); + PyModule_AddIntConstant(Module,"STATE_REINSTREQ",pkgCache::State::ReInstReq); + PyModule_AddIntConstant(Module,"STATE_HOLD",pkgCache::State::Hold); + PyModule_AddIntConstant(Module,"STATE_HOLD_REINSTREQ",pkgCache::State::HoldReInstReq); + +#ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"CurStateNotInstalled",pkgCache::State::NotInstalled); PyModule_AddIntConstant(Module,"CurStateUnPacked",pkgCache::State::UnPacked); PyModule_AddIntConstant(Module,"CurStateHalfConfigured",pkgCache::State::HalfConfigured); @@ -622,6 +709,7 @@ extern "C" void initapt_pkg() PyModule_AddIntConstant(Module,"InstStateReInstReq",pkgCache::State::ReInstReq); PyModule_AddIntConstant(Module,"InstStateHold",pkgCache::State::Hold); PyModule_AddIntConstant(Module,"InstStateHoldReInstReq",pkgCache::State::HoldReInstReq); +#endif #ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"_COMPAT_0_7",1); diff --git a/python/cache.cc b/python/cache.cc index f545a605..644646a1 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -136,9 +136,14 @@ static PyObject *PkgCacheOpen(PyObject *Self,PyObject *Args) static PyMethodDef PkgCacheMethods[] = { + {"update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, + {"open", PkgCacheOpen, METH_VARARGS,"Open the cache"}, + {"close", PkgCacheClose, METH_VARARGS,"Close the cache"}, +#ifdef COMPAT_0_7 {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, {"Open", PkgCacheOpen, METH_VARARGS,"Open the cache"}, {"Close", PkgCacheClose, METH_VARARGS,"Close the cache"}, +#endif {} }; @@ -190,6 +195,15 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { } static PyGetSetDef PkgCacheGetSet[] = { + {"depends_count",PkgCacheGetDependsCount}, + {"filelist",PkgCacheGetFileList}, + {"package_count",PkgCacheGetPackageCount}, + {"packagefile_count",PkgCacheGetPackageFileCount}, + {"packages",PkgCacheGetPackages}, + {"provides_count",PkgCacheGetProvidesCount}, + {"verfile_count",PkgCacheGetVerFileCount}, + {"version_count",PkgCacheGetVersionCount}, +#ifdef COMPAT_0_7 {"DependsCount",PkgCacheGetDependsCount}, {"FileList",PkgCacheGetFileList}, {"PackageCount",PkgCacheGetPackageCount}, @@ -198,6 +212,7 @@ static PyGetSetDef PkgCacheGetSet[] = { {"ProvidesCount",PkgCacheGetProvidesCount}, {"VerFileCount",PkgCacheGetVerFileCount}, {"VersionCount",PkgCacheGetVersionCount}, +#endif {} }; @@ -482,6 +497,20 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) } static PyGetSetDef PackageGetSet[] = { + {"name",PackageGetName}, + {"section",PackageGetSection}, + {"revdependslist",PackageGetRevDependsList}, + {"provideslist",PackageGetProvidesList}, + {"selected_state",PackageGetSelectedState}, + {"inst_state",PackageGetInstState}, + {"current_state",PackageGetCurrentState}, + {"id",PackageGetID}, + {"auto",PackageGetAuto}, + {"essential",PackageGetEssential}, + {"important",PackageGetImportant}, + {"versionlist",PackageGetVersionList}, + {"currentver",PackageGetCurrentVer}, + #ifdef COMPAT_0_7 {"Name",PackageGetName}, {"Section",PackageGetSection}, {"RevDependsList",PackageGetRevDependsList}, @@ -495,6 +524,7 @@ static PyGetSetDef PackageGetSet[] = { {"Important",PackageGetImportant}, {"VersionList",PackageGetVersionList}, {"CurrentVer",PackageGetCurrentVer}, + #endif {} }; @@ -579,9 +609,13 @@ static PyObject *DescriptionGetFileList(PyObject *Self,void*) } static PyGetSetDef DescriptionGetSet[] = { - {"LanguageCode",DescriptionGetLanguageCode}, + {"languagecode",DescriptionGetLanguageCode}, {"md5",DescriptionGetMd5}, + {"filelist",DescriptionGetFileList}, + #ifdef COMPAT_0_7 + {"LanguageCode",DescriptionGetLanguageCode}, {"FileList",DescriptionGetFileList}, + #endif {} }; @@ -955,8 +989,12 @@ static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) static PyMethodDef DependencyMethods[] = { + {"smart_target_pkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, + {"all_targets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, +#ifdef COMPAT_0_7 {"SmartTargetPkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, {"AllTargets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, +#endif {} }; @@ -1014,6 +1052,14 @@ static PyObject *DependencyGetID(PyObject *Self,void*) } static PyGetSetDef DependencyGetSet[] = { + {"comptype",DependencyGetCompType}, + {"deptype",DependencyGetDepType}, + {"id",DependencyGetID}, + {"parentpkg",DependencyGetParentPkg}, + {"parentver",DependencyGetParentVer}, + {"targetpkg",DependencyGetTargetPkg}, + {"targetver",DependencyGetTargetVer}, +#ifdef COMPAT_0_7 {"CompType",DependencyGetCompType}, {"DepType",DependencyGetDepType}, {"ID",DependencyGetID}, @@ -1021,6 +1067,7 @@ static PyGetSetDef DependencyGetSet[] = { {"ParentVer",DependencyGetParentVer}, {"TargetPkg",DependencyGetTargetPkg}, {"TargetVer",DependencyGetTargetVer}, +#endif {} }; diff --git a/python/cdrom.cc b/python/cdrom.cc index bf94a390..044bbf30 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -58,8 +58,12 @@ static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) static PyMethodDef PkgCdromMethods[] = { + {"add",PkgCdromAdd,METH_VARARGS,"add(progress) -> Add a cdrom"}, + {"ident",PkgCdromIdent,METH_VARARGS,"ident(progress) -> Ident a cdrom"}, +#ifdef COMPAT_0_7 {"Add",PkgCdromAdd,METH_VARARGS,"Add(progress) -> Add a cdrom"}, {"Ident",PkgCdromIdent,METH_VARARGS,"Ident(progress) -> Ident a cdrom"}, +#endif {} }; diff --git a/python/configuration.cc b/python/configuration.cc index abbed6d9..107cf90f 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -453,13 +453,26 @@ PyObject *ParseCommandLine(PyObject *Self,PyObject *Args) static PyMethodDef CnfMethods[] = { // Query + {"find",CnfFind,METH_VARARGS,doc_Find}, + {"find_file",CnfFindFile,METH_VARARGS,doc_FindFile}, + {"find_dir",CnfFindDir,METH_VARARGS,doc_FindDir}, + {"find_i",CnfFindI,METH_VARARGS,doc_FindI}, + {"find_b",CnfFindB,METH_VARARGS,doc_FindB}, + + // Others + {"set",CnfSet,METH_VARARGS,doc_Set}, + {"exists",CnfExists,METH_VARARGS,doc_Exists}, + {"subtree",CnfSubTree,METH_VARARGS,doc_SubTree}, + {"list",CnfList,METH_VARARGS,doc_List}, + {"valuelist",CnfValueList,METH_VARARGS,doc_ValueList}, + {"mytag",CnfMyTag,METH_VARARGS,doc_MyTag}, + {"clear",CnfClear,METH_VARARGS,doc_Clear}, +#ifdef COMPAT_0_7 {"Find",CnfFind,METH_VARARGS,doc_Find}, {"FindFile",CnfFindFile,METH_VARARGS,doc_FindFile}, {"FindDir",CnfFindDir,METH_VARARGS,doc_FindDir}, {"FindI",CnfFindI,METH_VARARGS,doc_FindI}, {"FindB",CnfFindB,METH_VARARGS,doc_FindB}, - - // Others {"Set",CnfSet,METH_VARARGS,doc_Set}, {"Exists",CnfExists,METH_VARARGS,doc_Exists}, {"SubTree",CnfSubTree,METH_VARARGS,doc_SubTree}, @@ -467,10 +480,12 @@ static PyMethodDef CnfMethods[] = {"ValueList",CnfValueList,METH_VARARGS,doc_ValueList}, {"MyTag",CnfMyTag,METH_VARARGS,doc_MyTag}, {"Clear",CnfClear,METH_VARARGS,doc_Clear}, - +#endif // Python Special {"keys",CnfKeys,METH_VARARGS,doc_Keys}, + #if PY_MAJOR_VERSION < 3 {"has_key",CnfExists,METH_VARARGS,doc_Exists}, + #endif {"get",CnfFind,METH_VARARGS,doc_Find}, {} }; diff --git a/python/depcache.cc b/python/depcache.cc index ef2240ce..f3b16211 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -528,21 +528,47 @@ static PyObject *PkgDepCacheMarkedReinstall(PyObject *Self,PyObject *Args) static PyMethodDef PkgDepCacheMethods[] = { + {"init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, + {"get_candidate",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, + {"set_candidate",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, + + // global cache operations + {"upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, + {"fix_broken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, + {"read_pinfile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, + {"minimize_upgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, + // Manipulators + {"mark_keep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, + {"mark_delete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, + {"mark_install",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, + {"set_reinstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, + // state information + {"is_upgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, + {"is_now_broken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, + {"is_inst_broken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, + {"is_garbage",PkgDepCacheIsGarbage,METH_VARARGS,"Is pkg garbage (mark-n-sweep)"}, + {"is_auto_installed",PkgDepCacheIsAutoInstalled,METH_VARARGS,"Is pkg marked as auto installed"}, + {"marked_install",PkgDepCacheMarkedInstall,METH_VARARGS,"Is pkg marked for install"}, + {"marked_upgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"}, + {"marked_delete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"}, + {"marked_keep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, + {"marked_reinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, + {"marked_downgrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, + + // Action + {"commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, +#ifdef COMPAT_0_7 {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, {"SetCandidateVer",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, - - // global cache operations {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, {"ReadPinFile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, {"MinimizeUpgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, - // Manipulators {"MarkKeep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, {"MarkDelete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, {"MarkInstall",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, {"SetReInstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, - // state information {"IsUpgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, {"IsNowBroken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, {"IsInstBroken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, @@ -554,9 +580,8 @@ static PyMethodDef PkgDepCacheMethods[] = {"MarkedKeep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, {"MarkedReinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, {"MarkedDowngrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - - // Action {"Commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, +#endif {} }; @@ -582,12 +607,20 @@ static PyObject *PkgDepCacheGetDebSize(PyObject *Self,void*) { #undef depcache static PyGetSetDef PkgDepCacheGetSet[] = { + {"brokencount",PkgDepCacheGetBrokenCount}, + {"debsize",PkgDepCacheGetDebSize}, + {"delcount",PkgDepCacheGetDelCount}, + {"instcount",PkgDepCacheGetInstCount}, + {"keepcount",PkgDepCacheGetKeepCount}, + {"usrsize",PkgDepCacheGetUsrSize}, + #ifdef COMPAT_0_7 {"BrokenCount",PkgDepCacheGetBrokenCount}, {"DebSize",PkgDepCacheGetDebSize}, {"DelCount",PkgDepCacheGetDelCount}, {"InstCount",PkgDepCacheGetInstCount}, {"KeepCount",PkgDepCacheGetKeepCount}, {"UsrSize",PkgDepCacheGetUsrSize}, + #endif {} }; @@ -779,14 +812,22 @@ static PyObject *PkgProblemResolverInstallProtect(PyObject *Self,PyObject *Args) static PyMethodDef PkgProblemResolverMethods[] = { // config + {"protect", PkgProblemResolverProtect, METH_VARARGS, "protect(PkgIterator)"}, + {"remove", PkgProblemResolverRemove, METH_VARARGS, "remove(PkgIterator)"}, + {"clear", PkgProblemResolverClear, METH_VARARGS, "clear(PkgIterator)"}, + {"install_protect", PkgProblemResolverInstallProtect, METH_VARARGS, "install_protect()"}, + + // Actions + {"resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, + {"resolve_by_keep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, + #ifdef COMPAT_0_7 {"Protect", PkgProblemResolverProtect, METH_VARARGS, "Protect(PkgIterator)"}, {"Remove", PkgProblemResolverRemove, METH_VARARGS, "Remove(PkgIterator)"}, {"Clear", PkgProblemResolverClear, METH_VARARGS, "Clear(PkgIterator)"}, {"InstallProtect", PkgProblemResolverInstallProtect, METH_VARARGS, "ProtectInstalled()"}, - - // Actions {"Resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, {"ResolveByKeep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, + #endif {} }; diff --git a/python/indexfile.cc b/python/indexfile.cc index 600dc853..795931fb 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -28,7 +28,10 @@ static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args) static PyMethodDef PackageIndexFileMethods[] = { + {"archive_uri",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, + #ifdef COMPAT_0_7 {"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, + #endif {} }; @@ -69,12 +72,20 @@ static PyObject *PackageIndexFileRepr(PyObject *Self) } static PyGetSetDef PackageIndexFileGetSet[] = { + {"describe",PackageIndexFileGetDescribe}, + {"exists",PackageIndexFileGetExists}, + {"has_packages",PackageIndexFileGetHasPackages}, + {"is_trusted",PackageIndexFileGetIsTrusted}, + {"label",PackageIndexFileGetLabel}, + {"size",PackageIndexFileGetSize}, + #ifdef COMPAT_0_7 {"Describe",PackageIndexFileGetDescribe}, {"Exists",PackageIndexFileGetExists}, {"HasPackages",PackageIndexFileGetHasPackages}, {"IsTrusted",PackageIndexFileGetIsTrusted}, {"Label",PackageIndexFileGetLabel}, {"Size",PackageIndexFileGetSize}, + #endif {} }; diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 781acc8b..cae2b580 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -92,9 +92,14 @@ static PyObject *PkgManagerFixMissing(PyObject *Self,PyObject *Args) static PyMethodDef PkgManagerMethods[] = { + {"get_archives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, + {"do_install",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, + {"fix_missing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, +#ifdef COMPAT_0_7 {"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"}, +#endif {} }; @@ -110,9 +115,14 @@ static PyObject *PkgManagerGetResultIncomplete(PyObject *Self,void*) { } static PyGetSetDef PkgManagerGetSet[] = { + {"result_completed",PkgManagerGetResultCompleted}, + {"result_failed",PkgManagerGetResultFailed}, + {"result_incomplete",PkgManagerGetResultIncomplete}, +#ifdef COMPAT_0_7 {"ResultCompleted",PkgManagerGetResultCompleted}, {"ResultFailed",PkgManagerGetResultFailed}, {"ResultIncomplete",PkgManagerGetResultIncomplete}, +#endif {} }; diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 1cccfce2..f9e48352 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -49,7 +49,10 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) static PyMethodDef PkgRecordsMethods[] = { + {"lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, + #ifdef COMPAT_0_7 {"Lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, + #endif {} }; @@ -117,6 +120,19 @@ static PyObject *PkgRecordsGetRecord(PyObject *Self,void*) { return PyString_FromStringAndSize(start,stop-start); } static PyGetSetDef PkgRecordsGetSet[] = { + {"filename",PkgRecordsGetFileName}, + {"homepage",PkgRecordsGetHomepage}, + {"longdesc",PkgRecordsGetLongDesc}, + {"md5",PkgRecordsGetMD5Hash}, + {"maintainer",PkgRecordsGetMaintainer}, + {"name",PkgRecordsGetName}, + {"record",PkgRecordsGetRecord}, + {"sha1",PkgRecordsGetSHA1Hash}, + {"sha256",PkgRecordsGetSHA256Hash}, + {"shortdesc",PkgRecordsGetShortDesc}, + {"sourcepkg",PkgRecordsGetSourcePkg}, + {"sourcever",PkgRecordsGetSourceVer}, +#ifdef COMPAT_0_7 {"FileName",PkgRecordsGetFileName}, {"Homepage",PkgRecordsGetHomepage}, {"LongDesc",PkgRecordsGetLongDesc}, @@ -129,6 +145,7 @@ static PyGetSetDef PkgRecordsGetSet[] = { {"ShortDesc",PkgRecordsGetShortDesc}, {"SourcePkg",PkgRecordsGetSourcePkg}, {"SourceVer",PkgRecordsGetSourceVer}, +#endif {} }; diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 8b4dce3e..2a8b7bab 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -70,8 +70,12 @@ static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) static PyMethodDef PkgSrcRecordsMethods[] = { + {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, + {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, +#ifdef COMPAT_0_7 {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"Restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, +#endif {} }; @@ -168,6 +172,16 @@ static PyObject *PkgSrcRecordsGetBuildDepends(PyObject *Self,void*) { } static PyGetSetDef PkgSrcRecordsGetSet[] = { + {"binaries",PkgSrcRecordsGetBinaries}, + {"builddepends",PkgSrcRecordsGetBuildDepends}, + {"files",PkgSrcRecordsGetFiles}, + {"index",PkgSrcRecordsGetIndex}, + {"maintainer",PkgSrcRecordsGetMaintainer}, + {"package",PkgSrcRecordsGetPackage}, + {"record",PkgSrcRecordsGetRecord}, + {"section",PkgSrcRecordsGetSection}, + {"version",PkgSrcRecordsGetVersion}, +#ifdef COMPAT_0_7 {"Binaries",PkgSrcRecordsGetBinaries}, {"BuildDepends",PkgSrcRecordsGetBuildDepends}, {"Files",PkgSrcRecordsGetFiles}, @@ -177,6 +191,7 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { {"Record",PkgSrcRecordsGetRecord}, {"Section",PkgSrcRecordsGetSection}, {"Version",PkgSrcRecordsGetVersion}, +#endif {} }; diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 15311e94..daf0c08c 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -72,9 +72,14 @@ static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args) static PyMethodDef PkgSourceListMethods[] = { + {"find_index",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, + {"read_main_list",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, + {"get_indexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, +#ifdef COMPAT_0_7 {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, +#endif {} }; @@ -93,7 +98,10 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) } static PyGetSetDef PkgSourceListGetSet[] = { + {"list",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, +#ifdef COMPAT_0_7 {"List",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, +#endif {} }; diff --git a/python/tag.cc b/python/tag.cc index bc23e98b..846123ba 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -377,13 +377,20 @@ PyObject *RewriteSection(PyObject *self,PyObject *Args) static PyMethodDef TagSecMethods[] = { // Query + {"find",TagSecFind,METH_VARARGS,doc_Find}, + {"findflag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, + {"bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, +#ifdef COMPAT_0_7 {"Find",TagSecFind,METH_VARARGS,doc_Find}, {"FindFlag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, {"Bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, +#endif // Python Special {"keys",TagSecKeys,METH_VARARGS,doc_Keys}, +#if PY_MAJOR_VERSION < 3 {"has_key",TagSecExists,METH_VARARGS,doc_Exists}, +#endif {"get",TagSecFind,METH_VARARGS,doc_Find}, {} }; @@ -448,9 +455,14 @@ PyTypeObject TagSecType = static PyMethodDef TagFileMethods[] = { // Query + {"step",TagFileStep,METH_VARARGS,doc_Step}, + {"offset",TagFileOffset,METH_VARARGS,doc_Offset}, + {"jump",TagFileJump,METH_VARARGS,doc_Jump}, +#ifdef COMPAT_0_7 {"Step",TagFileStep,METH_VARARGS,doc_Step}, {"Offset",TagFileOffset,METH_VARARGS,doc_Offset}, {"Jump",TagFileJump,METH_VARARGS,doc_Jump}, +#endif {} }; @@ -463,7 +475,10 @@ static PyObject *TagFileGetSection(PyObject *Self,void*) { } static PyGetSetDef TagFileGetSet[] = { + {"section",TagFileGetSection,0,"Return a TagSection.",0}, +#ifdef COMPAT_0_7 {"Section",TagFileGetSection,0,"Return a TagSection.",0}, +#endif {} }; -- cgit v1.2.3 From 884c8a4ebdfcedf8143dcb2ce8ef92779c353e06 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 4 Jun 2009 17:18:29 +0200 Subject: python/: Unify naming conventions for all new names. Unify all names to follow these rules: 1. Replace the first [A-Z] with the lowercase version [a-z] 2. Replace multiple [A-Z] with [A-Z][a-z] (one upper, remaining ones lowercase) 3. Replace all remaining [A-Z] with _[a-z] This brings us from 'FileName' to 'file_name' and from 'DescURI' to 'desc_uri'. We will at a later stage add some exceptions to this rule, like 'filename' instead of 'file_name', to improve readability. --- python/acquire.cc | 8 ++++---- python/apt_pkgmodule.cc | 36 ++++++++++++++++++------------------ python/cache.cc | 30 +++++++++++++++--------------- python/configuration.cc | 6 +++--- python/depcache.cc | 20 ++++++++++---------- python/pkgrecords.cc | 16 ++++++++-------- python/pkgsrcrecords.cc | 2 +- python/tag.cc | 2 +- 8 files changed, 60 insertions(+), 60 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index 6cb2130c..1b1c5dd8 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -39,10 +39,10 @@ MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthE static PyGetSetDef AcquireItemGetSet[] = { {"complete",AcquireItemGetComplete}, - {"descuri",AcquireItemGetDescURI}, - {"destfile",AcquireItemGetDestFile}, - {"errortext",AcquireItemGetErrorText}, - {"filesize",AcquireItemGetFileSize}, + {"desc_uri",AcquireItemGetDescURI}, + {"dest_file",AcquireItemGetDestFile}, + {"error_text",AcquireItemGetErrorText}, + {"file_size",AcquireItemGetFileSize}, {"is",AcquireItemGetID}, {"is_trusted",AcquireItemGetIsTrusted}, {"local",AcquireItemGetLocal}, diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 44234f8d..8259d7c3 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -407,7 +407,7 @@ static PyMethodDef methods[] = // Locking {"get_lock",GetLock,METH_VARARGS,doc_GetLock}, {"pkgsystem_lock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, - {"pkgsystem_unlock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, + {"pkgsystem_un_lock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, #ifdef COMPAT_0_7 {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, @@ -415,10 +415,10 @@ static PyMethodDef methods[] = #endif // Command line - {"read_configfile",LoadConfig,METH_VARARGS,doc_LoadConfig}, - {"read_configdir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, - {"read_configfile_isc",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, - {"parse_commandline",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, + {"read_config_file",LoadConfig,METH_VARARGS,doc_LoadConfig}, + {"read_config_dir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, + {"read_config_file_isc",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, + {"parse_command_line",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, #ifdef COMPAT_0_7 {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, @@ -438,7 +438,7 @@ static PyMethodDef methods[] = // Depends {"parse_depends",ParseDepends,METH_VARARGS,doc_ParseDepends}, - {"parse_srcdepends",ParseSrcDepends,METH_VARARGS,doc_ParseDepends}, + {"parse_src_depends",ParseSrcDepends,METH_VARARGS,doc_ParseDepends}, #ifdef COMPAT_0_7 {"ParseDepends",ParseDepends,METH_VARARGS,doc_ParseDepends}, {"ParseSrcDepends",ParseSrcDepends,METH_VARARGS,doc_ParseDepends}, @@ -450,12 +450,12 @@ static PyMethodDef methods[] = {"sha256sum",sha256sum,METH_VARARGS,doc_sha256sum}, // Strings - {"check_domainlist",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, + {"check_domain_list",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, {"quote_string",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, - {"dequote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, + {"de_quote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, {"size_to_str",StrSizeToStr,METH_VARARGS,"SizeToStr(int) -> String"}, {"time_to_str",StrTimeToStr,METH_VARARGS,"TimeToStr(int) -> String"}, - {"uri_to_filename",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, + {"uri_to_file_name",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, {"base64_encode",StrBase64Encode,METH_VARARGS,"Base64Encode(String) -> String"}, {"string_to_bool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, {"time_rfc1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, @@ -644,7 +644,7 @@ extern "C" void initapt_pkg() // My constants PyModule_AddIntConstant(Module,"DEP_DEPENDS",pkgCache::Dep::Depends); - PyModule_AddIntConstant(Module,"DEP_PREDEPENDS",pkgCache::Dep::PreDepends); + PyModule_AddIntConstant(Module,"DEP_PRE_DEPENDS",pkgCache::Dep::PreDepends); PyModule_AddIntConstant(Module,"DEP_SUGGESTS",pkgCache::Dep::Suggests); PyModule_AddIntConstant(Module,"DEP_RECOMMENDS",pkgCache::Dep::Recommends); PyModule_AddIntConstant(Module,"DEP_CONFLICTS",pkgCache::Dep::Conflicts); @@ -673,23 +673,23 @@ extern "C" void initapt_pkg() PyModule_AddIntConstant(Module,"PriExtra",pkgCache::State::Extra); #endif // CurState - PyModule_AddIntConstant(Module,"CURSTATE_NOTINSTALLED",pkgCache::State::NotInstalled); - PyModule_AddIntConstant(Module,"CURSTATE_UNPACKED",pkgCache::State::UnPacked); - PyModule_AddIntConstant(Module,"CURSTATE_HALFCONFIGURED",pkgCache::State::HalfConfigured); - PyModule_AddIntConstant(Module,"CURSTATE_HALFINSTALLED",pkgCache::State::HalfInstalled); - PyModule_AddIntConstant(Module,"CURSTATE_CONFIGFILES",pkgCache::State::ConfigFiles); + PyModule_AddIntConstant(Module,"CURSTATE_NOT_INSTALLED",pkgCache::State::NotInstalled); + PyModule_AddIntConstant(Module,"CURSTATE_UN_PACKED",pkgCache::State::UnPacked); + PyModule_AddIntConstant(Module,"CURSTATE_HALF_CONFIGURED",pkgCache::State::HalfConfigured); + PyModule_AddIntConstant(Module,"CURSTATE_HALF_INSTALLED",pkgCache::State::HalfInstalled); + PyModule_AddIntConstant(Module,"CURSTATE_CONFIG_FILES",pkgCache::State::ConfigFiles); PyModule_AddIntConstant(Module,"CURSTATE_INSTALLED",pkgCache::State::Installed); // SelState PyModule_AddIntConstant(Module,"SELSTATE_UNKNOWN",pkgCache::State::Unknown); PyModule_AddIntConstant(Module,"SELSTATE_INSTALL",pkgCache::State::Install); PyModule_AddIntConstant(Module,"SELSTATE_HOLD",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"SELSTATE_DEINSTALL",pkgCache::State::DeInstall); + PyModule_AddIntConstant(Module,"SELSTATE_DE_INSTALL",pkgCache::State::DeInstall); PyModule_AddIntConstant(Module,"SELSTATE_PURGE",pkgCache::State::Purge); // InstState PyModule_AddIntConstant(Module,"INSTSTATE_OK",pkgCache::State::Ok); - PyModule_AddIntConstant(Module,"INSTSTATE_REINSTREQ",pkgCache::State::ReInstReq); + PyModule_AddIntConstant(Module,"INSTSTATE_RE_INST_REQ",pkgCache::State::ReInstReq); PyModule_AddIntConstant(Module,"INSTSTATE_HOLD",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_REINSTREQ",pkgCache::State::HoldReInstReq); + PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_RE_INST_REQ",pkgCache::State::HoldReInstReq); #ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"CurStateNotInstalled",pkgCache::State::NotInstalled); diff --git a/python/cache.cc b/python/cache.cc index c7694026..27b77773 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -196,12 +196,12 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { static PyGetSetDef PkgCacheGetSet[] = { {"depends_count",PkgCacheGetDependsCount}, - {"filelist",PkgCacheGetFileList}, + {"file_list",PkgCacheGetFileList}, {"package_count",PkgCacheGetPackageCount}, - {"packagefile_count",PkgCacheGetPackageFileCount}, + {"package_file_count",PkgCacheGetPackageFileCount}, {"packages",PkgCacheGetPackages}, {"provides_count",PkgCacheGetProvidesCount}, - {"verfile_count",PkgCacheGetVerFileCount}, + {"ver_file_count",PkgCacheGetVerFileCount}, {"version_count",PkgCacheGetVersionCount}, #ifdef COMPAT_0_7 {"DependsCount",PkgCacheGetDependsCount}, @@ -499,8 +499,8 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) static PyGetSetDef PackageGetSet[] = { {"name",PackageGetName}, {"section",PackageGetSection}, - {"revdependslist",PackageGetRevDependsList}, - {"provideslist",PackageGetProvidesList}, + {"rev_depends_list",PackageGetRevDependsList}, + {"provides_list",PackageGetProvidesList}, {"selected_state",PackageGetSelectedState}, {"inst_state",PackageGetInstState}, {"current_state",PackageGetCurrentState}, @@ -508,8 +508,8 @@ static PyGetSetDef PackageGetSet[] = { {"auto",PackageGetAuto}, {"essential",PackageGetEssential}, {"important",PackageGetImportant}, - {"versionlist",PackageGetVersionList}, - {"currentver",PackageGetCurrentVer}, + {"version_list",PackageGetVersionList}, + {"current_ver",PackageGetCurrentVer}, #ifdef COMPAT_0_7 {"Name",PackageGetName}, {"Section",PackageGetSection}, @@ -609,9 +609,9 @@ static PyObject *DescriptionGetFileList(PyObject *Self,void*) } static PyGetSetDef DescriptionGetSet[] = { - {"languagecode",DescriptionGetLanguageCode}, + {"language_code",DescriptionGetLanguageCode}, {"md5",DescriptionGetMd5}, - {"filelist",DescriptionGetFileList}, + {"file_list",DescriptionGetFileList}, #ifdef COMPAT_0_7 {"LanguageCode",DescriptionGetLanguageCode}, {"FileList",DescriptionGetFileList}, @@ -1212,13 +1212,13 @@ static PyObject *DependencyGetID(PyObject *Self,void*) } static PyGetSetDef DependencyGetSet[] = { - {"comptype",DependencyGetCompType}, - {"deptype",DependencyGetDepType}, + {"comp_type",DependencyGetCompType}, + {"dep_type",DependencyGetDepType}, {"id",DependencyGetID}, - {"parentpkg",DependencyGetParentPkg}, - {"parentver",DependencyGetParentVer}, - {"targetpkg",DependencyGetTargetPkg}, - {"targetver",DependencyGetTargetVer}, + {"parent_pkg",DependencyGetParentPkg}, + {"parent_ver",DependencyGetParentVer}, + {"target_pkg",DependencyGetTargetPkg}, + {"target_ver",DependencyGetTargetVer}, #ifdef COMPAT_0_7 {"CompType",DependencyGetCompType}, {"DepType",DependencyGetDepType}, diff --git a/python/configuration.cc b/python/configuration.cc index 107cf90f..7b08d90e 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -462,10 +462,10 @@ static PyMethodDef CnfMethods[] = // Others {"set",CnfSet,METH_VARARGS,doc_Set}, {"exists",CnfExists,METH_VARARGS,doc_Exists}, - {"subtree",CnfSubTree,METH_VARARGS,doc_SubTree}, + {"sub_tree",CnfSubTree,METH_VARARGS,doc_SubTree}, {"list",CnfList,METH_VARARGS,doc_List}, - {"valuelist",CnfValueList,METH_VARARGS,doc_ValueList}, - {"mytag",CnfMyTag,METH_VARARGS,doc_MyTag}, + {"value_list",CnfValueList,METH_VARARGS,doc_ValueList}, + {"my_tag",CnfMyTag,METH_VARARGS,doc_MyTag}, {"clear",CnfClear,METH_VARARGS,doc_Clear}, #ifdef COMPAT_0_7 {"Find",CnfFind,METH_VARARGS,doc_Find}, diff --git a/python/depcache.cc b/python/depcache.cc index f3b16211..650dcb23 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -529,19 +529,19 @@ static PyObject *PkgDepCacheMarkedReinstall(PyObject *Self,PyObject *Args) static PyMethodDef PkgDepCacheMethods[] = { {"init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, - {"get_candidate",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, - {"set_candidate",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, + {"get_candidate_ver",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, + {"set_candidate_ver",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, // global cache operations {"upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, {"fix_broken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, - {"read_pinfile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, + {"read_pin_file",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, {"minimize_upgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, // Manipulators {"mark_keep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, {"mark_delete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, {"mark_install",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, - {"set_reinstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, + {"set_re_install",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, // state information {"is_upgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, {"is_now_broken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, @@ -607,12 +607,12 @@ static PyObject *PkgDepCacheGetDebSize(PyObject *Self,void*) { #undef depcache static PyGetSetDef PkgDepCacheGetSet[] = { - {"brokencount",PkgDepCacheGetBrokenCount}, - {"debsize",PkgDepCacheGetDebSize}, - {"delcount",PkgDepCacheGetDelCount}, - {"instcount",PkgDepCacheGetInstCount}, - {"keepcount",PkgDepCacheGetKeepCount}, - {"usrsize",PkgDepCacheGetUsrSize}, + {"broken_count",PkgDepCacheGetBrokenCount}, + {"deb_size",PkgDepCacheGetDebSize}, + {"del_count",PkgDepCacheGetDelCount}, + {"inst_count",PkgDepCacheGetInstCount}, + {"keep_count",PkgDepCacheGetKeepCount}, + {"usr_size",PkgDepCacheGetUsrSize}, #ifdef COMPAT_0_7 {"BrokenCount",PkgDepCacheGetBrokenCount}, {"DebSize",PkgDepCacheGetDebSize}, diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index f9e48352..48440387 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -120,18 +120,18 @@ static PyObject *PkgRecordsGetRecord(PyObject *Self,void*) { return PyString_FromStringAndSize(start,stop-start); } static PyGetSetDef PkgRecordsGetSet[] = { - {"filename",PkgRecordsGetFileName}, + {"file_name",PkgRecordsGetFileName}, {"homepage",PkgRecordsGetHomepage}, - {"longdesc",PkgRecordsGetLongDesc}, - {"md5",PkgRecordsGetMD5Hash}, + {"long_desc",PkgRecordsGetLongDesc}, + {"md5_hash",PkgRecordsGetMD5Hash}, {"maintainer",PkgRecordsGetMaintainer}, {"name",PkgRecordsGetName}, {"record",PkgRecordsGetRecord}, - {"sha1",PkgRecordsGetSHA1Hash}, - {"sha256",PkgRecordsGetSHA256Hash}, - {"shortdesc",PkgRecordsGetShortDesc}, - {"sourcepkg",PkgRecordsGetSourcePkg}, - {"sourcever",PkgRecordsGetSourceVer}, + {"sha1_hash",PkgRecordsGetSHA1Hash}, + {"sha256_hash",PkgRecordsGetSHA256Hash}, + {"short_desc",PkgRecordsGetShortDesc}, + {"source_pkg",PkgRecordsGetSourcePkg}, + {"source_ver",PkgRecordsGetSourceVer}, #ifdef COMPAT_0_7 {"FileName",PkgRecordsGetFileName}, {"Homepage",PkgRecordsGetHomepage}, diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 2a8b7bab..dea7ff37 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -173,7 +173,7 @@ static PyObject *PkgSrcRecordsGetBuildDepends(PyObject *Self,void*) { static PyGetSetDef PkgSrcRecordsGetSet[] = { {"binaries",PkgSrcRecordsGetBinaries}, - {"builddepends",PkgSrcRecordsGetBuildDepends}, + {"build_depends",PkgSrcRecordsGetBuildDepends}, {"files",PkgSrcRecordsGetFiles}, {"index",PkgSrcRecordsGetIndex}, {"maintainer",PkgSrcRecordsGetMaintainer}, diff --git a/python/tag.cc b/python/tag.cc index 846123ba..c30adb0a 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -378,7 +378,7 @@ static PyMethodDef TagSecMethods[] = { // Query {"find",TagSecFind,METH_VARARGS,doc_Find}, - {"findflag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, + {"find_flag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, {"bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, #ifdef COMPAT_0_7 {"Find",TagSecFind,METH_VARARGS,doc_Find}, -- cgit v1.2.3 From 14dfadc054e9bdafd2507dbca70dbec925471ae0 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 5 Jun 2009 15:00:15 +0200 Subject: Introduce the rename rules formally, and add some exceptions. --- apt/cache.py | 4 +- apt/package.py | 10 ++--- doc/source/apt_pkg.rst | 36 ++++++++-------- doc/source/examples/cache-pkgfile.py | 2 +- doc/source/whatsnew/0.8.0.rst | 82 +++++++++++++++++++++++++++++++++++- python/acquire.cc | 10 ++--- python/apt_pkgmodule.cc | 16 +++---- python/cache.cc | 2 +- python/configuration.cc | 2 +- python/depcache.cc | 4 +- python/pkgrecords.cc | 2 +- 11 files changed, 124 insertions(+), 46 deletions(-) (limited to 'python/configuration.cc') diff --git a/apt/cache.py b/apt/cache.py index 56b32d45..8590510c 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -170,8 +170,8 @@ class Cache(object): reqreinst = set() for pkg in self: if (not pkg.candidate.downloadable and - (pkg._pkg.inst_state == apt_pkg.INSTSTATE_RE_INST_REQ or - pkg._pkg.inst_state == apt_pkg.INSTSTATE_HOLD_RE_INST_REQ)): + (pkg._pkg.inst_state == apt_pkg.INSTSTATE_REINSTREQ or + pkg._pkg.inst_state == apt_pkg.INSTSTATE_HOLD_REINSTREQ)): reqreinst.add(pkg.name) return reqreinst diff --git a/apt/package.py b/apt/package.py index a24486e1..48d14595 100644 --- a/apt/package.py +++ b/apt/package.py @@ -379,7 +379,7 @@ class Version(object): .. versionadded:: 0.7.10 """ - return self._records.file_name + return self._records.filename @property def md5(self): @@ -413,7 +413,7 @@ class Version(object): for (packagefile, index) in self._cand.file_list: indexfile = self.package._pcache._list.find_index(packagefile) if indexfile: - yield indexfile.archive_uri(self._records.file_name) + yield indexfile.archive_uri(self._records.filename) @property def uris(self): @@ -443,19 +443,19 @@ class Version(object): .. versionadded:: 0.7.10 """ - base = os.path.basename(self._records.file_name) + base = os.path.basename(self._records.filename) destfile = os.path.join(destdir, base) if _file_is_same(destfile, self.size, self._records.md5_hash): print 'Ignoring already existing file:', destfile return acq = apt_pkg.Acquire(progress or apt.progress.TextFetchProgress()) apt_pkg.AcquireFile(acq, self.uri, self._records.md5_hash, self.size, - base, dest_file=destfile) + base, destfile=destfile) acq.run() for item in acq.items: if item.status != item.stat_done: raise FetchError("The item %r could not be fetched: %s" % - (item.dest_file, item.error_text)) + (item.destfile, item.error_text)) return os.path.abspath(destfile) def fetch_source(self, destdir="", progress=None, unpack=True): diff --git a/doc/source/apt_pkg.rst b/doc/source/apt_pkg.rst index 39b48c35..c814615c 100644 --- a/doc/source/apt_pkg.rst +++ b/doc/source/apt_pkg.rst @@ -167,7 +167,7 @@ Working with the cache If *from_user* is ``True``, the package will be marked as manually installed. This is the default. - .. method:: set_re_install(pkg) + .. method:: set_reinstall(pkg) Set if the :class:`Package` *pkg* should be reinstalled. @@ -398,7 +398,7 @@ Resolving Dependencies The component (eg. main) - .. attribute:: file_name + .. attribute:: filename The name of the file. @@ -430,7 +430,7 @@ Resolving Dependencies for pkgfile in cache.file_list: if pkgfile.not_source: - print 'The file %s has no source.' % pkgfile.file_name + print 'The file %s has no source.' % pkgfile.filename .. attribute:: origin @@ -809,7 +809,7 @@ Records # Now you can access the record print records.SourcePkg # == python-apt - .. attribute:: file_name + .. attribute:: filename Return the field 'Filename' of the record. This is the path to the package, relative to the base path of the archive. @@ -1103,7 +1103,7 @@ installation. Constant for comparing :attr:`AcquireItem.status` -.. class:: AcquireFile(owner, uri[, md5, size, descr, short_descr, dest_dir, dest_file]) +.. class:: AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir, destfile]) Create a new :class:`AcquireFile()` object and register it with *acquire*, so it will be fetched. AcquireFile objects provide no methods or attributes @@ -1126,9 +1126,9 @@ installation. used to describe the item in the progress class. *short_descr* is the short form of it. - You can use *dest_dir* to manipulate the directory where the file will - be saved in. Instead of *dest_dir*, you can also specify the full path to - the file using the parameter *dest_file*. You can not combine both. + You can use *destdir* to manipulate the directory where the file will + be saved in. Instead of *destdir*, you can also specify the full path to + the file using the parameter *destfile*. You can not combine both. @@ -1379,7 +1379,7 @@ Configuration Check whether the key *key* exists in the configuration. - .. method:: sub_tree(key) + .. method:: subtree(key) Return a sub tree starting at *key*. The resulting object can be used like this one. @@ -1429,7 +1429,7 @@ Configuration Behaves like a :class:`Configuration()` objects, but provides access to a subsection of another Configuration-like object. This type of object is - returned by the :meth:`Configuration.sub_tree()` method. + returned by the :meth:`Configuration.subtree()` method. .. data:: config @@ -1459,7 +1459,7 @@ Modifying the settings therein to the :class:`Configuration()` object specified by the parameter *configuration* -.. function:: parse_command_line(configuration, options, argv) +.. function:: parse_commandline(configuration, options, argv) This function is like getopt except it manipulates a configuration space. output is a list of non-option arguments (filenames, etc). *options* is a @@ -1541,11 +1541,11 @@ String functions apt_pkg.check_domain_list("alioth.debian.org","debian.net,debian.org") -.. function:: de_quote_string(string) +.. function:: dequote_string(string) Dequote the string specified by the parameter *string*, e.g.:: - >>> apt_pkg.DeQuoteString("%61%70%74%20is%20cool") + >>> apt_pkg.dequote_string("%61%70%74%20is%20cool") 'apt is cool' .. function:: quote_string(string, repl) @@ -1627,14 +1627,14 @@ String functions Return the string *version*, eliminating everything following the last '-'. Thus, this should be equivalent to ``version.rsplit('-', 1)[0]``. -.. function:: uri_to_file_name(uri) +.. function:: uri_to_filename(uri) Take a string *uri* as parameter and return a filename which can be used to store the file, based on the URI. Example:: - >>> apt_pkg.uri_to_file_name('http://debian.org/index.html') + >>> apt_pkg.uri_to_filename('http://debian.org/index.html') 'debian.org_index.html' @@ -1667,7 +1667,7 @@ Package States .. data:: CURSTATE_HALF_INSTALLED .. data:: CURSTATE_INSTALLED .. data:: CURSTATE_NOT_INSTALLED -.. data:: CURSTATE_UN_PACKED +.. data:: CURSTATE_UNPACKED @@ -1687,9 +1687,9 @@ Dependency types Installed states ^^^^^^^^^^^^^^^^ .. data:: INSTSTATE_HOLD -.. data:: INSTSTATE_HOLD_RE_INST_REQ +.. data:: INSTSTATE_HOLD_REINSTREQ .. data:: INSTSTATE_OK -.. data:: INSTSTATE_RE_INST_REQ +.. data:: INSTSTATE_REINSTREQ .. _Priorities: diff --git a/doc/source/examples/cache-pkgfile.py b/doc/source/examples/cache-pkgfile.py index 1300a55c..f4cc2e66 100644 --- a/doc/source/examples/cache-pkgfile.py +++ b/doc/source/examples/cache-pkgfile.py @@ -7,7 +7,7 @@ def main(): apt_pkg.init() cache = apt_pkg.Cache() for pkgfile in cache.file_list: - print 'Package-File:', pkgfile.file_name + print 'Package-File:', pkgfile.filename print 'Index-Type:', pkgfile.index_type # 'Debian Package Index' if pkgfile.not_source: print 'Source: None' diff --git a/doc/source/whatsnew/0.8.0.rst b/doc/source/whatsnew/0.8.0.rst index d1ac3ac5..d507e82a 100644 --- a/doc/source/whatsnew/0.8.0.rst +++ b/doc/source/whatsnew/0.8.0.rst @@ -15,19 +15,97 @@ Python-apt is the first Debian package to support the third major release of Python. The port is straight forward and integrates as nicely in Python 3 as the Python 2 builds integrate in Python 2. +Please be aware that python-apt builds for Python 3 are built without the +compatibility options enabled for Python 2 builds. They also do not provide +methods like :meth:`has_key` on mapping objects, because it has been removed +in Python 3. + Real classes in :mod:`apt_pkg` ------------------------------ +The 0.8 release introduces real classes in the :mod:`apt_pkg` extension. This +is an important step forward and makes writing code much easier, because you +can see the classes without having to create an object first. It also makes +it easier to talk about those classes, because they have a real name now. + +The 0.7 series shipped many functions for creating new objects, because the +classes were not exported. In 0.8, the classes themselves replace those +functions, as you can see in the following table. + +.. table:: + + ===================================== ================================= + Function Replacing class + ===================================== ================================= + :func:`apt_pkg.GetAcquire` :class:`apt_pkg.Acquire` + :func:`apt_pkg.GetCache()` :class:`apt_pkg.Cache` + :func:`apt_pkg.GetCdrom()` :class:`apt_pkg.Cdrom` + :func:`apt_pkg.GetDepCache()` :class:`apt_pkg.DepCache` + :func:`apt_pkg.GetPackageManager` :class:`apt_pkg.PackageManager` + :func:`apt_pkg.GetPkgAcqFile` :class:`apt_pkg.AcquireFile` + :func:`apt_pkg.GetPkgActionGroup` :class:`apt_pkg.ActionGroup` + :func:`apt_pkg.GetPkgProblemResolver` :class:`apt_pkg.ProblemResolver` + :func:`apt_pkg.GetPkgRecords` :class:`apt_pkg.PackageRecords` + :func:`apt_pkg.GetPkgSourceList` :class:`apt_pkg.SourceList` + :func:`apt_pkg.GetPkgSrcRecords` :class:`apt_pkg.SourceRecords` + :func:`apt_pkg.ParseSection` :class:`apt_pkg.TagSection` + :func:`apt_pkg.ParseTagFile` :class:`apt_pkg.TagFile` + ===================================== ================================= Complete rename of functions, methods and attributes ----------------------------------------------------- +In May 2008, Ben Finney reported bug 481061 against the python-apt package, +asking for PEP8 conformant names. With the release of python-apt 0.8, this +is finally happening. Supporting new language features like the :keyword:`with` statement ------------------------------------------------------------------- +This is not a real big change, but it's good to have it: +:class:`apt_pkg.ActionGroup` can now be used as a context manager for the +:keyword:`with` statement. This makes it more obvious that you are using an +action group, and is just cooler:: + + with apt_pkg.ActionGroup(depcache): + for package in my_selected_packages: + depcache.mark_install(package) + +This also works for :class:`apt.Cache`:: + + with cache.action_group(): # cache is an Instance of apt.Cache + for package in my_selected_packages: + package.mark_install() # Instance of apt.Package + Other changes ------------- This release of python-apt also features several other, smaller changes: - * Reduced memory usage by creating Package() objects in apt.Cache() only - when needed. + * Reduced memory usage by making :class:`apt.Cache` create + :class:`apt.Package()` object dynamically, instead of creating all of + them during the cache initialization. * Support to set the candidate version in :class:`apt.package.Package` + +Porting your applications to python-apt 0.8 +------------------------------------------- +Porting your application to python-apt 0.8 may be trivial. You should download +the source tarball of python-apt and run the tool utils/migrate-0.8 using +Python 2.6 over your code:: + + python2.6 utils/migrate-0.8.py -c myapp.py mypackage/ + +This will search your code for places where possibly deprecated names are +used. Using the argument ``-c``, you can turn colorized output on. + +Now that you know which parts of your code have to be changed, you have to know +how to do this. For classes, please look at the table. For all attributes, +methods, functions, and their parameters the following rules apply: + + 1. Replace leading [A-Z] with [a-z] (e.g DescURI => descURI) + 2. Replace multiple [A-Z] with [A-Z][a-z] (e.g. descURI => descUri) + 3. Replace every [A-Z] with the corresponding [a-z] (descUri => desc_uri) + +As an exception, refixes such as 'de' (e.g. 'dequote') or 'un' (e.g. 'unlock') +are normally not seperated by underscores from the next word. There are also +some other exceptions which are listed here, and apply to any name containing +this word: **filename**, **filesize**, **destdir**, **destfile**, **dequote**, +**unlock**, **reinstall**, **pinfile**, **REINSTREQ**, **UNPACKED**, +**parse_commandline**. diff --git a/python/acquire.cc b/python/acquire.cc index 1b1c5dd8..5f38f7bd 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -40,9 +40,9 @@ MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthE static PyGetSetDef AcquireItemGetSet[] = { {"complete",AcquireItemGetComplete}, {"desc_uri",AcquireItemGetDescURI}, - {"dest_file",AcquireItemGetDestFile}, + {"destfile",AcquireItemGetDestFile}, {"error_text",AcquireItemGetErrorText}, - {"file_size",AcquireItemGetFileSize}, + {"filesize",AcquireItemGetFileSize}, {"is",AcquireItemGetID}, {"is_trusted",AcquireItemGetIsTrusted}, {"local",AcquireItemGetLocal}, @@ -310,7 +310,7 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject int size = 0; uri = md5 = descr = shortDescr = destDir = destFile = ""; - char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortdescr", + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "short_descr", "destdir", "destfile", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, @@ -335,8 +335,8 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject static char *doc_PkgAcquireFile = - "AcquireFile(owner, uri[, md5, size, descr, short_descr, dest_dir," - "dest_file]) -> New AcquireFile() object\n\n" + "AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir," + "destfile]) -> New AcquireFile() object\n\n" "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" "*destdir* OR *destfile* to specify the destination directory/file."; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index bfabc652..403e0ebf 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -407,7 +407,7 @@ static PyMethodDef methods[] = // Locking {"get_lock",GetLock,METH_VARARGS,doc_GetLock}, {"pkgsystem_lock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, - {"pkgsystem_un_lock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, + {"pkgsystem_unlock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, #ifdef COMPAT_0_7 {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, @@ -418,7 +418,7 @@ static PyMethodDef methods[] = {"read_config_file",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"read_config_dir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, {"read_config_file_isc",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, - {"parse_command_line",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, + {"parse_commandline",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, #ifdef COMPAT_0_7 {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, @@ -452,10 +452,10 @@ static PyMethodDef methods[] = // Strings {"check_domain_list",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, {"quote_string",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, - {"de_quote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, + {"dequote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, {"size_to_str",StrSizeToStr,METH_VARARGS,"SizeToStr(int) -> String"}, {"time_to_str",StrTimeToStr,METH_VARARGS,"TimeToStr(int) -> String"}, - {"uri_to_file_name",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, + {"uri_to_filename",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, {"base64_encode",StrBase64Encode,METH_VARARGS,"Base64Encode(String) -> String"}, {"string_to_bool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, {"time_rfc1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, @@ -657,7 +657,7 @@ extern "C" void initapt_pkg() #endif // CurState PyModule_AddIntConstant(Module,"CURSTATE_NOT_INSTALLED",pkgCache::State::NotInstalled); - PyModule_AddIntConstant(Module,"CURSTATE_UN_PACKED",pkgCache::State::UnPacked); + PyModule_AddIntConstant(Module,"CURSTATE_UNPACKED",pkgCache::State::UnPacked); PyModule_AddIntConstant(Module,"CURSTATE_HALF_CONFIGURED",pkgCache::State::HalfConfigured); PyModule_AddIntConstant(Module,"CURSTATE_HALF_INSTALLED",pkgCache::State::HalfInstalled); PyModule_AddIntConstant(Module,"CURSTATE_CONFIG_FILES",pkgCache::State::ConfigFiles); @@ -666,13 +666,13 @@ extern "C" void initapt_pkg() PyModule_AddIntConstant(Module,"SELSTATE_UNKNOWN",pkgCache::State::Unknown); PyModule_AddIntConstant(Module,"SELSTATE_INSTALL",pkgCache::State::Install); PyModule_AddIntConstant(Module,"SELSTATE_HOLD",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"SELSTATE_DE_INSTALL",pkgCache::State::DeInstall); + PyModule_AddIntConstant(Module,"SELSTATE_DEINSTALL",pkgCache::State::DeInstall); PyModule_AddIntConstant(Module,"SELSTATE_PURGE",pkgCache::State::Purge); // InstState PyModule_AddIntConstant(Module,"INSTSTATE_OK",pkgCache::State::Ok); - PyModule_AddIntConstant(Module,"INSTSTATE_RE_INST_REQ",pkgCache::State::ReInstReq); + PyModule_AddIntConstant(Module,"INSTSTATE_REINSTREQ",pkgCache::State::ReInstReq); PyModule_AddIntConstant(Module,"INSTSTATE_HOLD",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_RE_INST_REQ",pkgCache::State::HoldReInstReq); + PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_REINSTREQ",pkgCache::State::HoldReInstReq); #ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"CurStateNotInstalled",pkgCache::State::NotInstalled); diff --git a/python/cache.cc b/python/cache.cc index 21a6a872..d09e22f3 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -1030,7 +1030,7 @@ static PyGetSetDef PackageFileGetSet[] = { {(char*)"architecture",PackageFile_GetArchitecture}, {(char*)"archive",PackageFile_GetArchive}, {(char*)"component",PackageFile_GetComponent}, - {(char*)"file_name",PackageFile_GetFileName}, + {(char*)"filename",PackageFile_GetFileName}, {(char*)"id",PackageFile_GetID}, {(char*)"index_type",PackageFile_GetIndexType}, {(char*)"label",PackageFile_GetLabel}, diff --git a/python/configuration.cc b/python/configuration.cc index 7b08d90e..81dd78ac 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -462,7 +462,7 @@ static PyMethodDef CnfMethods[] = // Others {"set",CnfSet,METH_VARARGS,doc_Set}, {"exists",CnfExists,METH_VARARGS,doc_Exists}, - {"sub_tree",CnfSubTree,METH_VARARGS,doc_SubTree}, + {"subtree",CnfSubTree,METH_VARARGS,doc_SubTree}, {"list",CnfList,METH_VARARGS,doc_List}, {"value_list",CnfValueList,METH_VARARGS,doc_ValueList}, {"my_tag",CnfMyTag,METH_VARARGS,doc_MyTag}, diff --git a/python/depcache.cc b/python/depcache.cc index 650dcb23..f69802f8 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -535,13 +535,13 @@ static PyMethodDef PkgDepCacheMethods[] = // global cache operations {"upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, {"fix_broken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, - {"read_pin_file",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, + {"read_pinfile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, {"minimize_upgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, // Manipulators {"mark_keep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, {"mark_delete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, {"mark_install",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, - {"set_re_install",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, + {"set_reinstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, // state information {"is_upgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, {"is_now_broken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 48440387..212e4ab0 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -120,7 +120,7 @@ static PyObject *PkgRecordsGetRecord(PyObject *Self,void*) { return PyString_FromStringAndSize(start,stop-start); } static PyGetSetDef PkgRecordsGetSet[] = { - {"file_name",PkgRecordsGetFileName}, + {"filename",PkgRecordsGetFileName}, {"homepage",PkgRecordsGetHomepage}, {"long_desc",PkgRecordsGetLongDesc}, {"md5_hash",PkgRecordsGetMD5Hash}, -- cgit v1.2.3 From 1040f7f6ec9cf689d6530827348a63daad52b3ef Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 8 Jun 2009 17:17:48 +0200 Subject: python/generic.h,tag.cc,configuration.cc: Use tp_alloc/tp_free instead of PyObject_NEW/DEL This allows us to finally implement subclassing. Previously deletion of an instance of a subclass caused segmentation faults, this is not the case anymore. --- python/configuration.cc | 3 ++- python/generic.h | 12 ++++++------ python/tag.cc | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/configuration.cc b/python/configuration.cc index 81dd78ac..3c6ea88c 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -161,7 +161,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) } // Create a new sub configuration. - SubConfiguration *New = PyObject_NEW(SubConfiguration,&ConfigurationSubType); + SubConfiguration *New = (SubConfiguration*)(&ConfigurationSubType) + ->tp_alloc(&ConfigurationSubType,0); new (&New->Object) Configuration(Itm); New->Owner = Self; Py_INCREF(Self); diff --git a/python/generic.h b/python/generic.h index ae2871e3..df4d8755 100644 --- a/python/generic.h +++ b/python/generic.h @@ -99,7 +99,7 @@ inline PyObject *GetOwner(PyObject *Obj) template inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type) { - CppPyObject *New = PyObject_NEW(CppPyObject,Type); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T; return New; } @@ -107,7 +107,7 @@ inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type) template inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type,A const &Arg) { - CppPyObject *New = PyObject_NEW(CppPyObject,Type); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); return New; } @@ -116,7 +116,7 @@ template inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, PyTypeObject *Type) { - CppOwnedPyObject *New = PyObject_NEW(CppOwnedPyObject,Type); + CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T; New->Owner = Owner; Py_INCREF(Owner); @@ -127,7 +127,7 @@ template inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, PyTypeObject *Type,A const &Arg) { - CppOwnedPyObject *New = PyObject_NEW(CppOwnedPyObject,Type); + CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); New->Owner = Owner; if (Owner != 0) @@ -140,7 +140,7 @@ template void CppDealloc(PyObject *Obj) { GetCpp(Obj).~T(); - PyObject_DEL(Obj); + Obj->ob_type->tp_free(Obj); } template @@ -150,7 +150,7 @@ void CppOwnedDealloc(PyObject *iObj) Obj->Object.~T(); if (Obj->Owner != 0) Py_DECREF(Obj->Owner); - PyObject_DEL(Obj); + iObj->ob_type->tp_free(iObj); } inline PyObject *CppPyString(std::string Str) diff --git a/python/tag.cc b/python/tag.cc index 5a31488c..31491c90 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); - PyObject_DEL(Obj); + Obj->ob_type->tp_free(Obj); } /*}}}*/ @@ -246,7 +246,7 @@ static PyObject *TagSecNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { return 0; // Create the object.. - TagSecData *New = PyObject_NEW(TagSecData,type); + TagSecData *New = (TagSecData*)type->tp_alloc(type, 0); new (&New->Object) pkgTagSection(); New->Data = new char[strlen(Data)+2]; snprintf(New->Data,strlen(Data)+2,"%s\n",Data); @@ -286,14 +286,14 @@ static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) if (fileno == -1) return 0; - TagFileData *New = PyObject_NEW(TagFileData,type); + TagFileData *New = (TagFileData*)type->tp_alloc(type, 0); new (&New->Fd) FileFd(fileno,false); New->File = File; Py_INCREF(New->File); new (&New->Object) pkgTagFile(&New->Fd); // Create the section - New->Section = PyObject_NEW(TagSecData,&TagSecType); + New->Section = (TagSecData*)(&TagSecType)->tp_alloc(&TagSecType, 0); new (&New->Section->Object) pkgTagSection(); New->Section->Data = 0; -- cgit v1.2.3 From f652213b76f72382bab21e730bf0ccc4419a1267 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 9 Jun 2009 18:10:19 +0200 Subject: Allow types providing __new__() to be subclassed. --- debian/changelog | 3 ++- python/acquire.cc | 6 ++++-- python/cache.cc | 3 ++- python/cdrom.cc | 3 ++- python/configuration.cc | 3 ++- python/depcache.cc | 9 ++++++--- python/hashstring.cc | 3 ++- python/indexrecords.cc | 3 ++- python/pkgmanager.cc | 3 ++- python/pkgrecords.cc | 3 ++- python/pkgsrcrecords.cc | 3 ++- python/sourcelist.cc | 3 ++- python/tag.cc | 6 ++++-- 13 files changed, 34 insertions(+), 17 deletions(-) (limited to 'python/configuration.cc') diff --git a/debian/changelog b/debian/changelog index 1a80d081..818bf630 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,9 @@ python-apt (0.7.92) experimental; urgency=low * Add apt_pkg.HashString and apt_pkg.IndexRecords (Closes: #456141) + * Allow types providing __new__() to be subclassed. - -- Julian Andres Klode Mon, 08 Jun 2009 17:23:37 +0200 + -- Julian Andres Klode Tue, 09 Jun 2009 18:09:53 +0200 python-apt (0.7.91) experimental; urgency=low diff --git a/python/acquire.cc b/python/acquire.cc index 05bffc65..702d48ce 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -276,7 +276,8 @@ PyTypeObject PkgAcquireType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_PkgAcquire, // tp_doc 0, // tp_traverse 0, // tp_clear @@ -366,7 +367,8 @@ PyTypeObject PkgAcquireFileType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_PkgAcquireFile, // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/cache.cc b/python/cache.cc index c988145f..14484104 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -331,7 +331,8 @@ PyTypeObject PkgCacheType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT , // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_PkgCache, // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/cdrom.cc b/python/cdrom.cc index 3e63a89c..e98947d1 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -108,7 +108,8 @@ PyTypeObject PkgCdromType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "Cdrom Object", // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/configuration.cc b/python/configuration.cc index 3c6ea88c..365a35fd 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -526,7 +526,8 @@ PyTypeObject ConfigurationType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "Configuration Object", // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/depcache.cc b/python/depcache.cc index a69e0723..f1c34fef 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -675,7 +675,8 @@ PyTypeObject PkgDepCacheType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_PkgDepCache, // tp_doc 0, // tp_traverse 0, // tp_clear @@ -858,7 +859,8 @@ PyTypeObject PkgProblemResolverType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "ProblemResolver Object", // tp_doc 0, // tp_traverse 0, // tp_clear @@ -975,7 +977,8 @@ PyTypeObject PkgActionGroupType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_PkgActionGroup, // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/hashstring.cc b/python/hashstring.cc index 71ae5bf4..58bcca9e 100644 --- a/python/hashstring.cc +++ b/python/hashstring.cc @@ -118,7 +118,8 @@ PyTypeObject PyHashString_Type = { 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), HashString_doc, // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 35e41c59..61ff07fc 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -104,7 +104,8 @@ PyTypeObject PyIndexRecords_Type = { 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), IndexRecords_doc, // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 7752ce5b..f47e77ad 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -153,7 +153,8 @@ PyTypeObject PkgManagerType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "PackageManager Object", // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 6022097a..8beefffd 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -186,7 +186,8 @@ PyTypeObject PkgRecordsType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "Records Object", // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 50445432..e6b78a83 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -228,7 +228,8 @@ PyTypeObject PkgSrcRecordsType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "SourceRecords Object", // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 1c05d83e..5e5838d8 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -138,7 +138,8 @@ PyTypeObject PkgSourceListType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), "pkgSourceList Object", // tp_doc 0, // tp_traverse 0, // tp_clear diff --git a/python/tag.cc b/python/tag.cc index 31491c90..7e7eb21c 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -434,7 +434,8 @@ PyTypeObject TagSecType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_TagSec, // tp_doc 0, // tp_traverse 0, // tp_clear @@ -521,7 +522,8 @@ PyTypeObject TagFileType = 0, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), doc_TagFile, // tp_doc 0, // tp_traverse 0, // tp_clear -- cgit v1.2.3 From c41d1e0c66ab4effdf737ca4c9a9c86c08237451 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 23 Jun 2009 11:39:09 +0200 Subject: python/configuration.cc: Make ConfigurationPtr,ConfigurationSub subclasses of Configuration. This makes isinstance(apt_pkg.config, apt_pkg.Configuration) return True instead of False. --- debian/changelog | 1 + python/configuration.cc | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'python/configuration.cc') diff --git a/debian/changelog b/debian/changelog index c4486505..3209f7ee 100644 --- a/debian/changelog +++ b/debian/changelog @@ -20,6 +20,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low * Merge 0.7.10.4 from unstable * debian/control: Update Standards-Version to 3.8.2 * Make AcquireFile a subclass of AcquireItem + * Make ConfigurationPtr,ConfigurationSub subclasses of Configuration. [ Sebastian Heinlein ] * apt/progress.py: Extract the package name from the status message diff --git a/python/configuration.cc b/python/configuration.cc index 365a35fd..9ef5967b 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -582,6 +582,9 @@ PyTypeObject ConfigurationPtrType = 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + &ConfigurationType, // tp_base }; PyTypeObject ConfigurationSubType = @@ -618,5 +621,8 @@ PyTypeObject ConfigurationSubType = 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + &ConfigurationType, // tp_base }; -- cgit v1.2.3 From e80500e7173387acc7a6b6be9d7424a4343ec036 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 25 Jun 2009 18:53:47 +0200 Subject: python: Use PyVarObject_HEAD_INIT() instead of PyObject_HEAD_INIT(). This is related to PEP 3123 and fixes some compiler warnings. --- python/acquire.cc | 17 ++++------------- python/cache.cc | 45 +++++++++------------------------------------ python/cdrom.cc | 5 +---- python/configuration.cc | 15 +++------------ python/depcache.cc | 15 +++------------ python/generic.h | 1 + python/hashstring.cc | 5 +---- python/indexfile.cc | 5 +---- python/indexrecords.cc | 5 +---- python/metaindex.cc | 5 +---- python/pkgmanager.cc | 5 +---- python/pkgrecords.cc | 5 +---- python/pkgsrcrecords.cc | 5 +---- python/policy.cc | 5 +---- python/sourcelist.cc | 5 +---- python/tag.cc | 12 ++++-------- 16 files changed, 34 insertions(+), 121 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index a36012bc..6c6c2ea4 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -105,10 +105,7 @@ static PyObject *AcquireItemRepr(PyObject *Self) PyTypeObject AcquireItemType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItem", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -267,10 +264,7 @@ static char *doc_PkgAcquire = "Acquire(progress) -> Acquire() object.\n\n" PyTypeObject PkgAcquireType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Acquire", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize @@ -360,11 +354,8 @@ static char *doc_PkgAcquireFile = PyTypeObject PkgAcquireFileType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif - "apt_pkg.AcquireFile", // tp_name + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireFile", // tp_name sizeof(CppOwnedPyObject),// tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/cache.cc b/python/cache.cc index 0f5e27eb..a571788f 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -299,10 +299,7 @@ static char *doc_PkgCache = "Cache([progress]) -> Cache() object.\n\n" static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -349,10 +346,7 @@ PyTypeObject PkgCacheType = // --------------------------------------------------------------------- PyTypeObject PkgCacheFileType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "pkgCacheFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -425,10 +419,7 @@ static PySequenceMethods PkgListSeq = PyTypeObject PkgListType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageList", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -550,10 +541,7 @@ static PyObject *PackageRepr(PyObject *Self) PyTypeObject PackageType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Package", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -641,10 +629,7 @@ static PyObject *DescriptionRepr(PyObject *Self) PyTypeObject DescriptionType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Description", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -904,10 +889,7 @@ static PyGetSetDef VersionGetSet[] = { PyTypeObject VersionType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Version", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -1068,10 +1050,7 @@ static PyGetSetDef PackageFileGetSet[] = { }; PyTypeObject PackageFileType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -1243,10 +1222,7 @@ static PyGetSetDef DependencyGetSet[] = { PyTypeObject DependencyType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Dependency", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -1331,10 +1307,7 @@ static PySequenceMethods RDepListSeq = PyTypeObject RDepListType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DependencyList", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/cdrom.cc b/python/cdrom.cc index e2651670..492afd90 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -85,10 +85,7 @@ static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) PyTypeObject PkgCdromType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cdrom", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/configuration.cc b/python/configuration.cc index 9ef5967b..07f55957 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -503,10 +503,7 @@ static PySequenceMethods ConfigurationSeq = {0,0,0,0,0,0,0,CnfContains,0,0}; static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; PyTypeObject ConfigurationType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize @@ -550,10 +547,7 @@ PyTypeObject ConfigurationType = PyTypeObject ConfigurationPtrType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ConfigurationPtr", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize @@ -589,10 +583,7 @@ PyTypeObject ConfigurationPtrType = PyTypeObject ConfigurationSubType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ConfigurationSub", // tp_name sizeof(SubConfiguration), // tp_basicsize 0, // tp_itemsize diff --git a/python/depcache.cc b/python/depcache.cc index 9c0c9a6f..2ce7a595 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -667,10 +667,7 @@ static char *doc_PkgDepCache = "DepCache(cache) -> DepCache() object\n\n" "The parameter *cache* refers to an apt_pkg.Cache() object."; PyTypeObject PkgDepCacheType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DepCache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -858,10 +855,7 @@ static PyMethodDef PkgProblemResolverMethods[] = PyTypeObject PkgProblemResolverType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ProblemResolver", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize @@ -977,10 +971,7 @@ static char *doc_PkgActionGroup = "ActionGroup(depcache)\n\n" PyTypeObject PkgActionGroupType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ActionGroup", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/generic.h b/python/generic.h index 182b1b53..118917cb 100644 --- a/python/generic.h +++ b/python/generic.h @@ -63,6 +63,7 @@ typedef int Py_ssize_t; #define PyBytes_Check PyString_Check #define PyBytes_AsString PyString_AsString #define PyBytes_AsStringAndSize PyString_AsStringAndSize +#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, #endif #endif diff --git a/python/hashstring.cc b/python/hashstring.cc index 23212a4b..6f70ac7e 100644 --- a/python/hashstring.cc +++ b/python/hashstring.cc @@ -95,10 +95,7 @@ static char *HashString_doc = " HashString('MD5Sum', '6cc1b6e6655e3555ac47e5b5fe26d04e')\n\n" "Valid options for 'type' are: MD5Sum, SHA1, SHA256."; PyTypeObject PyHashString_Type = { - PyObject_HEAD_INIT(&PyType_Type) -#if PY_MAJOR_VERSION < 3 - 0, // ob_size -#endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.HashString", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/indexfile.cc b/python/indexfile.cc index 73f76ce6..5b526b87 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -90,10 +90,7 @@ static PyGetSetDef PackageIndexFileGetSet[] = { PyTypeObject PackageIndexFileType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageIndexFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/indexrecords.cc b/python/indexrecords.cc index fcb2b85d..588cf883 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -81,10 +81,7 @@ static PyMethodDef IndexRecords_Methods[] = { static char *IndexRecords_doc = "IndexRecords()\n\n" "Representation of a release file."; PyTypeObject PyIndexRecords_Type = { - PyObject_HEAD_INIT(&PyType_Type) -#if PY_MAJOR_VERSION < 3 - 0, // ob_size -#endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.IndexRecords", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/metaindex.cc b/python/metaindex.cc index b5d194b4..87b1e59a 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -72,10 +72,7 @@ static PyObject *MetaIndexRepr(PyObject *Self) PyTypeObject MetaIndexType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.MetaIndex", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 668f7cfc..9e9cc32d 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -133,10 +133,7 @@ static PyGetSetDef PkgManagerGetSet[] = { PyTypeObject PkgManagerType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageManager", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 4a3c80db..886bdb58 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -163,10 +163,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) PyTypeObject PkgRecordsType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageRecords", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 9707dce2..187050b7 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -204,10 +204,7 @@ static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kw PyTypeObject PkgSrcRecordsType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceRecords", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/policy.cc b/python/policy.cc index 5150af91..91ed5454 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -143,10 +143,7 @@ static char *Policy_doc = "Policy(cache)\n\n" "may be some cases where a special policy class is needed."; PyTypeObject PyPolicy_Type = { - PyObject_HEAD_INIT(&PyType_Type) -#if PY_MAJOR_VERSION < 3 - 0, // ob_size -#endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Policy", // tp_name sizeof(CppOwnedPyObject),// tp_basicsize 0, // tp_itemsize diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 2cf5eea9..0820d5bf 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -115,10 +115,7 @@ static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kw PyTypeObject PkgSourceListType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceList", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize diff --git a/python/tag.cc b/python/tag.cc index 1ad0a465..2b71517d 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -175,6 +175,7 @@ static PyObject *TagSecKeys(PyObject *Self,PyObject *Args) return List; } +#if PY_MAJOR_VERSION < 3 static char *doc_Exists = "Exists(Name) -> integer"; static PyObject *TagSecExists(PyObject *Self,PyObject *Args) { @@ -188,6 +189,7 @@ static PyObject *TagSecExists(PyObject *Self,PyObject *Args) return Py_BuildValue("i",0); return Py_BuildValue("i",1); } +#endif static int TagSecContains(PyObject *Self,PyObject *Arg) { @@ -436,10 +438,7 @@ static char *doc_TagSec = "TagSection(text) -> Create a new object.\n\n" "to the functions provided by the C++ class (e.g. Find)"; PyTypeObject TagSecType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.TagSection", // tp_name sizeof(TagSecData), // tp_basicsize 0, // tp_itemsize @@ -525,10 +524,7 @@ static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" // Type for a Tag File PyTypeObject TagFileType = { - PyObject_HEAD_INIT(&PyType_Type) - #if PY_MAJOR_VERSION < 3 - 0, // ob_size - #endif + PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.TagFile", // tp_name sizeof(TagFileData), // tp_basicsize 0, // tp_itemsize -- cgit v1.2.3 From dabc8c6796afdaf0e2918db77117a07eae8b1fd4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Jul 2009 14:25:06 +0200 Subject: python: Rename all PyTypeObject's to conform to PEP 7. This is the first step towards implementing coding guidelines for the C++ code and providing an usable C++ API. --- python/acquire.cc | 18 +++++++------- python/apt_pkgmodule.cc | 62 +++++++++++++++++++++++------------------------ python/apt_pkgmodule.h | 60 +++++++++++++++++++++++----------------------- python/cache.cc | 60 +++++++++++++++++++++++----------------------- python/cdrom.cc | 4 ++-- python/configuration.cc | 16 ++++++------- python/depcache.cc | 64 ++++++++++++++++++++++++------------------------- python/indexfile.cc | 2 +- python/metaindex.cc | 4 ++-- python/pkgmanager.cc | 12 +++++----- python/pkgrecords.cc | 8 +++---- python/pkgsrcrecords.cc | 6 ++--- python/policy.cc | 12 +++++----- python/sourcelist.cc | 14 +++++------ python/tag.cc | 12 +++++----- 15 files changed, 177 insertions(+), 177 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index 054956ea..4329e790 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -140,7 +140,7 @@ static void AcquireItemDealloc(PyObject *self) { -PyTypeObject AcquireItemType = +PyTypeObject PyAcquireItem_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItem", // tp_name @@ -238,7 +238,7 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) I != fetcher->ItemsEnd(); I++) { PyAcquireItemObject *Obj; - Obj = CppOwnedPyObject_NEW(Self,&AcquireItemType,*I); + Obj = CppOwnedPyObject_NEW(Self,&PyAcquireItem_Type,*I); Obj->NoDelete = true; PyList_Append(List,Obj); ((PyAcquireObject *)Self)->items.push_back(Obj); @@ -305,7 +305,7 @@ static char *doc_PkgAcquire = "Acquire(progress) -> Acquire() object.\n\n" "specify a apt.progress.FetchProgress() object, which will display the\n" "progress of the fetching."; -PyTypeObject PkgAcquireType = +PyTypeObject PyAcquire_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Acquire", // tp_name @@ -354,7 +354,7 @@ PyObject *GetAcquire(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetAcquire() is deprecated." " Please see apt_pkg.Acquire() for the replacement.", 1); - return PkgAcquireNew(&PkgAcquireType,Args,0); + return PkgAcquireNew(&PyAcquire_Type,Args,0); } #endif @@ -369,7 +369,7 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject "destdir", "destfile", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PkgAcquireType, &pyfetcher, &uri, &md5, + &PyAcquire_Type, &pyfetcher, &uri, &md5, &size, &descr, &shortDescr, &destDir, &destFile) == 0) return 0; @@ -397,7 +397,7 @@ static char *doc_PkgAcquireFile = "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" "*destdir* OR *destfile* to specify the destination directory/file."; -PyTypeObject PkgAcquireFileType = +PyTypeObject PyAcquireFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireFile", // tp_name @@ -432,7 +432,7 @@ PyTypeObject PkgAcquireFileType = 0, // tp_methods 0, // tp_members 0, // tp_getset - &AcquireItemType, // tp_base + &PyAcquireItem_Type, // tp_base 0, // tp_dict 0, // tp_descr_get 0, // tp_descr_set @@ -459,7 +459,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) "destDir", "destFile", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PkgAcquireType, &pyfetcher, &uri, &md5, + &PyAcquire_Type, &pyfetcher, &uri, &md5, &size, &descr, &shortDescr, &destDir, &destFile) == 0) return 0; @@ -472,7 +472,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) shortDescr, destDir, destFile); // short-desc - CppPyObject *AcqFileObj = CppPyObject_NEW(&PkgAcquireFileType); + CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); AcqFileObj->Object = af; AcqFileObj->NoDelete = true; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 4c0fd5ed..d236820a 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -36,7 +36,7 @@ static PyObject *newConfiguration(PyObject *self,PyObject *args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " "deprecated. Use apt_pkg.Configuration() instead.", 1); - return CppPyObject_NEW(&ConfigurationType); + return CppPyObject_NEW(&PyConfiguration_Type); } #endif /*}}}*/ @@ -556,9 +556,9 @@ extern "C" void initapt_pkg() #endif { // Finalize our types to add slots, etc. - if (PyType_Ready(&ConfigurationPtrType) == -1) INIT_ERROR; - if (PyType_Ready(&ConfigurationSubType) == -1) INIT_ERROR; - if (PyType_Ready(&PkgCacheFileType) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfigurationPtr_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfigurationSub_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyCacheFile_Type) == -1) INIT_ERROR; // Initialize the module #if PY_MAJOR_VERSION >= 3 @@ -568,7 +568,7 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppPyObject *Config = CppPyObject_NEW(&ConfigurationPtrType); + CppPyObject *Config = CppPyObject_NEW(&PyConfigurationPtr_Type); Config->Object = _config; PyModule_AddObject(Module,"config",Config); #ifdef COMPAT_0_7 @@ -578,43 +578,43 @@ extern "C" void initapt_pkg() // Add our classes. /* ============================ tag.cc ============================ */ - ADDTYPE(Module,"TagSection",&TagSecType); - ADDTYPE(Module,"TagFile",&TagFileType); + ADDTYPE(Module,"TagSection",&PyTagSection_Type); + ADDTYPE(Module,"TagFile",&PyTagFile_Type); /* ============================ acquire.cc ============================ */ - ADDTYPE(Module,"Acquire",&PkgAcquireType); - ADDTYPE(Module,"AcquireFile",&PkgAcquireFileType); - ADDTYPE(Module,"AcquireItem",&AcquireItemType); // NO __new__() + ADDTYPE(Module,"Acquire",&PyAcquire_Type); + ADDTYPE(Module,"AcquireFile",&PyAcquireFile_Type); + ADDTYPE(Module,"AcquireItem",&PyAcquireItem_Type); // NO __new__() /* ============================ cache.cc ============================ */ - ADDTYPE(Module,"Cache",&PkgCacheType); - ADDTYPE(Module,"Dependency",&DependencyType); // NO __new__() - ADDTYPE(Module,"Description",&DescriptionType); // NO __new__() - ADDTYPE(Module,"PackageFile",&PackageFileType); // NO __new__() - ADDTYPE(Module,"PackageList",&PkgListType); // NO __new__(), internal - ADDTYPE(Module,"DependencyList",&RDepListType); // NO __new__(), internal - ADDTYPE(Module,"Package",&PackageType); // NO __new__() - ADDTYPE(Module,"Version",&VersionType); // NO __new__() + ADDTYPE(Module,"Cache",&PyCache_Type); + ADDTYPE(Module,"Dependency",&PyDependency_Type); // NO __new__() + ADDTYPE(Module,"Description",&PyDescription_Type); // NO __new__() + ADDTYPE(Module,"PackageFile",&PyPackageFile_Type); // NO __new__() + ADDTYPE(Module,"PackageList",&PyPackageList_Type); // NO __new__(), internal + ADDTYPE(Module,"DependencyList",&PyDependencyList_Type); // NO __new__(), internal + ADDTYPE(Module,"Package",&PyPackage_Type); // NO __new__() + ADDTYPE(Module,"Version",&PyVersion_Type); // NO __new__() /* ============================ cdrom.cc ============================ */ - ADDTYPE(Module,"Cdrom",&PkgCdromType); + ADDTYPE(Module,"Cdrom",&PyCdrom_Type); /* ========================= configuration.cc ========================= */ - ADDTYPE(Module,"Configuration",&ConfigurationType); - //ADDTYPE(Module,"ConfigurationSub",&ConfigurationSubType); // NO __new__() - //ADDTYPE(Module,"ConfigurationPtr",&ConfigurationPtrType); // NO __new__() + ADDTYPE(Module,"Configuration",&PyConfiguration_Type); + //ADDTYPE(Module,"ConfigurationSub",&PyConfigurationSub_Type); // NO __new__() + //ADDTYPE(Module,"ConfigurationPtr",&PyConfigurationPtr_Type); // NO __new__() /* ========================= depcache.cc ========================= */ - ADDTYPE(Module,"ActionGroup",&PkgActionGroupType); - ADDTYPE(Module,"DepCache",&PkgDepCacheType); - ADDTYPE(Module,"ProblemResolver",&PkgProblemResolverType); + ADDTYPE(Module,"ActionGroup",&PyActionGroup_Type); + ADDTYPE(Module,"DepCache",&PyDepCache_Type); + ADDTYPE(Module,"ProblemResolver",&PyProblemResolver_Type); /* ========================= indexfile.cc ========================= */ - ADDTYPE(Module,"PackageIndexFile",&PackageIndexFileType); // NO __new__() + ADDTYPE(Module,"PackageIndexFile",&PyPackageIndexFile_Type); // NO __new__() /* ========================= metaindex.cc ========================= */ - ADDTYPE(Module,"MetaIndex",&MetaIndexType); // NO __new__() + ADDTYPE(Module,"MetaIndex",&PyMetaIndex_Type); // NO __new__() /* ========================= pkgmanager.cc ========================= */ - ADDTYPE(Module,"PackageManager",&PkgManagerType); + ADDTYPE(Module,"PackageManager",&PyPackageManager_Type); /* ========================= pkgrecords.cc ========================= */ - ADDTYPE(Module,"PackageRecords",&PkgRecordsType); + ADDTYPE(Module,"PackageRecords",&PyPackageRecords_Type); /* ========================= pkgsrcrecords.cc ========================= */ - ADDTYPE(Module,"SourceRecords",&PkgSrcRecordsType); + ADDTYPE(Module,"SourceRecords",&PySourceRecords_Type); /* ========================= sourcelist.cc ========================= */ - ADDTYPE(Module,"SourceList",&PkgSourceListType); + ADDTYPE(Module,"SourceList",&PySourceList_Type); ADDTYPE(Module,"IndexRecords",&PyIndexRecords_Type); ADDTYPE(Module,"HashString",&PyHashString_Type); ADDTYPE(Module,"Policy",&PyPolicy_Type); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 1a2f1a1a..7b835ca8 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -14,13 +14,13 @@ #include // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &ConfigurationType || \ - (op)->ob_type == &ConfigurationPtrType || \ - (op)->ob_type == &ConfigurationSubType) -extern PyTypeObject ConfigurationType; -extern PyTypeObject ConfigurationPtrType; -extern PyTypeObject ConfigurationSubType; -extern PyTypeObject VersionType; +#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type || \ + (op)->ob_type == &PyConfigurationPtr_Type || \ + (op)->ob_type == &PyConfigurationSub_Type) +extern PyTypeObject PyConfiguration_Type; +extern PyTypeObject PyConfigurationPtr_Type; +extern PyTypeObject PyConfigurationSub_Type; +extern PyTypeObject PyVersion_Type; extern char *doc_LoadConfig; extern char *doc_LoadConfigISC; @@ -32,8 +32,8 @@ PyObject *LoadConfigDir(PyObject *Self,PyObject *Args); PyObject *ParseCommandLine(PyObject *Self,PyObject *Args); // Tag File Stuff -extern PyTypeObject TagSecType; -extern PyTypeObject TagFileType; +extern PyTypeObject PyTagSection_Type; +extern PyTypeObject PyTagFile_Type; extern char *doc_ParseSection; extern char *doc_ParseTagFile; extern char *doc_RewriteSection; @@ -54,58 +54,58 @@ PyObject *StrStrToTime(PyObject *self,PyObject *Args); PyObject *StrCheckDomainList(PyObject *Self,PyObject *Args); // Cache Stuff -extern PyTypeObject PkgCacheType; -extern PyTypeObject PkgCacheFileType; -extern PyTypeObject PkgListType; -extern PyTypeObject DescriptionType; -extern PyTypeObject PackageType; -extern PyTypeObject PackageFileType; -extern PyTypeObject DependencyType; -extern PyTypeObject RDepListType; +extern PyTypeObject PyCache_Type; +extern PyTypeObject PyCacheFile_Type; +extern PyTypeObject PyPackageList_Type; +extern PyTypeObject PyDescription_Type; +extern PyTypeObject PyPackage_Type; +extern PyTypeObject PyPackageFile_Type; +extern PyTypeObject PyDependency_Type; +extern PyTypeObject PyDependencyList_Type; PyObject *TmpGetCache(PyObject *Self,PyObject *Args); // DepCache -extern PyTypeObject PkgDepCacheType; +extern PyTypeObject PyDepCache_Type; PyObject *GetDepCache(PyObject *Self,PyObject *Args); // pkgProblemResolver -extern PyTypeObject PkgProblemResolverType; +extern PyTypeObject PyProblemResolver_Type; PyObject *GetPkgProblemResolver(PyObject *Self, PyObject *Args); PyObject *GetPkgActionGroup(PyObject *Self, PyObject *Args); -extern PyTypeObject PkgActionGroupType; +extern PyTypeObject PyActionGroup_Type; // cdrom -extern PyTypeObject PkgCdromType; +extern PyTypeObject PyCdrom_Type; PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire -extern PyTypeObject AcquireItemType; -extern PyTypeObject PkgAcquireType; -extern PyTypeObject PkgAcquireFileType; +extern PyTypeObject PyAcquireItem_Type; +extern PyTypeObject PyAcquire_Type; +extern PyTypeObject PyAcquireFile_Type; extern char *doc_GetPkgAcqFile; PyObject *GetAcquire(PyObject *Self,PyObject *Args); PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); // packagemanager -extern PyTypeObject PkgManagerType; +extern PyTypeObject PyPackageManager_Type; PyObject *GetPkgManager(PyObject *Self,PyObject *Args); // PkgRecords Stuff -extern PyTypeObject PkgRecordsType; -extern PyTypeObject PkgSrcRecordsType; +extern PyTypeObject PyPackageRecords_Type; +extern PyTypeObject PySourceRecords_Type; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); // pkgSourceList -extern PyTypeObject PkgSourceListType; +extern PyTypeObject PySourceList_Type; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); // pkgSourceList -extern PyTypeObject PackageIndexFileType; +extern PyTypeObject PyPackageIndexFile_Type; // metaIndex -extern PyTypeObject MetaIndexType; +extern PyTypeObject PyMetaIndex_Type; // HashString PyObject *PyHashString_FromCpp(HashString *obj); diff --git a/python/cache.cc b/python/cache.cc index 40d7b18a..d3a8a949 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -62,7 +62,7 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) { PyObject *Obj; PyObject *Ver; - Ver = CppOwnedPyObject_NEW(Owner,&VersionType, + Ver = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, I.OwnerVer()); Obj = Py_BuildValue("ssN",I.ParentPkg().Name(),I.ProvideVersion(), Ver); @@ -150,7 +150,7 @@ static PyMethodDef PkgCacheMethods[] = static PyObject *PkgCacheGetPackages(PyObject *Self, void*) { pkgCache *Cache = GetCpp(Self); - return CppOwnedPyObject_NEW(Self,&PkgListType,Cache->PkgBegin()); + return CppOwnedPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); } static PyObject *PkgCacheGetPackageCount(PyObject *Self, void*) { @@ -188,7 +188,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self,&PackageFileType,I); + Obj = CppOwnedPyObject_NEW(Self,&PyPackageFile_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -238,7 +238,7 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return 0; } - return CppOwnedPyObject_NEW(Self,&PackageType,Pkg); + return CppOwnedPyObject_NEW(Self,&PyPackage_Type,Pkg); } static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) @@ -279,7 +279,7 @@ static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) } CppOwnedPyObject *CacheFileObj = - CppOwnedPyObject_NEW(0,&PkgCacheFileType, Cache); + CppOwnedPyObject_NEW(0,&PyCacheFile_Type, Cache); CppOwnedPyObject *CacheObj = CppOwnedPyObject_NEW(CacheFileObj,type, @@ -299,7 +299,7 @@ static char *doc_PkgCache = "Cache([progress]) -> Cache() object.\n\n" "If not specified, the progress is displayed in simple text form."; static PyMappingMethods CacheMap = {0,CacheMapOp,0}; -PyTypeObject PkgCacheType = +PyTypeObject PyCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cache", // tp_name @@ -346,7 +346,7 @@ PyTypeObject PkgCacheType = /*}}}*/ // PkgCacheFile Class /*{{{*/ // --------------------------------------------------------------------- -PyTypeObject PkgCacheFileType = +PyTypeObject PyCacheFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "pkgCacheFile", // tp_name @@ -404,7 +404,7 @@ static PyObject *PkgListItem(PyObject *iSelf,Py_ssize_t Index) } } - return CppOwnedPyObject_NEW(GetOwner(iSelf),&PackageType, + return CppOwnedPyObject_NEW(GetOwner(iSelf),&PyPackage_Type, Self.Iter); } @@ -419,7 +419,7 @@ static PySequenceMethods PkgListSeq = 0 // assign slice }; -PyTypeObject PkgListType = +PyTypeObject PyPackageList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageList", // tp_name @@ -457,7 +457,7 @@ PyTypeObject PkgListType = MkGet(PackageGetName,PyString_FromString(Pkg.Name())); MkGet(PackageGetSection,Safe_FromString(Pkg.Section())); MkGet(PackageGetRevDependsList,CppOwnedPyObject_NEW(Owner, - &RDepListType, Pkg.RevDependsList())); + &PyDependencyList_Type, Pkg.RevDependsList())); MkGet(PackageGetProvidesList,CreateProvides(Owner,Pkg.ProvidesList())); MkGet(PackageGetSelectedState,Py_BuildValue("i",Pkg->SelectedState)); MkGet(PackageGetInstState,Py_BuildValue("i",Pkg->InstState)); @@ -479,7 +479,7 @@ static PyObject *PackageGetVersionList(PyObject *Self,void*) for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&VersionType,I); + Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -494,7 +494,7 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) Py_INCREF(Py_None); return Py_None; } - return CppOwnedPyObject_NEW(Owner,&VersionType, + return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, Pkg.CurrentVer()); } @@ -541,7 +541,7 @@ static PyObject *PackageRepr(PyObject *Self) return PyString_FromString(S); } -PyTypeObject PackageType = +PyTypeObject PyPackage_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Package", // tp_name @@ -599,7 +599,7 @@ static PyObject *DescriptionGetFileList(PyObject *Self,void*) { PyObject *DescFile; PyObject *Obj; - DescFile = CppOwnedPyObject_NEW(Owner,&PackageFileType,I.File()); + DescFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",DescFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -629,7 +629,7 @@ static PyObject *DescriptionRepr(PyObject *Self) return PyString_FromString(S); } -PyTypeObject DescriptionType = +PyTypeObject PyDescription_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Description", // tp_name @@ -711,7 +711,7 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver, { PyObject *Obj; if (AsObj == true) - Obj = CppOwnedPyObject_NEW(Owner,&DependencyType, + Obj = CppOwnedPyObject_NEW(Owner,&PyDependency_Type, Start); else { @@ -763,7 +763,7 @@ static PyObject *VersionGetFileList(PyObject *Self, void*) { { PyObject *PkgFile; PyObject *Obj; - PkgFile = CppOwnedPyObject_NEW(Owner,&PackageFileType,I.File()); + PkgFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",PkgFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -783,7 +783,7 @@ static PyObject *VersionGetDependsList(PyObject *Self, void*) { } static PyObject *VersionGetParentPkg(PyObject *Self, void*) { PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PackageType, + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, Version_GetVer(Self).ParentPkg()); } static PyObject *VersionGetProvidesList(PyObject *Self, void*) { @@ -815,7 +815,7 @@ static PyObject *VersionGetTranslatedDescription(PyObject *Self, void*) { pkgCache::VerIterator &Ver = GetCpp(Self); PyObject *Owner = GetOwner(Self); return CppOwnedPyObject_NEW(Owner, - &DescriptionType, + &PyDescription_Type, Ver.TranslatedDescription()); } @@ -889,7 +889,7 @@ static PyGetSetDef VersionGetSet[] = { {} }; -PyTypeObject VersionType = +PyTypeObject PyVersion_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Version", // tp_name @@ -1051,7 +1051,7 @@ static PyGetSetDef PackageFileGetSet[] = { {} }; -PyTypeObject PackageFileType = { +PyTypeObject PyPackageFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize @@ -1113,7 +1113,7 @@ static PyObject *DepSmartTargetPkg(PyObject *Self,PyObject *Args) return Py_None; } - return CppOwnedPyObject_NEW(Owner,&PackageType,P); + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type,P); } static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) @@ -1129,7 +1129,7 @@ static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) for (pkgCache::Version **I = Vers; *I != 0; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&VersionType, + Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, pkgCache::VerIterator(*Dep.Cache(),*I)); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -1163,7 +1163,7 @@ static PyObject *DependencyGetTargetPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PackageType, + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, Dep.TargetPkg()); } @@ -1171,7 +1171,7 @@ static PyObject *DependencyGetParentVer(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&VersionType, + return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, Dep.ParentVer()); } @@ -1179,7 +1179,7 @@ static PyObject *DependencyGetParentPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PackageType, + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, Dep.ParentPkg()); } @@ -1222,7 +1222,7 @@ static PyGetSetDef DependencyGetSet[] = { }; -PyTypeObject DependencyType = +PyTypeObject PyDependency_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Dependency", // tp_name @@ -1293,7 +1293,7 @@ static PyObject *RDepListItem(PyObject *iSelf,Py_ssize_t Index) } return CppOwnedPyObject_NEW(GetOwner(iSelf), - &DependencyType,Self.Iter); + &PyDependency_Type,Self.Iter); } static PySequenceMethods RDepListSeq = @@ -1307,7 +1307,7 @@ static PySequenceMethods RDepListSeq = 0 // assign slice }; -PyTypeObject RDepListType = +PyTypeObject PyDependencyList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DependencyList", // tp_name @@ -1343,6 +1343,6 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCache() is deprecated. " "Please see apt_pkg.Cache() for the replacement.", 1); - return PkgCacheNew(&PkgCacheType,Args,0); + return PkgCacheNew(&PyCache_Type,Args,0); } #endif diff --git a/python/cdrom.cc b/python/cdrom.cc index b5b87758..84d7179f 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -77,7 +77,7 @@ static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) } -PyTypeObject PkgCdromType = +PyTypeObject PyCdrom_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cdrom", // tp_name @@ -126,7 +126,7 @@ PyObject *GetCdrom(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCdrom() is deprecated. " "Please see apt_pkg.Cdrom() for the replacement.", 1); - return PkgCdromNew(&PkgCdromType,Args,0); + return PkgCdromNew(&PyCdrom_Type,Args,0); } #endif diff --git a/python/configuration.cc b/python/configuration.cc index 07f55957..c7d7d796 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -49,7 +49,7 @@ void CnfSubFree(PyObject *Obj) /* */ static inline Configuration &GetSelf(PyObject *Obj) { - if (Obj->ob_type == &ConfigurationPtrType) + if (Obj->ob_type == &PyConfigurationPtr_Type) return *GetCpp(Obj); return GetCpp(Obj); } @@ -161,8 +161,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) } // Create a new sub configuration. - SubConfiguration *New = (SubConfiguration*)(&ConfigurationSubType) - ->tp_alloc(&ConfigurationSubType,0); + SubConfiguration *New = (SubConfiguration*)(&PyConfigurationSub_Type) + ->tp_alloc(&PyConfigurationSub_Type,0); new (&New->Object) Configuration(Itm); New->Owner = Self; Py_INCREF(Self); @@ -501,7 +501,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { // Type for a Normal Configuration object static PySequenceMethods ConfigurationSeq = {0,0,0,0,0,0,0,CnfContains,0,0}; static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; -PyTypeObject ConfigurationType = +PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name @@ -545,7 +545,7 @@ PyTypeObject ConfigurationType = CnfNew, // tp_new }; -PyTypeObject ConfigurationPtrType = +PyTypeObject PyConfigurationPtr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ConfigurationPtr", // tp_name @@ -578,10 +578,10 @@ PyTypeObject ConfigurationPtrType = CnfMethods, // tp_methods 0, // tp_members 0, // tp_getset - &ConfigurationType, // tp_base + &PyConfiguration_Type, // tp_base }; -PyTypeObject ConfigurationSubType = +PyTypeObject PyConfigurationSub_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ConfigurationSub", // tp_name @@ -614,6 +614,6 @@ PyTypeObject ConfigurationSubType = CnfMethods, // tp_methods 0, // tp_members 0, // tp_getset - &ConfigurationType, // tp_base + &PyConfiguration_Type, // tp_base }; diff --git a/python/depcache.cc b/python/depcache.cc index 68ca3a3b..2d72a82a 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -190,8 +190,8 @@ static PyObject *PkgDepCacheSetCandidateVer(PyObject *Self,PyObject *Args) PyObject *PackageObj; PyObject *VersionObj; if (PyArg_ParseTuple(Args,"O!O!", - &PackageType, &PackageObj, - &VersionType, &VersionObj) == 0) + &PyPackage_Type, &PackageObj, + &PyVersion_Type, &VersionObj) == 0) return 0; pkgCache::VerIterator &I = GetCpp(VersionObj); @@ -208,7 +208,7 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; PyObject *CandidateObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -219,7 +219,7 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) Py_INCREF(Py_None); return Py_None; } - CandidateObj = CppOwnedPyObject_NEW(PackageObj,&VersionType,I); + CandidateObj = CppOwnedPyObject_NEW(PackageObj,&PyVersion_Type,I); return CandidateObj; } @@ -300,7 +300,7 @@ static PyObject *PkgDepCacheMarkKeep(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -316,7 +316,7 @@ static PyObject *PkgDepCacheSetReInstall(PyObject *Self,PyObject *Args) PyObject *PackageObj; char value = 0; - if (PyArg_ParseTuple(Args,"O!b",&PackageType,&PackageObj, &value) == 0) + if (PyArg_ParseTuple(Args,"O!b",&PyPackage_Type,&PackageObj, &value) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -333,7 +333,7 @@ static PyObject *PkgDepCacheMarkDelete(PyObject *Self,PyObject *Args) PyObject *PackageObj; char purge = 0; - if (PyArg_ParseTuple(Args,"O!|b",&PackageType,&PackageObj, &purge) == 0) + if (PyArg_ParseTuple(Args,"O!|b",&PyPackage_Type,&PackageObj, &purge) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -351,7 +351,7 @@ static PyObject *PkgDepCacheMarkInstall(PyObject *Self,PyObject *Args) PyObject *PackageObj; char autoInst=1; char fromUser=1; - if (PyArg_ParseTuple(Args,"O!|bb",&PackageType,&PackageObj, + if (PyArg_ParseTuple(Args,"O!|bb",&PyPackage_Type,&PackageObj, &autoInst, &fromUser) == 0) return 0; @@ -370,7 +370,7 @@ static PyObject *PkgDepCacheMarkAuto(PyObject *Self,PyObject *Args) PyObject *PackageObj; char value = 0; - if (PyArg_ParseTuple(Args,"O!b",&PackageType,&PackageObj, &value) == 0) + if (PyArg_ParseTuple(Args,"O!b",&PyPackage_Type,&PackageObj, &value) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -386,7 +386,7 @@ static PyObject *PkgDepCacheIsUpgradable(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -400,7 +400,7 @@ static PyObject *PkgDepCacheIsGarbage(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -414,7 +414,7 @@ static PyObject *PkgDepCacheIsAutoInstalled(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -428,7 +428,7 @@ static PyObject *PkgDepCacheIsNowBroken(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -442,7 +442,7 @@ static PyObject *PkgDepCacheIsInstBroken(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -457,7 +457,7 @@ static PyObject *PkgDepCacheMarkedInstall(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -472,7 +472,7 @@ static PyObject *PkgDepCacheMarkedUpgrade(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -486,7 +486,7 @@ static PyObject *PkgDepCacheMarkedDelete(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -500,7 +500,7 @@ static PyObject *PkgDepCacheMarkedKeep(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -514,7 +514,7 @@ static PyObject *PkgDepCacheMarkedDowngrade(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -528,7 +528,7 @@ static PyObject *PkgDepCacheMarkedReinstall(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -656,7 +656,7 @@ static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds { PyObject *Owner; static char *kwlist[] = {"cache", 0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyCache_Type, &Owner) == 0) return 0; @@ -680,7 +680,7 @@ static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds static char *doc_PkgDepCache = "DepCache(cache) -> DepCache() object\n\n" "A DepCache() holds extra information on the state of the packages.\n\n" "The parameter *cache* refers to an apt_pkg.Cache() object."; -PyTypeObject PkgDepCacheType = +PyTypeObject PyDepCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DepCache", // tp_name @@ -730,7 +730,7 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetDepCache() is deprecated" ". Please see apt_pkg.DepCache() for the replacement.",1); - return PkgDepCacheNew(&PkgDepCacheType,Args,0); + return PkgDepCacheNew(&PyDepCache_Type,Args,0); } #endif @@ -745,7 +745,7 @@ static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObjec { PyObject *Owner; static char *kwlist[] = {"depcache",0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -765,7 +765,7 @@ PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgProblemResolver() is" " deprecated. Please see apt_pkg.ProblemResolver() for the " "replacement.", 1); - return PkgProblemResolverNew(&PkgProblemResolverType,Args,0); + return PkgProblemResolverNew(&PyProblemResolver_Type,Args,0); } #endif @@ -803,7 +803,7 @@ static PyObject *PkgProblemResolverProtect(PyObject *Self,PyObject *Args) { pkgProblemResolver *fixer = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); fixer->Protect(Pkg); @@ -815,7 +815,7 @@ static PyObject *PkgProblemResolverRemove(PyObject *Self,PyObject *Args) { pkgProblemResolver *fixer = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); fixer->Remove(Pkg); @@ -827,7 +827,7 @@ static PyObject *PkgProblemResolverClear(PyObject *Self,PyObject *Args) { pkgProblemResolver *fixer = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); fixer->Clear(Pkg); @@ -867,7 +867,7 @@ static PyMethodDef PkgProblemResolverMethods[] = {} }; -PyTypeObject PkgProblemResolverType = +PyTypeObject PyProblemResolver_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ProblemResolver", // tp_name @@ -953,7 +953,7 @@ static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *k { PyObject *Owner; static char *kwlist[] = {"depcache", 0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -983,7 +983,7 @@ static char *doc_PkgActionGroup = "ActionGroup(depcache)\n\n" "automatically released from the cache."; -PyTypeObject PkgActionGroupType = +PyTypeObject PyActionGroup_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ActionGroup", // tp_name @@ -1034,7 +1034,7 @@ PyObject *GetPkgActionGroup(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgActionGroup() is " "deprecated. Please see apt_pkg.ActionGroup() for the " "replacement.", 1); - return PkgActionGroupNew(&PkgActionGroupType,Args,0); + return PkgActionGroupNew(&PyActionGroup_Type,Args,0); } #endif diff --git a/python/indexfile.cc b/python/indexfile.cc index f2180cd7..7bf646d0 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -88,7 +88,7 @@ static PyGetSetDef PackageIndexFileGetSet[] = { {} }; -PyTypeObject PackageIndexFileType = +PyTypeObject PyPackageIndexFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageIndexFile", // tp_name diff --git a/python/metaindex.cc b/python/metaindex.cc index 195394d6..d67c0ada 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -38,7 +38,7 @@ static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) { I != indexFiles->end(); I++) { CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &PackageIndexFileType,*I); + Obj = CppOwnedPyObject_NEW(Self, &PyPackageIndexFile_Type,*I); // Do not delete pkgIndexFile*, they are managed by metaIndex. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -73,7 +73,7 @@ static PyObject *MetaIndexRepr(PyObject *Self) return PyString_FromString(S); } -PyTypeObject MetaIndexType = +PyTypeObject PyMetaIndex_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.MetaIndex", // tp_name diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9e9cc32d..f4f84a2b 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -24,7 +24,7 @@ static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; char *kwlist[] = {"depcache",0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -42,7 +42,7 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPackageManager() is " "deprecated. Please see apt_pkg.PackageManager() for the " "replacement.", 1); - return PkgManagerNew(&PkgManagerType,Args,0); + return PkgManagerNew(&PyPackageManager_Type,Args,0); } #endif @@ -53,9 +53,9 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) PyObject *fetcher, *list, *recs; if (PyArg_ParseTuple(Args, "O!O!O!", - &PkgAcquireType,&fetcher, - &PkgSourceListType, &list, - &PkgRecordsType, &recs) == 0) + &PyAcquire_Type,&fetcher, + &PySourceList_Type, &list, + &PyPackageRecords_Type, &recs) == 0) return 0; pkgAcquire *s_fetcher = GetCpp(fetcher); @@ -131,7 +131,7 @@ static PyGetSetDef PkgManagerGetSet[] = { {} }; -PyTypeObject PkgManagerType = +PyTypeObject PyPackageManager_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageManager", // tp_name diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 886bdb58..d34ba0d2 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -27,7 +27,7 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) PyObject *PkgFObj; long int Index; - if (PyArg_ParseTuple(Args,"(O!l)",&PackageFileType,&PkgFObj,&Index) == 0) + if (PyArg_ParseTuple(Args,"(O!l)",&PyPackageFile_Type,&PkgFObj,&Index) == 0) return 0; // Get the index and check to make sure it is reasonable @@ -153,7 +153,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; char *kwlist[] = {"cache",0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyCache_Type, &Owner) == 0) return 0; @@ -161,7 +161,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) GetCpp(Owner))); } -PyTypeObject PkgRecordsType = +PyTypeObject PyPackageRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageRecords", // tp_name @@ -215,6 +215,6 @@ PyObject *GetPkgRecords(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgRecords() is " "deprecated. Please see apt_pkg.Records() for the " "replacement.", 1); - return PkgRecordsNew(&PkgRecordsType,Args,0); + return PkgRecordsNew(&PyPackageRecords_Type,Args,0); } #endif diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 99711585..fbc9a293 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -124,7 +124,7 @@ static PyObject *PkgSrcRecordsGetIndex(PyObject *Self,void*) { return 0; const pkgIndexFile &tmp = Struct.Last->Index(); CppOwnedPyObject *PyObj; - PyObj = CppOwnedPyObject_NEW(Self,&PackageIndexFileType, + PyObj = CppOwnedPyObject_NEW(Self,&PyPackageIndexFile_Type, (pkgIndexFile*)&tmp); // Do not delete the pkgIndexFile*, it is managed by PkgSrcRecords::Parser. PyObj->NoDelete=true; @@ -255,7 +255,7 @@ static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kw return HandleErrors(CppPyObject_NEW(type)); } -PyTypeObject PkgSrcRecordsType = +PyTypeObject PySourceRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceRecords", // tp_name @@ -310,6 +310,6 @@ PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"") == 0) return 0; - return HandleErrors(CppPyObject_NEW(&PkgSrcRecordsType)); + return HandleErrors(CppPyObject_NEW(&PySourceRecords_Type)); } #endif diff --git a/python/policy.cc b/python/policy.cc index d086c4fc..faf53b38 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -29,7 +29,7 @@ static PyObject *Policy_NEW(PyTypeObject *type,PyObject *Args, char *kwlist[] = {"cache", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O", kwlist, &cache) == 0) return 0; - if (!PyObject_TypeCheck(cache, &PkgCacheType)) { + if (!PyObject_TypeCheck(cache, &PyCache_Type)) { PyErr_SetString(PyExc_TypeError,"`cache` must be a apt_pkg.Cache()."); return 0; } @@ -43,7 +43,7 @@ static char *Policy_GetPriority_doc = "get_priority(package: apt_pkg.Package)" PyObject *Policy_GetPriority(PyObject *self, PyObject *arg) { pkgPolicy *policy = GetCpp(self); - if (PyObject_TypeCheck(arg, &PackageType)) { + if (PyObject_TypeCheck(arg, &PyPackage_Type)) { pkgCache::PkgIterator pkg = GetCpp(arg); return Py_BuildValue("i", policy->GetPriority(pkg)); } else { @@ -57,11 +57,11 @@ static char *Policy_GetCandidateVer_doc = "get_match(package: apt_pkg.Package)" "Get the best package for the job."; PyObject *Policy_GetCandidateVer(PyObject *self, PyObject *arg) { - if (PyObject_TypeCheck(arg, &PackageType)) { + if (PyObject_TypeCheck(arg, &PyPackage_Type)) { pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetCandidateVer(pkg); - return CppOwnedPyObject_NEW(arg,&VersionType, + return CppOwnedPyObject_NEW(arg,&PyVersion_Type, ver); } else { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); @@ -74,14 +74,14 @@ static char *Policy_GetMatch_doc = "get_match(package: apt_pkg.Package) -> " "Return a matching version for the given package."; static PyObject *Policy_GetMatch(PyObject *self, PyObject *arg) { - if (PyObject_TypeCheck(arg, &PackageType) == 0) { + if (PyObject_TypeCheck(arg, &PyPackage_Type) == 0) { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); return 0; } pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetMatch(pkg); - return CppOwnedPyObject_NEW(arg,&VersionType,ver); + return CppOwnedPyObject_NEW(arg,&PyVersion_Type,ver); } static char *Policy_ReadPinFile_doc = "read_pinfile(filename: str) -> bool\n\n" diff --git a/python/sourcelist.cc b/python/sourcelist.cc index beb249dc..e86f7fd3 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -28,20 +28,20 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) PyObject *pyPkgFileIter; CppOwnedPyObject *pyPkgIndexFile; - if (PyArg_ParseTuple(Args, "O!", &PackageFileType,&pyPkgFileIter) == 0) + if (PyArg_ParseTuple(Args, "O!", &PyPackageFile_Type,&pyPkgFileIter) == 0) return 0; pkgCache::PkgFileIterator &i = GetCpp(pyPkgFileIter); pkgIndexFile *index; if(list->FindIndex(i, index)) { - pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PackageIndexFileType,index); + pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PyPackageIndexFile_Type,index); // Do not delete the pkgIndexFile*, it is managed by pkgSourceList. pyPkgIndexFile->NoDelete = true; return pyPkgIndexFile; } - //&PackageIndexFileType,&pyPkgIndexFile) + //&PyPackageIndexFile_Type,&pyPkgIndexFile) Py_INCREF(Py_None); return Py_None; @@ -63,7 +63,7 @@ static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args) PyObject *pyFetcher; char all = 0; - if (PyArg_ParseTuple(Args, "O!|b",&PkgAcquireType,&pyFetcher, &all) == 0) + if (PyArg_ParseTuple(Args, "O!|b",&PyAcquire_Type,&pyFetcher, &all) == 0) return 0; pkgAcquire *fetcher = GetCpp(pyFetcher); @@ -93,7 +93,7 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) I != list->end(); I++) { CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &MetaIndexType,*I); + Obj = CppOwnedPyObject_NEW(Self, &PyMetaIndex_Type,*I); // Never delete metaIndex*, they are managed by the pkgSourceList. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -118,7 +118,7 @@ static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kw return CppPyObject_NEW(type,new pkgSourceList()); } -PyTypeObject PkgSourceListType = +PyTypeObject PySourceList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceList", // tp_name @@ -168,6 +168,6 @@ PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSourceList() is " "deprecated. Please see apt_pkg.SourceList() for the " "replacement.", 1); - return PkgSourceListNew(&PkgSourceListType,Args,0); + return PkgSourceListNew(&PySourceList_Type,Args,0); } #endif diff --git a/python/tag.cc b/python/tag.cc index 2b71517d..573e8ce2 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -290,7 +290,7 @@ PyObject *ParseSection(PyObject *self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseSection() is " "deprecated. Please see apt_pkg.TagSection() for the " "replacement.", 1); - return TagSecNew(&TagSecType,Args,0); + return TagSecNew(&PyTagSection_Type,Args,0); } #endif /*}}}*/ @@ -315,7 +315,7 @@ static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) new (&New->Object) pkgTagFile(&New->Fd); // Create the section - New->Section = (TagSecData*)(&TagSecType)->tp_alloc(&TagSecType, 0); + New->Section = (TagSecData*)(&PyTagSection_Type)->tp_alloc(&PyTagSection_Type, 0); new (&New->Section->Object) pkgTagSection(); New->Section->Owner = New; Py_INCREF(New->Section->Owner); @@ -329,7 +329,7 @@ PyObject *ParseTagFile(PyObject *self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseTagFile() is " "deprecated. Please see apt_pkg.TagFile() for the " "replacement.", 1); - return TagFileNew(&TagFileType,Args,0); + return TagFileNew(&PyTagFile_Type,Args,0); } #endif /*}}}*/ @@ -357,7 +357,7 @@ PyObject *RewriteSection(PyObject *self,PyObject *Args) PyObject *Section; PyObject *Order; PyObject *Rewrite; - if (PyArg_ParseTuple(Args,"O!O!O!",&TagSecType,&Section, + if (PyArg_ParseTuple(Args,"O!O!O!",&PyTagSection_Type,&Section, &PyList_Type,&Order,&PyList_Type,&Rewrite) == 0) return 0; @@ -436,7 +436,7 @@ static char *doc_TagSec = "TagSection(text) -> Create a new object.\n\n" "header sections, like those in debian/control or Packages files.\n\n" "TagSection() behave like read-only dictionaries and also provide access\n" "to the functions provided by the C++ class (e.g. Find)"; -PyTypeObject TagSecType = +PyTypeObject PyTagSection_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.TagSection", // tp_name @@ -522,7 +522,7 @@ static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" "a file descriptor (an integer)"; // Type for a Tag File -PyTypeObject TagFileType = +PyTypeObject PyTagFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.TagFile", // tp_name -- cgit v1.2.3 From 85165f89d3df8ad1c66bd9c842795885c407069e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Jul 2009 17:47:45 +0200 Subject: python: No zero-size arrays for char *kwlist[]. --- python/acquire.cc | 2 +- python/cache.cc | 2 +- python/cdrom.cc | 2 +- python/configuration.cc | 2 +- python/depcache.cc | 6 +++--- python/tag.cc | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index 4329e790..8b6de173 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -281,7 +281,7 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) pkgAcquire *fetcher; PyObject *pyFetchProgressInst = NULL; - static char *kwlist[] = {"progress", 0}; + char *kwlist[] = {"progress", 0}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"|O",kwlist,&pyFetchProgressInst) == 0) return 0; diff --git a/python/cache.cc b/python/cache.cc index d3a8a949..c160cf69 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -244,7 +244,7 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *pyCallbackInst = 0; - static char *kwlist[] = {"progress", 0}; + char *kwlist[] = {"progress", 0}; if (PyArg_ParseTupleAndKeywords (Args, kwds, "|O", kwlist, &pyCallbackInst) == 0) return 0; diff --git a/python/cdrom.cc b/python/cdrom.cc index 84d7179f..50d1b4b1 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -66,7 +66,7 @@ static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { pkgCdrom *cdrom = new pkgCdrom(); - static char *kwlist[] = {}; + char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"",kwlist) == 0) return 0; diff --git a/python/configuration.cc b/python/configuration.cc index c7d7d796..ba075133 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -492,7 +492,7 @@ static PyMethodDef CnfMethods[] = }; static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {}; + char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; return CppPyObject_NEW(type); diff --git a/python/depcache.cc b/python/depcache.cc index 2d72a82a..e78b9f4e 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -655,7 +655,7 @@ static PyGetSetDef PkgDepCacheGetSet[] = { static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; - static char *kwlist[] = {"cache", 0}; + char *kwlist[] = {"cache", 0}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyCache_Type, &Owner) == 0) return 0; @@ -744,7 +744,7 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; - static char *kwlist[] = {"depcache",0}; + char *kwlist[] = {"depcache",0}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -952,7 +952,7 @@ static PyMethodDef PkgActionGroupMethods[] = static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; - static char *kwlist[] = {"depcache", 0}; + char *kwlist[] = {"depcache", 0}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; diff --git a/python/tag.cc b/python/tag.cc index 573e8ce2..b393effe 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -260,7 +260,7 @@ static PyObject *TagFileJump(PyObject *Self,PyObject *Args) // --------------------------------------------------------------------- static PyObject *TagSecNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { char *Data; - static char *kwlist[] = {"text", 0}; + char *kwlist[] = {"text", 0}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"s",kwlist,&Data) == 0) return 0; @@ -301,7 +301,7 @@ PyObject *ParseSection(PyObject *self,PyObject *Args) static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *File; - static char *kwlist[] = {"file", 0}; + char *kwlist[] = {"file", 0}; if (PyArg_ParseTupleAndKeywords(Args,kwds,"O",kwlist,&File) == 0) return 0; int fileno = PyObject_AsFileDescriptor(File); -- cgit v1.2.3 From 8430dbf041ce70dcba81101678beee0492252fd2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Jul 2009 20:43:56 +0200 Subject: python/configuration.cc: Unify all Configuration,ConfigurationPtr,ConfigurationSub into one type. This makes the whole API easier. The disadvantage is that we require 8 bytes (??) more per object for the owner object pointer, which is NULL for most cases (the only exception being objects created by Configuration.sub_tree). --- debian/changelog | 3 +- python/apt_pkgmodule.cc | 9 ++-- python/apt_pkgmodule.h | 6 +-- python/configuration.cc | 116 ++++-------------------------------------------- 4 files changed, 15 insertions(+), 119 deletions(-) (limited to 'python/configuration.cc') diff --git a/debian/changelog b/debian/changelog index 304237c1..4ae6e574 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,6 +33,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low * Introduce apt_pkg.Hashes class. * Make AcquireItem objects raise ValueError instead of segfaulting when the Acquire() object is shut down or the main object (e.g. AcquireFile) is deallocated. + * Unify all Configuration,ConfigurationPtr,ConfigurationSub into one type. [ Sebastian Heinlein ] * apt/progress.py: Extract the package name from the status message @@ -48,7 +49,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low * python/progress.cc: - low level code for update_status_full and pulse_items() - -- Julian Andres Klode Sun, 12 Jul 2009 21:19:40 +0200 + -- Julian Andres Klode Tue, 14 Jul 2009 20:42:03 +0200 python-apt (0.7.91) experimental; urgency=low diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 3f18f785..e4fd0dfc 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -527,8 +527,7 @@ extern "C" void initapt_pkg() #endif { // Finalize our types to add slots, etc. - if (PyType_Ready(&PyConfigurationPtr_Type) == -1) INIT_ERROR; - if (PyType_Ready(&PyConfigurationSub_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfiguration_Type) == -1) INIT_ERROR; if (PyType_Ready(&PyCacheFile_Type) == -1) INIT_ERROR; // Initialize the module @@ -539,8 +538,10 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppPyObject *Config = CppPyObject_NEW(&PyConfigurationPtr_Type); + CppOwnedPyObject *Config = CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type); Config->Object = _config; + // Global configuration, should never be deleted. + Config->NoDelete = true; PyModule_AddObject(Module,"config",Config); #ifdef COMPAT_0_7 Py_INCREF(Config); @@ -568,8 +569,6 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"Cdrom",&PyCdrom_Type); /* ========================= configuration.cc ========================= */ ADDTYPE(Module,"Configuration",&PyConfiguration_Type); - //ADDTYPE(Module,"ConfigurationSub",&PyConfigurationSub_Type); // NO __new__() - //ADDTYPE(Module,"ConfigurationPtr",&PyConfigurationPtr_Type); // NO __new__() /* ========================= depcache.cc ========================= */ ADDTYPE(Module,"ActionGroup",&PyActionGroup_Type); ADDTYPE(Module,"DepCache",&PyDepCache_Type); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 7b835ca8..f77c5e73 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -14,12 +14,8 @@ #include // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type || \ - (op)->ob_type == &PyConfigurationPtr_Type || \ - (op)->ob_type == &PyConfigurationSub_Type) +#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) extern PyTypeObject PyConfiguration_Type; -extern PyTypeObject PyConfigurationPtr_Type; -extern PyTypeObject PyConfigurationSub_Type; extern PyTypeObject PyVersion_Type; extern char *doc_LoadConfig; diff --git a/python/configuration.cc b/python/configuration.cc index ba075133..e7e31cc8 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -5,11 +5,8 @@ Configuration - Binding for the configuration object. - There are three seperate classes.. - Configuration - A stand alone configuration instance - ConfigurationPtr - A pointer to a configuration instance, used only - for the global instance (_config) - ConfigurationSub - A subtree - has a reference to its owner. + The Configuration object can have an owner (a parent Configuration object), + and it always uses a pointer. The wrapping is mostly 1:1 with the C++ code, but there are additions to wrap the linked tree walking into nice flat sequence walking. @@ -25,33 +22,13 @@ #include /*}}}*/ -/* If we create a sub tree then it is of this type, the Owner is used - to manage reference counting. */ -struct SubConfiguration : public CppPyObject -{ - PyObject *Owner; -}; - - /*}}}*/ -// CnfSubFree - Free a sub configuration /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void CnfSubFree(PyObject *Obj) -{ - SubConfiguration *Self = (SubConfiguration *)Obj; - Py_DECREF(Self->Owner); - CppDealloc(Obj); -} - /*}}}*/ // GetSelf - Convert PyObject to Configuration /*{{{*/ // --------------------------------------------------------------------- /* */ static inline Configuration &GetSelf(PyObject *Obj) { - if (Obj->ob_type == &PyConfigurationPtr_Type) - return *GetCpp(Obj); - return GetCpp(Obj); + return *GetCpp(Obj); } /*}}}*/ @@ -160,13 +137,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) return 0; } - // Create a new sub configuration. - SubConfiguration *New = (SubConfiguration*)(&PyConfigurationSub_Type) - ->tp_alloc(&PyConfigurationSub_Type,0); - new (&New->Object) Configuration(Itm); - New->Owner = Self; - Py_INCREF(Self); - return New; + return CppOwnedPyObject_NEW(Self,&PyConfiguration_Type, + new Configuration(Itm)); } // Return a list of items at a specific level @@ -495,7 +467,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppPyObject_NEW(type); + return CppOwnedPyObject_NEW(NULL, type, new Configuration()); } // Type for a Normal Configuration object @@ -505,10 +477,10 @@ PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name - sizeof(CppPyObject), // tp_basicsize + sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppDealloc, // tp_dealloc + CppOwnedDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -545,75 +517,3 @@ PyTypeObject PyConfiguration_Type = CnfNew, // tp_new }; -PyTypeObject PyConfigurationPtr_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.ConfigurationPtr", // tp_name - sizeof(CppPyObject), // tp_basicsize - 0, // tp_itemsize - // Methods - (destructor)PyObject_Free, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - 0, // tp_repr - 0, // tp_as_number - &ConfigurationSeq, // tp_as_sequence - &ConfigurationMap, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "ConfigurationPtr Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - CnfMethods, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyConfiguration_Type, // tp_base -}; - -PyTypeObject PyConfigurationSub_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.ConfigurationSub", // tp_name - sizeof(SubConfiguration), // tp_basicsize - 0, // tp_itemsize - // Methods - CnfSubFree, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - 0, // tp_repr - 0, // tp_as_number - &ConfigurationSeq, // tp_as_sequence - &ConfigurationMap, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "ConfigurationSub Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - CnfMethods, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyConfiguration_Type, // tp_base -}; - -- cgit v1.2.3 From 22d8199e2d047dc6b258241cf33e67d77aa33ca6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 23 Jul 2009 20:38:27 +0200 Subject: python/configuration: Hack-in unicode character support in parse_commandline(). --- python/configuration.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'python/configuration.cc') diff --git a/python/configuration.cc b/python/configuration.cc index e7e31cc8..11231a28 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -361,7 +361,11 @@ PyObject *ParseCommandLine(PyObject *Self,PyObject *Args) for (int I = 0; I != Length; I++) { char *Type = 0; + #if PY_MAJOR_VERSION >= 3 + if (PyArg_ParseTuple(PySequence_GetItem(POList,I),"Czs|s", + #else if (PyArg_ParseTuple(PySequence_GetItem(POList,I),"czs|s", + #endif &OList[I].ShortOpt,&OList[I].LongOpt, &OList[I].ConfName,&Type) == 0) { -- cgit v1.2.3 From c41f809bef5b591d36d6bbb663841a9434eb77fb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 31 Jul 2009 14:55:02 +0200 Subject: python/configuration.cc, apt_pkgmodule.cc: Fix Configuration segfaults. In apt_pkgmodule, change the type to Configuration*. In configuration.cc, check that GetSelf(Self).Tree(0) != 0 before doing GetSelf(Self).Tree(0)->Parent. --- python/apt_pkgmodule.cc | 2 +- python/configuration.cc | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'python/configuration.cc') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 9e486a91..d53f64a6 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -56,7 +56,7 @@ static PyObject *newConfiguration(PyObject *self,PyObject *args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " "deprecated. Use apt_pkg.Configuration() instead.", 1); - return CppPyObject_NEW(&PyConfiguration_Type); + return CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type, new Configuration()); } #endif /*}}}*/ diff --git a/python/configuration.cc b/python/configuration.cc index 11231a28..b2367c3e 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -152,6 +152,8 @@ static PyObject *CnfList(PyObject *Self,PyObject *Args) // Convert the whole configuration space into a list PyObject *List = PyList_New(0); const Configuration::Item *Top = GetSelf(Self).Tree(RootName); + if (!GetSelf(Self).Tree(0)) + return List; const Configuration::Item *Root = GetSelf(Self).Tree(0)->Parent; if (Top != 0 && RootName != 0) Top = Top->Child; @@ -216,7 +218,7 @@ static PyObject *CnfKeys(PyObject *Self,PyObject *Args) const Configuration::Item *Root = 0; if (RootName == 0) Stop = 0; - if (Top != 0) + if (Top != 0 && GetSelf(Self).Tree(0)) Root = GetSelf(Self).Tree(0)->Parent; for (; Top != 0;) { -- cgit v1.2.3 From d24964f86e1108f88d55a9580bbd6d2e482562dd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 27 Jan 2010 15:11:39 +0100 Subject: Merge the CppOwnedPyObject C++ class into CppPyObject. --- debian/changelog | 1 + python/acquire-item.cc | 18 ++++---- python/acquire.cc | 24 +++++----- python/apt_instmodule.h | 2 +- python/apt_pkgmodule.cc | 4 +- python/arfile.cc | 32 +++++++------- python/cache.cc | 114 ++++++++++++++++++++++++------------------------ python/cdrom.cc | 2 +- python/configuration.cc | 8 ++-- python/depcache.cc | 42 +++++++++--------- python/generic.h | 93 ++++++++++----------------------------- python/hashes.cc | 2 +- python/hashstring.cc | 2 +- python/indexfile.cc | 8 ++-- python/indexrecords.cc | 2 +- python/metaindex.cc | 8 ++-- python/pkgmanager.cc | 2 +- python/pkgrecords.cc | 10 ++--- python/pkgsrcrecords.cc | 8 ++-- python/policy.cc | 14 +++--- python/python-apt.h | 61 +++++++++++--------------- python/sourcelist.cc | 10 ++--- python/tag.cc | 10 ++--- python/tarfile.cc | 20 ++++----- 24 files changed, 219 insertions(+), 278 deletions(-) (limited to 'python/configuration.cc') diff --git a/debian/changelog b/debian/changelog index 9b505a58..08bf564b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,6 +15,7 @@ python-apt (0.7.93.1) UNRELEASED; urgency=low * Drop the segfault prevention measures from the Acquire code, as they fail to work. A replacement will be added once destruction callbacks are added in APT. + * Merge the CppOwnedPyObject C++ class into CppPyObject. -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 059f1802..d5f9ad10 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -159,13 +159,13 @@ static PyObject *acquireitem_repr(PyObject *Self) static void acquireitem_dealloc(PyObject *self) { - CppOwnedDeallocPtr(self); + CppDeallocPtr(self); } PyTypeObject PyAcquireItem_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItem", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods acquireitem_dealloc, // tp_dealloc @@ -186,8 +186,8 @@ PyTypeObject PyAcquireItem_Type = { Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "AcquireItem Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -222,7 +222,7 @@ static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * shortDescr, destDir, destFile); // short-desc - CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); + CppPyObject *AcqFileObj = CppPyObject_NEW(pyfetcher, type); AcqFileObj->Object = af; return AcqFileObj; } @@ -237,7 +237,7 @@ static char *acquirefile_doc = PyTypeObject PyAcquireFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireFile", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods acquireitem_dealloc, // tp_dealloc @@ -259,8 +259,8 @@ PyTypeObject PyAcquireFile_Type = { Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, acquirefile_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -309,7 +309,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) shortDescr, destDir, destFile); // short-desc - CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); + CppPyObject *AcqFileObj = CppPyObject_NEW(NULL, &PyAcquireFile_Type); AcqFileObj->Object = af; AcqFileObj->NoDelete = true; diff --git a/python/acquire.cc b/python/acquire.cc index bcb76d67..cd7f7709 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -77,10 +77,10 @@ static PyGetSetDef acquireworker_getset[] = { PyTypeObject PyAcquireWorker_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireWorker", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -98,8 +98,8 @@ PyTypeObject PyAcquireWorker_Type = { Py_TPFLAGS_DEFAULT| // tp_flags Py_TPFLAGS_HAVE_GC, 0, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -132,7 +132,7 @@ static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); return item ? CppPyString(item->ShortDesc) : NULL; } -static PyObject *acquireitemdesc_get_owner(CppOwnedPyObject *self, void *closure) +static PyObject *acquireitemdesc_get_owner(CppPyObject *self, void *closure) { if (self->Owner != NULL) { Py_INCREF(self->Owner); @@ -160,10 +160,10 @@ static char *acquireitemdesc_doc = PyTypeObject PyAcquireItemDesc_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItemDesc", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -181,8 +181,8 @@ PyTypeObject PyAcquireItemDesc_Type = { (Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC), acquireitemdesc_doc, // tp_doc - CppOwnedTraverse,// tp_traverse - CppOwnedClear, // tp_clear + CppTraverse,// tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -255,7 +255,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) { PyObject *List = PyList_New(0); pkgAcquire *Owner = GetCpp(self); - CppOwnedPyObject *PyWorker = NULL; + CppPyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); @@ -313,7 +313,7 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) fetcher = new pkgAcquire(); } - PyObject *FetcherObj = CppPyObject_NEW(type, fetcher); + PyObject *FetcherObj = CppPyObject_NEW(NULL, type, fetcher); if (progress != 0) progress->setPyAcquire(FetcherObj); @@ -325,7 +325,7 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) * Create a new apt_pkg.Acquire Python object from the pkgAcquire object. */ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete) { - CppPyObject *obj = CppPyObject_NEW(&PyAcquire_Type, fetcher); + CppPyObject *obj = CppPyObject_NEW(NULL, &PyAcquire_Type, fetcher); obj->NoDelete = (!Delete); return obj; } diff --git a/python/apt_instmodule.h b/python/apt_instmodule.h index 2b07261b..f6b337f4 100644 --- a/python/apt_instmodule.h +++ b/python/apt_instmodule.h @@ -27,7 +27,7 @@ extern PyTypeObject PyDebFile_Type; extern PyTypeObject PyTarFile_Type; extern PyTypeObject PyTarMember_Type; -struct PyTarFileObject : public CppOwnedPyObject { +struct PyTarFileObject : public CppPyObject { int min; FileFd Fd; }; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 64db74d2..e77fd3ca 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -56,7 +56,7 @@ static PyObject *newConfiguration(PyObject *self,PyObject *args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " "deprecated. Use apt_pkg.Configuration() instead.", 1); - return CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type, new Configuration()); + return CppPyObject_NEW(NULL, &PyConfiguration_Type, new Configuration()); } #endif /*}}}*/ @@ -599,7 +599,7 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppOwnedPyObject *Config = CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type); + CppPyObject *Config = CppPyObject_NEW(NULL, &PyConfiguration_Type); Config->Object = _config; // Global configuration, should never be deleted. Config->NoDelete = true; diff --git a/python/arfile.cc b/python/arfile.cc index 1abb738f..4f95a791 100644 --- a/python/arfile.cc +++ b/python/arfile.cc @@ -93,10 +93,10 @@ static const char *armember_doc = PyTypeObject PyArMember_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_inst.ArMember", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -114,8 +114,8 @@ PyTypeObject PyArMember_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, armember_doc, // tp_doc - CppOwnedTraverse,// tp_traverse - CppOwnedClear, // tp_clear + CppTraverse,// tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -135,7 +135,7 @@ public: } }; -struct PyArArchiveObject : public CppOwnedPyObject { +struct PyArArchiveObject : public CppPyObject { FileFd Fd; }; @@ -146,7 +146,7 @@ static const char *ararchive_getmember_doc = static PyObject *ararchive_getmember(PyArArchiveObject *self, PyObject *arg) { const char *name; - CppOwnedPyObject *ret; + CppPyObject *ret; if (! (name = PyObject_AsString(arg))) return 0; @@ -157,7 +157,7 @@ static PyObject *ararchive_getmember(PyArArchiveObject *self, PyObject *arg) } // Create our object. - ret = CppOwnedPyObject_NEW(self,&PyArMember_Type); + ret = CppPyObject_NEW(self,&PyArMember_Type); ret->Object = const_cast(member); ret->NoDelete = true; return ret; @@ -302,7 +302,7 @@ static PyObject *ararchive_gettar(PyArArchiveObject *self, PyObject *args) return 0; } - PyTarFileObject *tarfile = (PyTarFileObject*)CppOwnedPyObject_NEW(self,&PyTarFile_Type); + PyTarFileObject *tarfile = (PyTarFileObject*)CppPyObject_NEW(self,&PyTarFile_Type); new (&tarfile->Fd) FileFd(self->Fd); tarfile->min = member->Start; tarfile->Object = new ExtractTar(self->Fd, member->Size, comp); @@ -317,8 +317,8 @@ static PyObject *ararchive_getmembers(PyArArchiveObject *self) PyObject *list = PyList_New(0); ARArchive::Member *member = self->Object->Members(); do { - CppOwnedPyObject *ret; - ret = CppOwnedPyObject_NEW(self,&PyArMember_Type); + CppPyObject *ret; + ret = CppPyObject_NEW(self,&PyArMember_Type); ret->Object = member; ret->NoDelete = true; PyList_Append(list, ret); @@ -380,14 +380,14 @@ static PyObject *ararchive_new(PyTypeObject *type, PyObject *args, // We receive a filename. if ((filename = (char*)PyObject_AsString(file))) { - self = (PyArArchiveObject *)CppOwnedPyObject_NEW(0,type); + self = (PyArArchiveObject *)CppPyObject_NEW(0,type); new (&self->Fd) FileFd(filename,FileFd::ReadOnly); } // We receive a file object. else if ((fileno = PyObject_AsFileDescriptor(file)) != -1) { // Clear the error set by PyObject_AsString(). PyErr_Clear(); - self = (PyArArchiveObject *)CppOwnedPyObject_NEW(file,type); + self = (PyArArchiveObject *)CppPyObject_NEW(file,type); new (&self->Fd) FileFd(fileno,false); } else { @@ -402,7 +402,7 @@ static PyObject *ararchive_new(PyTypeObject *type, PyObject *args, static void ararchive_dealloc(PyObject *self) { ((PyArArchiveObject *)(self))->Fd.~FileFd(); - CppOwnedDeallocPtr(self); + CppDeallocPtr(self); } // Return bool or -1 (exception). @@ -455,8 +455,8 @@ PyTypeObject PyArArchive_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, ararchive_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset (getiterfunc)ararchive_iter, // tp_iter @@ -511,7 +511,7 @@ static PyObject *_gettar(PyDebFileObject *self, const ARArchive::Member *m, { if (!m) return 0; - PyTarFileObject *tarfile = (PyTarFileObject*)CppOwnedPyObject_NEW(self,&PyTarFile_Type); + PyTarFileObject *tarfile = (PyTarFileObject*)CppPyObject_NEW(self,&PyTarFile_Type); new (&tarfile->Fd) FileFd(self->Fd); tarfile->min = m->Start; tarfile->Object = new ExtractTar(self->Fd, m->Size, comp); diff --git a/python/cache.cc b/python/cache.cc index 6bbf0766..fe6e8b68 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -73,7 +73,7 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) { PyObject *Obj; PyObject *Ver; - Ver = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + Ver = CppPyObject_NEW(Owner,&PyVersion_Type, I.OwnerVer()); Obj = Py_BuildValue("ssN",I.ParentPkg().Name(),I.ProvideVersion(), Ver); @@ -162,7 +162,7 @@ static PyMethodDef PkgCacheMethods[] = static PyObject *PkgCacheGetPackages(PyObject *Self, void*) { pkgCache *Cache = GetCpp(Self); - return CppOwnedPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); + return CppPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); } static PyObject *PkgCacheGetPackageCount(PyObject *Self, void*) { @@ -200,7 +200,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self,&PyPackageFile_Type,I); + Obj = CppPyObject_NEW(Self,&PyPackageFile_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -250,7 +250,7 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return 0; } - return CppOwnedPyObject_NEW(Self,&PyPackage_Type,Pkg); + return CppPyObject_NEW(Self,&PyPackage_Type,Pkg); } static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) @@ -292,11 +292,11 @@ static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) return HandleErrors(); } - CppOwnedPyObject *CacheFileObj = - CppOwnedPyObject_NEW(0,&PyCacheFile_Type, Cache); + CppPyObject *CacheFileObj = + CppPyObject_NEW(0,&PyCacheFile_Type, Cache); - CppOwnedPyObject *CacheObj = - CppOwnedPyObject_NEW(CacheFileObj,type, + CppPyObject *CacheObj = + CppPyObject_NEW(CacheFileObj,type, (pkgCache *)(*Cache)); // Do not delete the pointer to the pkgCache, it is managed by pkgCacheFile. @@ -317,10 +317,10 @@ PyTypeObject PyCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cache", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -339,8 +339,8 @@ PyTypeObject PyCache_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_PkgCache, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -364,10 +364,10 @@ PyTypeObject PyCacheFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "pkgCacheFile", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -418,7 +418,7 @@ static PyObject *PkgListItem(PyObject *iSelf,Py_ssize_t Index) } } - return CppOwnedPyObject_NEW(GetOwner(iSelf),&PyPackage_Type, + return CppPyObject_NEW(GetOwner(iSelf),&PyPackage_Type, Self.Iter); } @@ -437,10 +437,10 @@ PyTypeObject PyPackageList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageList", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -457,8 +457,8 @@ PyTypeObject PyPackageList_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags 0, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear }; #define Owner (GetOwner(Self)) @@ -470,7 +470,7 @@ PyTypeObject PyPackageList_Type = MkGet(PackageGetName,PyString_FromString(Pkg.Name())) MkGet(PackageGetSection,Safe_FromString(Pkg.Section())) -MkGet(PackageGetRevDependsList,CppOwnedPyObject_NEW(Owner, +MkGet(PackageGetRevDependsList,CppPyObject_NEW(Owner, &PyDependencyList_Type, Pkg.RevDependsList())) MkGet(PackageGetProvidesList,CreateProvides(Owner,Pkg.ProvidesList())) MkGet(PackageGetSelectedState,Py_BuildValue("i",Pkg->SelectedState)) @@ -493,7 +493,7 @@ static PyObject *PackageGetVersionList(PyObject *Self,void*) for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type,I); + Obj = CppPyObject_NEW(Owner,&PyVersion_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -508,7 +508,7 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) Py_INCREF(Py_None); return Py_None; } - return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + return CppPyObject_NEW(Owner,&PyVersion_Type, Pkg.CurrentVer()); } @@ -558,10 +558,10 @@ PyTypeObject PyPackage_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Package", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -578,8 +578,8 @@ PyTypeObject PyPackage_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "Package Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear,// tp_clear + CppTraverse, // tp_traverse + CppClear,// tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -612,7 +612,7 @@ static PyObject *DescriptionGetFileList(PyObject *Self,void*) { PyObject *DescFile; PyObject *Obj; - DescFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); + DescFile = CppPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",DescFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -643,10 +643,10 @@ PyTypeObject PyDescription_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Description", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -663,8 +663,8 @@ PyTypeObject PyDescription_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "apt_pkg.Description Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear,// tp_clear + CppTraverse, // tp_traverse + CppClear,// tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -711,7 +711,7 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver, { PyObject *Obj; if (AsObj == true) - Obj = CppOwnedPyObject_NEW(Owner,&PyDependency_Type, + Obj = CppPyObject_NEW(Owner,&PyDependency_Type, Start); else { @@ -763,7 +763,7 @@ static PyObject *VersionGetFileList(PyObject *Self, void*) { { PyObject *PkgFile; PyObject *Obj; - PkgFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); + PkgFile = CppPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",PkgFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -783,7 +783,7 @@ static PyObject *VersionGetDependsList(PyObject *Self, void*) { } static PyObject *VersionGetParentPkg(PyObject *Self, void*) { PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, + return CppPyObject_NEW(Owner,&PyPackage_Type, Version_GetVer(Self).ParentPkg()); } static PyObject *VersionGetProvidesList(PyObject *Self, void*) { @@ -814,7 +814,7 @@ static PyObject *VersionGetDownloadable(PyObject *Self, void*) { static PyObject *VersionGetTranslatedDescription(PyObject *Self, void*) { pkgCache::VerIterator &Ver = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner, + return CppPyObject_NEW(Owner, &PyDescription_Type, Ver.TranslatedDescription()); } @@ -894,10 +894,10 @@ PyTypeObject PyVersion_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Version", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -914,8 +914,8 @@ PyTypeObject PyVersion_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "Version Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear,// tp_clear + CppTraverse, // tp_traverse + CppClear,// tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1057,9 +1057,9 @@ static PyGetSetDef PackageFileGetSet[] = { PyTypeObject PyPackageFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageFile", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1076,8 +1076,8 @@ PyTypeObject PyPackageFile_Type = { 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "apt_pkg.PackageFile Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1113,7 +1113,7 @@ static PyObject *DepSmartTargetPkg(PyObject *Self,PyObject *Args) return Py_None; } - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type,P); + return CppPyObject_NEW(Owner,&PyPackage_Type,P); } static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) @@ -1129,7 +1129,7 @@ static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) for (pkgCache::Version **I = Vers; *I != 0; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + Obj = CppPyObject_NEW(Owner,&PyVersion_Type, pkgCache::VerIterator(*Dep.Cache(),*I)); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -1163,7 +1163,7 @@ static PyObject *DependencyGetTargetPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, + return CppPyObject_NEW(Owner,&PyPackage_Type, Dep.TargetPkg()); } @@ -1171,7 +1171,7 @@ static PyObject *DependencyGetParentVer(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, + return CppPyObject_NEW(Owner,&PyVersion_Type, Dep.ParentVer()); } @@ -1179,7 +1179,7 @@ static PyObject *DependencyGetParentPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, + return CppPyObject_NEW(Owner,&PyPackage_Type, Dep.ParentPkg()); } @@ -1240,10 +1240,10 @@ PyTypeObject PyDependency_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Dependency", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1260,8 +1260,8 @@ PyTypeObject PyDependency_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "Dependency Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1306,7 +1306,7 @@ static PyObject *RDepListItem(PyObject *iSelf,Py_ssize_t Index) } } - return CppOwnedPyObject_NEW(GetOwner(iSelf), + return CppPyObject_NEW(GetOwner(iSelf), &PyDependency_Type,Self.Iter); } @@ -1325,10 +1325,10 @@ PyTypeObject PyDependencyList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DependencyList", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1345,8 +1345,8 @@ PyTypeObject PyDependencyList_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "DependencyList Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear }; /*}}}*/ diff --git a/python/cdrom.cc b/python/cdrom.cc index 4195c9cb..0b9ae578 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -109,7 +109,7 @@ static PyMethodDef cdrom_methods[] = { static PyObject *cdrom_new(PyTypeObject *type,PyObject *Args,PyObject *kwds) { - return CppPyObject_NEW(type); + return CppPyObject_NEW(NULL, type); } static char *cdrom_doc = diff --git a/python/configuration.cc b/python/configuration.cc index b2367c3e..0cad8db3 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -137,7 +137,7 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) return 0; } - return CppOwnedPyObject_NEW(Self,&PyConfiguration_Type, + return CppPyObject_NEW(Self,&PyConfiguration_Type, new Configuration(Itm)); } @@ -473,7 +473,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppOwnedPyObject_NEW(NULL, type, new Configuration()); + return CppPyObject_NEW(NULL, type, new Configuration()); } // Type for a Normal Configuration object @@ -483,10 +483,10 @@ PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr diff --git a/python/depcache.cc b/python/depcache.cc index e78b9f4e..53459c32 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -219,7 +219,7 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) Py_INCREF(Py_None); return Py_None; } - CandidateObj = CppOwnedPyObject_NEW(PackageObj,&PyVersion_Type,I); + CandidateObj = CppPyObject_NEW(PackageObj,&PyVersion_Type,I); return CandidateObj; } @@ -625,8 +625,8 @@ static PyObject *PkgDepCacheGetPolicy(PyObject *Self,void*) { PyObject *Owner = GetOwner(Self); pkgDepCache *DepCache = GetCpp(Self); pkgPolicy *Policy = (pkgPolicy *)&DepCache->GetPolicy(); - CppOwnedPyObject *PyPolicy = - CppOwnedPyObject_NEW(Owner,&PyPolicy_Type,Policy); + CppPyObject *PyPolicy = + CppPyObject_NEW(Owner,&PyPolicy_Type,Policy); // Policy should not be deleted, it is managed by CacheFile. PyPolicy->NoDelete = true; return PyPolicy; @@ -668,8 +668,8 @@ static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds // and now the depcache pkgDepCache *depcache = (pkgDepCache *)(*CacheF); - CppOwnedPyObject *DepCachePyObj; - DepCachePyObj = CppOwnedPyObject_NEW(Owner,type,depcache); + CppPyObject *DepCachePyObj; + DepCachePyObj = CppPyObject_NEW(Owner,type,depcache); // Do not delete the underlying pointer, it is managed by the cachefile. DepCachePyObj->NoDelete = true; @@ -684,10 +684,10 @@ PyTypeObject PyDepCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DepCache", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -706,8 +706,8 @@ PyTypeObject PyDepCache_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_PkgDepCache, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -751,8 +751,8 @@ static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObjec pkgDepCache *depcache = GetCpp(Owner); pkgProblemResolver *fixer = new pkgProblemResolver(depcache); - CppOwnedPyObject *PkgProblemResolverPyObj; - PkgProblemResolverPyObj = CppOwnedPyObject_NEW(Owner, + CppPyObject *PkgProblemResolverPyObj; + PkgProblemResolverPyObj = CppPyObject_NEW(Owner, type, fixer); HandleErrors(PkgProblemResolverPyObj); @@ -871,10 +871,10 @@ PyTypeObject PyProblemResolver_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ProblemResolver", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr,// tp_dealloc + CppDeallocPtr,// tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -893,8 +893,8 @@ PyTypeObject PyProblemResolver_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), "ProblemResolver Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -959,8 +959,8 @@ static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *k pkgDepCache *depcache = GetCpp(Owner); pkgDepCache::ActionGroup *group = new pkgDepCache::ActionGroup(*depcache); - CppOwnedPyObject *PkgActionGroupPyObj; - PkgActionGroupPyObj = CppOwnedPyObject_NEW(Owner, + CppPyObject *PkgActionGroupPyObj; + PkgActionGroupPyObj = CppPyObject_NEW(Owner, type, group); HandleErrors(PkgActionGroupPyObj); @@ -987,10 +987,10 @@ PyTypeObject PyActionGroup_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ActionGroup", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -1009,8 +1009,8 @@ PyTypeObject PyActionGroup_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_PkgActionGroup, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/generic.h b/python/generic.h index d5d6e9fb..2b413a02 100644 --- a/python/generic.h +++ b/python/generic.h @@ -111,13 +111,17 @@ template struct CppPyObject : public PyObject // However if T doesn't have a default c'tor C++ doesn't generate one for // CppPyObject (since it can't know how it should initialize Object). // - // This causes problems then in CppOwnedPyObject, for which C++ can't create + // This causes problems then in CppPyObject, for which C++ can't create // a c'tor that calls the base class c'tor (which causes a compilation // error). // So basically having the c'tor here removes the need for T to have a // default c'tor, which is not always desireable. CppPyObject() { }; + // The owner of the object. The object keeps a reference to it during its + // lifetime. + PyObject *Owner; + // Flag which causes the underlying object to not be deleted. bool NoDelete; @@ -125,11 +129,6 @@ template struct CppPyObject : public PyObject T Object; }; -template struct CppOwnedPyObject : public CppPyObject -{ - PyObject *Owner; -}; - template inline T &GetCpp(PyObject *Obj) { @@ -139,121 +138,73 @@ inline T &GetCpp(PyObject *Obj) template inline PyObject *GetOwner(PyObject *Obj) { - return ((CppOwnedPyObject *)Obj)->Owner; + return ((CppPyObject *)Obj)->Owner; } -// Generic 'new' functions -template -inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== ALLOCATING " << Type->tp_name << " ===\n"; - #endif - CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); - new (&New->Object) T; - return New; -} - -template -inline CppPyObject *CppPyObject_NEW(PyTypeObject *Type,A const &Arg) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== ALLOCATING " << Type->tp_name << " ===\n"; - #endif - CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); - new (&New->Object) T(Arg); - return New; -} template -inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, - PyTypeObject *Type) +inline CppPyObject *CppPyObject_NEW(PyObject *Owner,PyTypeObject *Type) { #ifdef ALLOC_DEBUG std::cerr << "=== ALLOCATING " << Type->tp_name << "+ ===\n"; #endif - CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T; New->Owner = Owner; Py_XINCREF(Owner); return New; } -template -inline CppOwnedPyObject *CppOwnedPyObject_NEW(PyObject *Owner, - PyTypeObject *Type,A const &Arg) +template +inline CppPyObject *CppPyObject_NEW(PyObject *Owner, PyTypeObject *Type,T const &Arg) { #ifdef ALLOC_DEBUG std::cerr << "=== ALLOCATING " << Type->tp_name << "+ ===\n"; #endif - CppOwnedPyObject *New = (CppOwnedPyObject*)Type->tp_alloc(Type, 0); + CppPyObject *New = (CppPyObject*)Type->tp_alloc(Type, 0); new (&New->Object) T(Arg); New->Owner = Owner; Py_XINCREF(Owner); return New; } -// Traversal and Clean for owned objects +// Traversal and Clean for objects template -int CppOwnedTraverse(PyObject *self, visitproc visit, void* arg) { - Py_VISIT(((CppOwnedPyObject *)self)->Owner); +int CppTraverse(PyObject *self, visitproc visit, void* arg) { + Py_VISIT(((CppPyObject *)self)->Owner); return 0; } template -int CppOwnedClear(PyObject *self) { - Py_CLEAR(((CppOwnedPyObject *)self)->Owner); +int CppClear(PyObject *self) { + Py_CLEAR(((CppPyObject *)self)->Owner); return 0; } -// Generic Dealloc type functions template -void CppDealloc(PyObject *Obj) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== DEALLOCATING " << Obj->ob_type->tp_name << " ===\n"; - #endif - if (!((CppPyObject*)Obj)->NoDelete) - GetCpp(Obj).~T(); - Obj->ob_type->tp_free(Obj); -} - -template -void CppOwnedDealloc(PyObject *iObj) +void CppDealloc(PyObject *iObj) { #ifdef ALLOC_DEBUG std::cerr << "=== DEALLOCATING " << iObj->ob_type->tp_name << "+ ===\n"; #endif - CppOwnedPyObject *Obj = (CppOwnedPyObject *)iObj; + CppPyObject *Obj = (CppPyObject *)iObj; if (!((CppPyObject*)Obj)->NoDelete) Obj->Object.~T(); - CppOwnedClear(iObj); + CppClear(iObj); iObj->ob_type->tp_free(iObj); } -// Pointer deallocation -// Generic Dealloc type functions -template -void CppDeallocPtr(PyObject *Obj) -{ - #ifdef ALLOC_DEBUG - std::cerr << "=== DEALLOCATING " << Obj->ob_type->tp_name << "* ===\n"; - #endif - if (!((CppPyObject*)Obj)->NoDelete) - delete GetCpp(Obj); - Obj->ob_type->tp_free(Obj); -} template -void CppOwnedDeallocPtr(PyObject *iObj) +void CppDeallocPtr(PyObject *iObj) { #ifdef ALLOC_DEBUG std::cerr << "=== DEALLOCATING " << iObj->ob_type->tp_name << "*+ ===\n"; #endif - CppOwnedPyObject *Obj = (CppOwnedPyObject *)iObj; + CppPyObject *Obj = (CppPyObject *)iObj; if (!((CppPyObject*)Obj)->NoDelete) delete Obj->Object; - CppOwnedClear(iObj); + CppClear(iObj); iObj->ob_type->tp_free(iObj); } diff --git a/python/hashes.cc b/python/hashes.cc index 0086c17a..d0b0fb0c 100644 --- a/python/hashes.cc +++ b/python/hashes.cc @@ -25,7 +25,7 @@ static PyObject *hashes_new(PyTypeObject *type,PyObject *args, PyObject *kwds) { - return CppPyObject_NEW(type); + return CppPyObject_NEW(NULL, type); } static int hashes_init(PyObject *self, PyObject *args, PyObject *kwds) diff --git a/python/hashstring.cc b/python/hashstring.cc index 90c80e4c..d4b7a3b2 100644 --- a/python/hashstring.cc +++ b/python/hashstring.cc @@ -31,7 +31,7 @@ static PyObject *hashstring_new(PyTypeObject *type,PyObject *Args, if (PyArg_ParseTupleAndKeywords(Args, kwds, "s|s:__new__", kwlist, &Type, &Hash) == 0) return 0; - CppPyObject *PyObj = CppPyObject_NEW(type); + CppPyObject *PyObj = CppPyObject_NEW(NULL, type); if (Hash) PyObj->Object = new HashString(Type,Hash); else // Type is the combined form now (i.e. type:hash) diff --git a/python/indexfile.cc b/python/indexfile.cc index 7accaa50..e8df9cf2 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -91,11 +91,11 @@ PyTypeObject PyIndexFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.IndexFile", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods // Not ..Ptr, because the pointer is managed somewhere else. - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -112,8 +112,8 @@ PyTypeObject PyIndexFile_Type = 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags "IndexFile Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 2d21362d..5750bf6b 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -30,7 +30,7 @@ static PyObject *indexrecords_new(PyTypeObject *type,PyObject *Args, if (PyArg_ParseTupleAndKeywords(Args, kwds, "", kwlist) == 0) return 0; indexRecords *records = new indexRecords(); - CppPyObject *New = CppPyObject_NEW(type, + CppPyObject *New = CppPyObject_NEW(NULL, type, records); return New; } diff --git a/python/metaindex.cc b/python/metaindex.cc index 2c5b0bd9..dee54521 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -37,8 +37,8 @@ static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) { for (vector::const_iterator I = indexFiles->begin(); I != indexFiles->end(); I++) { - CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &PyIndexFile_Type,*I); + CppPyObject *Obj; + Obj = CppPyObject_NEW(Self, &PyIndexFile_Type,*I); // Do not delete pkgIndexFile*, they are managed by metaIndex. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -76,10 +76,10 @@ PyTypeObject PyMetaIndex_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.MetaIndex", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 58f2aaec..9b4a9ab7 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -31,7 +31,7 @@ static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); CppPyObject *PkgManagerObj = - CppPyObject_NEW(type,pm); + CppPyObject_NEW(NULL, type,pm); return PkgManagerObj; } diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index d34ba0d2..1e43b2e8 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -157,7 +157,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) &Owner) == 0) return 0; - return HandleErrors(CppOwnedPyObject_NEW(Owner,type, + return HandleErrors(CppPyObject_NEW(Owner,type, GetCpp(Owner))); } @@ -165,10 +165,10 @@ PyTypeObject PyPackageRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageRecords", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -187,8 +187,8 @@ PyTypeObject PyPackageRecords_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), "Records Object", // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 0b54c2fe..41ee6276 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -123,8 +123,8 @@ static PyObject *PkgSrcRecordsGetIndex(PyObject *Self,void*) { if (Struct.Last == 0) return 0; const pkgIndexFile &tmp = Struct.Last->Index(); - CppOwnedPyObject *PyObj; - PyObj = CppOwnedPyObject_NEW(Self,&PyIndexFile_Type, + CppPyObject *PyObj; + PyObj = CppPyObject_NEW(Self,&PyIndexFile_Type, (pkgIndexFile*)&tmp); // Do not delete the pkgIndexFile*, it is managed by PkgSrcRecords::Parser. PyObj->NoDelete=true; @@ -252,7 +252,7 @@ static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kw if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return HandleErrors(CppPyObject_NEW(type)); + return HandleErrors(CppPyObject_NEW(NULL, type)); } PyTypeObject PySourceRecords_Type = @@ -310,6 +310,6 @@ PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"") == 0) return 0; - return HandleErrors(CppPyObject_NEW(&PySourceRecords_Type)); + return HandleErrors(CppPyObject_NEW(NULL, &PySourceRecords_Type)); } #endif diff --git a/python/policy.cc b/python/policy.cc index 80670267..3e1ec589 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -34,7 +34,7 @@ static PyObject *policy_new(PyTypeObject *type,PyObject *Args, return 0; } pkgPolicy *policy = new pkgPolicy(GetCpp(cache)); - return CppOwnedPyObject_NEW(cache,&PyPolicy_Type,policy); + return CppPyObject_NEW(cache,&PyPolicy_Type,policy); } static char *policy_get_priority_doc = "get_priority(package: apt_pkg.Package)" @@ -61,7 +61,7 @@ PyObject *policy_get_candidate_ver(PyObject *self, PyObject *arg) { pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetCandidateVer(pkg); - return CppOwnedPyObject_NEW(arg,&PyVersion_Type, + return CppPyObject_NEW(arg,&PyVersion_Type, ver); } else { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); @@ -81,7 +81,7 @@ static PyObject *policy_get_match(PyObject *self, PyObject *arg) { pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetMatch(pkg); - return CppOwnedPyObject_NEW(arg,&PyVersion_Type,ver); + return CppPyObject_NEW(arg,&PyVersion_Type,ver); } static char *policy_read_pinfile_doc = "read_pinfile(filename: str) -> bool\n\n" @@ -163,10 +163,10 @@ static char *policy_doc = "Policy(cache)\n\n" PyTypeObject PyPolicy_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Policy", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDeallocPtr, // tp_dealloc + CppDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -185,8 +185,8 @@ PyTypeObject PyPolicy_Type = { Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), policy_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/python-apt.h b/python/python-apt.h index f8c21adc..6f688c93 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -218,22 +218,11 @@ static int import_apt_pkg(void) { # define PyTagSection_ToCpp GetCpp # define PyVersion_ToCpp GetCpp -// Python object creation, using two inline template functions and one variadic -// macro per type. +// Template using a simpler version of from cpp template -inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp obj, - bool Delete=false) +inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) { - CppPyObject *Obj = CppPyObject_NEW(pytype, obj); - Obj->NoDelete = (!Delete); - return Obj; -} - -template -inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, - bool Delete=false, PyObject *Owner=NULL) -{ - CppOwnedPyObject *Obj = CppOwnedPyObject_NEW(Owner, pytype, obj); + CppPyObject *Obj = CppPyObject_NEW(Owner, pytype, obj); Obj->NoDelete = (!Delete); return Obj; } @@ -241,34 +230,34 @@ inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, # ifndef APT_PKGMODULE_H # define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp #endif -# define PyAcquireFile_FromCpp(...) FromCppOwned(&PyAcquireFile_Type, ##__VA_ARGS__) -# define PyAcquireItem_FromCpp(...) FromCppOwned(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) -# define PyAcquireWorker_FromCpp(...) FromCppOwned(&PyAcquireWorker_Type,##__VA_ARGS__) -# define PyActionGroup_FromCpp(...) FromCppOwned(&PyActionGroup_Type,##__VA_ARGS__) -# define PyCache_FromCpp(...) FromCppOwned(&PyCache_Type,##__VA_ARGS__) +# define PyAcquireFile_FromCpp(...) FromCpp(&PyAcquireFile_Type, ##__VA_ARGS__) +# define PyAcquireItem_FromCpp(...) FromCpp(&PyAcquireItem_Type,##__VA_ARGS__) +# define PyAcquireItemDesc_FromCpp(...) FromCpp(&PyAcquireItemDesc_Type,##__VA_ARGS__) +# define PyAcquireWorker_FromCpp(...) FromCpp(&PyAcquireWorker_Type,##__VA_ARGS__) +# define PyActionGroup_FromCpp(...) FromCpp(&PyActionGroup_Type,##__VA_ARGS__) +# define PyCache_FromCpp(...) FromCpp(&PyCache_Type,##__VA_ARGS__) # define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) # define PyCdrom_FromCpp(...) FromCpp(&PyCdrom_Type,##__VA_ARGS__) -# define PyConfiguration_FromCpp(...) FromCppOwned(&PyConfiguration_Type, ##__VA_ARGS__) -# define PyDepCache_FromCpp(...) FromCppOwned(&PyDepCache_Type,##__VA_ARGS__) -# define PyDependency_FromCpp(...) FromCppOwned(&PyDependency_Type,##__VA_ARGS__) -//# define PyDependencyList_FromCpp(...) FromCppOwned(&PyDependencyList_Type,##__VA_ARGS__) -# define PyDescription_FromCpp(...) FromCppOwned(&PyDescription_Type,##__VA_ARGS__) +# define PyConfiguration_FromCpp(...) FromCpp(&PyConfiguration_Type, ##__VA_ARGS__) +# define PyDepCache_FromCpp(...) FromCpp(&PyDepCache_Type,##__VA_ARGS__) +# define PyDependency_FromCpp(...) FromCpp(&PyDependency_Type,##__VA_ARGS__) +//# define PyDependencyList_FromCpp(...) FromCpp(&PyDependencyList_Type,##__VA_ARGS__) +# define PyDescription_FromCpp(...) FromCpp(&PyDescription_Type,##__VA_ARGS__) # define PyHashes_FromCpp(...) FromCpp(&PyHashes_Type,##__VA_ARGS__) # define PyHashString_FromCpp(...) FromCpp(&PyHashString_Type,##__VA_ARGS__) # define PyIndexRecords_FromCpp(...) FromCpp(&PyIndexRecords_Type,##__VA_ARGS__) -# define PyMetaIndex_FromCpp(...) FromCppOwned(&PyMetaIndex_Type,##__VA_ARGS__) -# define PyPackage_FromCpp(...) FromCppOwned(&PyPackage_Type,##__VA_ARGS__) -# define PyIndexFile_FromCpp(...) FromCppOwned(&PyIndexFile_Type,##__VA_ARGS__) -# define PyPackageFile_FromCpp(...) FromCppOwned(&PyPackageFile_Type,##__VA_ARGS__) -//# define PyPackageList_FromCpp(...) FromCppOwned(&PyPackageList_Type,##__VA_ARGS__) +# define PyMetaIndex_FromCpp(...) FromCpp(&PyMetaIndex_Type,##__VA_ARGS__) +# define PyPackage_FromCpp(...) FromCpp(&PyPackage_Type,##__VA_ARGS__) +# define PyIndexFile_FromCpp(...) FromCpp(&PyIndexFile_Type,##__VA_ARGS__) +# define PyPackageFile_FromCpp(...) FromCpp(&PyPackageFile_Type,##__VA_ARGS__) +//# define PyPackageList_FromCpp(...) FromCpp(&PyPackageList_Type,##__VA_ARGS__) # define PyPackageManager_FromCpp(...) FromCpp(&PyPackageManager_Type,##__VA_ARGS__) -//# define PyPackageRecords_FromCpp(...) FromCppOwned(&PyPackageRecords_Type,##__VA_ARGS__) -# define PyPolicy_FromCpp(...) FromCppOwned(&PyPolicy_Type,##__VA_ARGS__) -# define PyProblemResolver_FromCpp(...) FromCppOwned(&PyProblemResolver_Type,##__VA_ARGS__) +//# define PyPackageRecords_FromCpp(...) FromCpp(&PyPackageRecords_Type,##__VA_ARGS__) +# define PyPolicy_FromCpp(...) FromCpp(&PyPolicy_Type,##__VA_ARGS__) +# define PyProblemResolver_FromCpp(...) FromCpp(&PyProblemResolver_Type,##__VA_ARGS__) # define PySourceList_FromCpp(...) FromCpp(&PySourceList_Type,##__VA_ARGS__) //# define PySourceRecords_FromCpp(...) FromCpp(&PySourceRecords_Type,##__VA_ARGS__) -# define PyTagFile_FromCpp(...) FromCppOwned(&PyTagFile_Type,##__VA_ARGS__) -# define PyTagSection_FromCpp(...) FromCppOwned(&PyTagSection_Type,##__VA_ARGS__) -# define PyVersion_FromCpp(...) FromCppOwned(&PyVersion_Type,##__VA_ARGS__) +# define PyTagFile_FromCpp(...) FromCpp(&PyTagFile_Type,##__VA_ARGS__) +# define PyTagSection_FromCpp(...) FromCpp(&PyTagSection_Type,##__VA_ARGS__) +# define PyVersion_FromCpp(...) FromCpp(&PyVersion_Type,##__VA_ARGS__) #endif diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 52c0e6a8..b705d8b8 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -26,7 +26,7 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) { pkgSourceList *list = GetCpp(Self); PyObject *pyPkgFileIter; - CppOwnedPyObject *pyPkgIndexFile; + CppPyObject *pyPkgIndexFile; if (PyArg_ParseTuple(Args, "O!", &PyPackageFile_Type,&pyPkgFileIter) == 0) return 0; @@ -35,7 +35,7 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) pkgIndexFile *index; if(list->FindIndex(i, index)) { - pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PyIndexFile_Type,index); + pyPkgIndexFile = CppPyObject_NEW(pyPkgFileIter,&PyIndexFile_Type,index); // Do not delete the pkgIndexFile*, it is managed by pkgSourceList. pyPkgIndexFile->NoDelete = true; return pyPkgIndexFile; @@ -92,8 +92,8 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) for (vector::const_iterator I = list->begin(); I != list->end(); I++) { - CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &PyMetaIndex_Type,*I); + CppPyObject *Obj; + Obj = CppPyObject_NEW(Self, &PyMetaIndex_Type,*I); // Never delete metaIndex*, they are managed by the pkgSourceList. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -115,7 +115,7 @@ static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kw char *kwlist[] = {0}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppPyObject_NEW(type,new pkgSourceList()); + return CppPyObject_NEW(NULL, type,new pkgSourceList()); } PyTypeObject PySourceList_Type = diff --git a/python/tag.cc b/python/tag.cc index b1a3e520..2aaf3beb 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -34,13 +34,13 @@ using namespace std; /*}}}*/ /* We need to keep a private copy of the data.. */ -struct TagSecData : public CppOwnedPyObject +struct TagSecData : public CppPyObject { char *Data; }; // The owner of the TagFile is a Python file object. -struct TagFileData : public CppOwnedPyObject +struct TagFileData : public CppPyObject { TagSecData *Section; FileFd Fd; @@ -68,7 +68,7 @@ void TagSecFree(PyObject *Obj) { TagSecData *Self = (TagSecData *)Obj; delete [] Self->Data; - CppOwnedDealloc(Obj); + CppDealloc(Obj); } /*}}}*/ // TagFileFree - Free a Tag File /*{{{*/ @@ -488,8 +488,8 @@ PyTypeObject PyTagSection_Type = Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC), doc_TagSec, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter diff --git a/python/tarfile.cc b/python/tarfile.cc index 775ae22e..aa9a39f6 100644 --- a/python/tarfile.cc +++ b/python/tarfile.cc @@ -102,8 +102,8 @@ bool PyDirStream::FinishedFile(Item &Itm,int Fd) return true; // The current member and data. - CppOwnedPyObject *py_member; - py_member = CppOwnedPyObject_NEW(0, &PyTarMember_Type); + CppPyObject *py_member; + py_member = CppPyObject_NEW(0, &PyTarMember_Type); // Clone our object, including the strings in it. py_member->Object = Itm; py_member->Object.Name = new char[strlen(Itm.Name)+1]; @@ -121,7 +121,7 @@ void tarmember_dealloc(PyObject *self) { // We cloned those strings, delete them again. delete[] GetCpp(self).Name; delete[] GetCpp(self).LinkTarget; - CppOwnedDealloc(self); + CppDealloc(self); } // The tarfile.TarInfo interface for our TarMember class. @@ -269,7 +269,7 @@ static const char *tarmember_doc = PyTypeObject PyTarMember_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_inst.TarMember", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods tarmember_dealloc, // tp_dealloc @@ -290,8 +290,8 @@ PyTypeObject PyTarMember_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, tarmember_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -318,7 +318,7 @@ static PyObject *tarfile_new(PyTypeObject *type,PyObject *args,PyObject *kwds) &max,&comp) == 0) return 0; - self = (PyTarFileObject*)CppOwnedPyObject_NEW(file,type); + self = (PyTarFileObject*)CppPyObject_NEW(file,type); // We receive a filename. if ((filename = (char*)PyObject_AsString(file))) @@ -450,7 +450,7 @@ PyTypeObject PyTarFile_Type = { sizeof(PyTarFileObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -468,8 +468,8 @@ PyTypeObject PyTarFile_Type = { Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC, tarfile_doc, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear + CppTraverse, // tp_traverse + CppClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter -- cgit v1.2.3 From b2a1af65654e4584d6b54c5d4e12175ff0dffad9 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 2 Feb 2010 17:19:25 +0100 Subject: Remove inline functions from the C++ API, export them instead (part 2). --- python/acquire.cc | 2 +- python/apt_pkgmodule.cc | 36 +++++++++++-- python/apt_pkgmodule.h | 42 ++++++++++++++- python/configuration.cc | 8 +-- python/generic.cc | 2 + python/indexrecords.cc | 2 +- python/python-apt-helpers.cc | 68 ++++++++++++++++++++++++ python/python-apt.h | 124 +++++++++++++++++++++++-------------------- setup.py | 2 +- 9 files changed, 217 insertions(+), 69 deletions(-) create mode 100644 python/python-apt-helpers.cc (limited to 'python/configuration.cc') diff --git a/python/acquire.cc b/python/acquire.cc index cd7f7709..04e00b02 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -255,7 +255,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) { PyObject *List = PyList_New(0); pkgAcquire *Owner = GetCpp(self); - CppPyObject *PyWorker = NULL; + PyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d2472395..e3da1820 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -529,64 +529,94 @@ static struct _PyAptPkgAPIStruct API = { &PyAcquire_FromCpp, // acquire_fromcpp &PyAcquire_ToCpp, // acquire_tocpp &PyAcquireFile_Type, // acquirefile_type + &PyAcquireFile_FromCpp, // acquirefile_fromcpp &PyAcquireFile_ToCpp, // acquirefile_tocpp &PyAcquireItem_Type, // acquireitem_type + &PyAcquireItem_FromCpp, // acquireitem_fromcpp &PyAcquireItem_ToCpp, // acquireitem_type &PyAcquireItemDesc_Type, // acquireitemdesc_type + &PyAcquireItemDesc_FromCpp,// acquireitemdesc_fromcpp &PyAcquireItemDesc_ToCpp, // acquireitemdesc_tocpp &PyAcquireWorker_Type, // acquireworker_type + &PyAcquireWorker_FromCpp, // acquireworker_fromcpp &PyAcquireWorker_ToCpp, // acquireworker_tocpp &PyActionGroup_Type, // actiongroup_type - &PyActionGroup_ToCpp, // actiongroup_type + &PyActionGroup_FromCpp, // actiongroup_fromcpp + &PyActionGroup_ToCpp, // actiongroup_tocpp &PyCache_Type, // cache_type + &PyCache_FromCpp, // cache_fromcpp &PyCache_ToCpp, // cache_tocpp &PyCacheFile_Type, // cachefile_type + &PyCacheFile_FromCpp, // cachefile_fromcpp &PyCacheFile_ToCpp, // cachefile_tocpp &PyCdrom_Type, // cdrom_type + &PyCdrom_FromCpp, // cdrom_fromcpp &PyCdrom_ToCpp, // cdrom_tocpp &PyConfiguration_Type, // configuration_type + &PyConfiguration_FromCpp, // configuration_fromcpp &PyConfiguration_ToCpp, // configuration_tocpp &PyDepCache_Type, // depcache_type + &PyDepCache_FromCpp, // depcache_fromcpp &PyDepCache_ToCpp, // depcache_tocpp &PyDependency_Type, // dependency_type - &PyDependency_ToCpp, // dependency_type + &PyDependency_FromCpp, // dependency_fromcpp + &PyDependency_ToCpp, // dependency_tocpp &PyDependencyList_Type, // dependencylist_type + 0, // FIXME: dependencylist_fromcpp 0, // FIXME: dependencylist_tocpp &PyDescription_Type, // description_type + &PyDescription_FromCpp, // description_fromcpp &PyDescription_ToCpp, // description_tocpp &PyHashes_Type, // hashes_type + &PyHashes_FromCpp, // hashes_fromcpp &PyHashes_ToCpp, // hashes_tocpp &PyHashString_Type, // hashstring_type + &PyHashString_FromCpp, // hashstring_fromcpp &PyHashString_ToCpp, // hashstring_tocpp &PyIndexRecords_Type, // indexrecords_type + &PyIndexRecords_FromCpp, // indexrecords_tocpp &PyIndexRecords_ToCpp, // indexrecords_tocpp &PyMetaIndex_Type, // metaindex_type + &PyMetaIndex_FromCpp, // metaindex_tocpp &PyMetaIndex_ToCpp, // metaindex_tocpp &PyPackage_Type, // package_type + &PyPackage_FromCpp, // package_tocpp &PyPackage_ToCpp, // package_tocpp &PyPackageFile_Type, // packagefile_type + &PyPackageFile_FromCpp, // packagefile_tocpp &PyPackageFile_ToCpp, // packagefile_tocpp &PyIndexFile_Type, // packageindexfile_type + &PyIndexFile_FromCpp, // packageindexfile_tocpp &PyIndexFile_ToCpp, // packageindexfile_tocpp &PyPackageList_Type, // packagelist_type + 0, // FIXME: packagelist_fromcpp 0, // FIXME: packagelist_tocpp &PyPackageManager_Type, // packagemanager_type + &PyPackageManager_FromCpp, // packagemanager_type &PyPackageManager_ToCpp, // packagemanager_type &PyPackageRecords_Type, // packagerecords_type + 0, // FIXME: packagerecords_fromcpp 0, // FIXME: packagerecords_tocpp &PyPolicy_Type, // policy_type + &PyPolicy_FromCpp, // policy_tocpp &PyPolicy_ToCpp, // policy_tocpp &PyProblemResolver_Type, // problemresolver_type + &PyProblemResolver_FromCpp, // problemresolver_tocpp &PyProblemResolver_ToCpp, // problemresolver_tocpp &PySourceList_Type, // sourcelist_type + &PySourceList_FromCpp, // sourcelist_tocpp &PySourceList_ToCpp, // sourcelist_tocpp &PySourceRecords_Type, // sourcerecords_type - 0, // sourcerecords_tocpp + 0, // FIXME: sourcerecords_fromcpp + 0, // FIXME: sourcerecords_tocpp &PyTagFile_Type, // tagfile_type + &PyTagFile_FromCpp, // tagfile_tocpp &PyTagFile_ToCpp, // tagfile_tocpp &PyTagSection_Type, // tagsection_type + &PyTagSection_FromCpp, // tagsection_tocpp &PyTagSection_ToCpp, // tagsection_tocpp &PyVersion_Type, // version_type + &PyVersion_FromCpp, // version_tocpp &PyVersion_ToCpp, // version_tocpp }; diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index a22a25f0..3dcf8069 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -13,10 +13,20 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "generic.h" // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) extern PyTypeObject PyConfiguration_Type; extern PyTypeObject PyVersion_Type; @@ -157,6 +167,36 @@ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); # define PyTagSection_ToCpp GetCpp # define PyVersion_ToCpp GetCpp +PyObject* PyAcquireFile_FromCpp(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireItem_FromCpp(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireItemDesc_FromCpp(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireWorker_FromCpp(pkgAcquire::Worker* const &obj, bool Delete, PyObject *Owner); +PyObject* PyActionGroup_FromCpp(pkgDepCache::ActionGroup* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCache_FromCpp(pkgCache* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCacheFile_FromCpp(pkgCacheFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCdrom_FromCpp(pkgCdrom const &obj, bool Delete, PyObject *Owner); +PyObject* PyConfiguration_FromCpp(Configuration* const &obj, bool Delete, PyObject *Owner); +PyObject* PyDepCache_FromCpp(pkgDepCache* const &obj, bool Delete, PyObject *Owner); +PyObject* PyDependency_FromCpp(pkgCache::DepIterator const &obj, bool Delete, PyObject *Owner); +//PyObject* PyDependencyList_FromCpp(RDepListStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyDescription_FromCpp(pkgCache::DescIterator const &obj, bool Delete, PyObject *Owner); +PyObject* PyHashes_FromCpp(Hashes const &obj, bool Delete, PyObject *Owner); +PyObject* PyHashString_FromCpp(HashString* const &obj, bool Delete, PyObject *Owner); +PyObject* PyIndexRecords_FromCpp(indexRecords* const &obj, bool Delete, PyObject *Owner); +PyObject* PyMetaIndex_FromCpp(metaIndex* const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackage_FromCpp(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner); +PyObject* PyIndexFile_FromCpp(pkgIndexFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackageFile_FromCpp(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner); +//PyObject* PyPackageList_FromCpp(PkgListStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackageManager_FromCpp(pkgPackageManager* const &obj, bool Delete, PyObject *Owner); +//PyObject* PyPackageRecords_FromCpp(PkgRecordsStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyPolicy_FromCpp(pkgPolicy* const &obj, bool Delete, PyObject *Owner); +PyObject* PyProblemResolver_FromCpp(pkgProblemResolver* const &obj, bool Delete, PyObject *Owner); +PyObject* PySourceList_FromCpp(pkgSourceList* const &obj, bool Delete, PyObject *Owner); +//PyObject* PySourceRecords_FromCpp(PkgSrcRecordsStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyTagFile_FromCpp(pkgTagFile const &obj, bool Delete, PyObject *Owner); +PyObject* PyTagSection_FromCpp(pkgTagSection const &obj, bool Delete, PyObject *Owner); +PyObject* PyVersion_FromCpp(pkgCache::VerIterator const &obj, bool Delete, PyObject *Owner); #include "python-apt.h" #endif diff --git a/python/configuration.cc b/python/configuration.cc index 0cad8db3..974f6f3d 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -280,7 +280,7 @@ PyObject *LoadConfig(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -298,7 +298,7 @@ PyObject *LoadConfigISC(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -316,7 +316,7 @@ PyObject *LoadConfigDir(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -348,7 +348,7 @@ PyObject *ParseCommandLine(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"OO!O!",&Self, &PyList_Type,&POList,&PyList_Type,&Pargv) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; diff --git a/python/generic.cc b/python/generic.cc index 51439a1b..640f0862 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -9,6 +9,8 @@ /*}}}*/ // Include Files /*{{{*/ #include "generic.h" +using namespace std; + #include /*}}}*/ diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 5750bf6b..80960160 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -60,7 +60,7 @@ static PyObject *indexrecords_lookup(PyObject *self,PyObject *args) } // Copy the HashString(), to prevent crashes and to not require the // indexRecords object to exist. - PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash)); + PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash), true, NULL); PyObject *value = Py_BuildValue("(Oi)",py_hash,result->Size); Py_DECREF(py_hash); return value; diff --git a/python/python-apt-helpers.cc b/python/python-apt-helpers.cc new file mode 100644 index 00000000..7a0f20c4 --- /dev/null +++ b/python/python-apt-helpers.cc @@ -0,0 +1,68 @@ +/* + * python-apt.h - Common object creation functions for the public API + * + * Copyright 2010 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "apt_pkgmodule.h" + +/** + * Short macro to be used for the generic FromCpp functions. + * + */ +#define NEW_FROM(NAME,TYPE,Cpp) \ +PyObject* NAME(Cpp const &obj, bool Delete, PyObject *Owner) \ +{ \ + CppPyObject *Obj = CppPyObject_NEW(Owner, TYPE, obj); \ + Obj->NoDelete = (!Delete); \ + return Obj; \ +} + +// Create all those functions +NEW_FROM(PyAcquireFile_FromCpp,&PyAcquireFile_Type,pkgAcqFile*) +NEW_FROM(PyAcquireItem_FromCpp,&PyAcquireItem_Type,pkgAcquire::Item*) +NEW_FROM(PyAcquireItemDesc_FromCpp,&PyAcquireItemDesc_Type,pkgAcquire::ItemDesc*) +NEW_FROM(PyAcquireWorker_FromCpp,&PyAcquireWorker_Type,pkgAcquire::Worker*) +NEW_FROM(PyActionGroup_FromCpp,&PyActionGroup_Type,pkgDepCache::ActionGroup*) +NEW_FROM(PyCache_FromCpp,&PyCache_Type,pkgCache*) +NEW_FROM(PyCacheFile_FromCpp,&PyCacheFile_Type,pkgCacheFile*) +NEW_FROM(PyCdrom_FromCpp,&PyCdrom_Type,pkgCdrom) +NEW_FROM(PyConfiguration_FromCpp,&PyConfiguration_Type,Configuration*) +NEW_FROM(PyDepCache_FromCpp,&PyDepCache_Type,pkgDepCache*) +NEW_FROM(PyDependency_FromCpp,&PyDependency_Type,pkgCache::DepIterator) +//NEW_FROM(PyDependencyList_FromCpp,&PyDependencyList_Type,RDepListStruct) +NEW_FROM(PyDescription_FromCpp,&PyDescription_Type,pkgCache::DescIterator) +NEW_FROM(PyHashes_FromCpp,&PyHashes_Type,Hashes) +NEW_FROM(PyHashString_FromCpp,&PyHashString_Type,HashString*) +NEW_FROM(PyIndexRecords_FromCpp,&PyIndexRecords_Type,indexRecords*) +NEW_FROM(PyMetaIndex_FromCpp,&PyMetaIndex_Type,metaIndex*) +NEW_FROM(PyPackage_FromCpp,&PyPackage_Type,pkgCache::PkgIterator) +NEW_FROM(PyIndexFile_FromCpp,&PyIndexFile_Type,pkgIndexFile*) +NEW_FROM(PyPackageFile_FromCpp,&PyPackageFile_Type,pkgCache::PkgFileIterator) +//NEW_FROM(PyPackageList_FromCpp,&PyPackageList_Type,PkgListStruct) +NEW_FROM(PyPackageManager_FromCpp,&PyPackageManager_Type,pkgPackageManager*) +//NEW_FROM(PyPackageRecords_FromCpp,&PyPackageRecords_Type,PkgRecordsStruct) +NEW_FROM(PyPolicy_FromCpp,&PyPolicy_Type,pkgPolicy*) +NEW_FROM(PyProblemResolver_FromCpp,&PyProblemResolver_Type,pkgProblemResolver*) +NEW_FROM(PySourceList_FromCpp,&PySourceList_Type,pkgSourceList*) +//NEW_FROM(PySourceRecords_FromCpp,&PySourceRecords_Type,PkgSrcRecordsStruct) +NEW_FROM(PyTagFile_FromCpp,&PyTagFile_Type,pkgTagFile) +NEW_FROM(PyTagSection_FromCpp,&PyTagSection_Type,pkgTagSection) +NEW_FROM(PyVersion_FromCpp,&PyVersion_Type,pkgCache::VerIterator) + +#undef NEW_FROM diff --git a/python/python-apt.h b/python/python-apt.h index 7b34c249..0c25ff02 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -47,94 +47,126 @@ struct _PyAptPkgAPIStruct { pkgAcquire*& (*acquire_tocpp)(PyObject *self); // apt_pkg.AcquireFile PyTypeObject *acquirefile_type; + PyObject* (*acquirefile_fromcpp)(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); pkgAcqFile*& (*acquirefile_tocpp)(PyObject *self); + // apt_pkg.AcquireItem PyTypeObject *acquireitem_type; + PyObject* (*acquireitem_fromcpp)(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); pkgAcquire::Item*& (*acquireitem_tocpp)(PyObject *self); // apt_pkg.AcquireItemDesc PyTypeObject *acquireitemdesc_type; + PyObject* (*acquireitemdesc_fromcpp)(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); pkgAcquire::ItemDesc*& (*acquireitemdesc_tocpp)(PyObject *self); PyTypeObject *acquireworker_type; + PyObject* (*acquireworker_fromcpp)(pkgAcquire::Worker* const &obj, bool Delete, PyObject *Owner); pkgAcquire::Worker*& (*acquireworker_tocpp)(PyObject *self); PyTypeObject *actiongroup_type; + PyObject* (*actiongroup_fromcpp)(pkgDepCache::ActionGroup* const &obj, bool Delete, PyObject *Owner); pkgDepCache::ActionGroup*& (*actiongroup_tocpp)(PyObject *self); PyTypeObject *cache_type; + PyObject* (*cache_fromcpp)(pkgCache* const &obj, bool Delete, PyObject *Owner); pkgCache*& (*cache_tocpp)(PyObject *self); PyTypeObject *cachefile_type; + PyObject* (*cachefile_fromcpp)(pkgCacheFile* const &obj, bool Delete, PyObject *Owner); pkgCacheFile*& (*cachefile_tocpp)(PyObject *self); PyTypeObject *cdrom_type; + PyObject* (*cdrom_fromcpp)(pkgCdrom const &obj, bool Delete, PyObject *Owner); pkgCdrom& (*cdrom_tocpp)(PyObject *self); PyTypeObject *configuration_type; + PyObject* (*configuration_fromcpp)(Configuration* const &obj, bool Delete, PyObject *Owner); Configuration*& (*configuration_tocpp)(PyObject *self); PyTypeObject *depcache_type; + PyObject* (*depcache_fromcpp)(pkgDepCache* const &obj, bool Delete, PyObject *Owner); pkgDepCache*& (*depcache_tocpp)(PyObject *self); PyTypeObject *dependency_type; + PyObject* (*dependency_fromcpp)(pkgCache::DepIterator const &obj, bool Delete, PyObject *Owner); pkgCache::DepIterator& (*dependency_tocpp)(PyObject *self); PyTypeObject *dependencylist_type; - void *dependencylist_tocpp; // FIXME: need packagelist_tocpp + void *dependencylist_fromcpp; // FIXME: need dependencylist_fromcpp + void *dependencylist_tocpp; // FIXME: need dependencylist_tocpp PyTypeObject *description_type; + PyObject* (*description_fromcpp)(pkgCache::DescIterator const &obj, bool Delete, PyObject *Owner); pkgCache::DescIterator& (*description_tocpp)(PyObject *self); PyTypeObject *hashes_type; + PyObject* (*hashes_fromcpp)(Hashes const &obj, bool Delete, PyObject *Owner); Hashes& (*hashes_tocpp)(PyObject *self); PyTypeObject *hashstring_type; + PyObject* (*hashstring_fromcpp)(HashString* const &obj, bool Delete, PyObject *Owner); HashString*& (*hashstring_tocpp)(PyObject *self); PyTypeObject *indexrecords_type; + PyObject* (*indexrecords_fromcpp)(indexRecords* const &obj, bool Delete, PyObject *Owner); indexRecords*& (*indexrecords_tocpp)(PyObject *self); PyTypeObject *metaindex_type; + PyObject* (*metaindex_fromcpp)(metaIndex* const &obj, bool Delete, PyObject *Owner); metaIndex*& (*metaindex_tocpp)(PyObject *self); PyTypeObject *package_type; + PyObject* (*package_fromcpp)(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner); pkgCache::PkgIterator& (*package_tocpp)(PyObject *self); PyTypeObject *packagefile_type; + PyObject* (*packagefile_fromcpp)(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner); pkgCache::PkgFileIterator& (*packagefile_tocpp)(PyObject *self); PyTypeObject *packageindexfile_type; + PyObject* (*indexfile_fromcpp)(pkgIndexFile* const &obj, bool Delete, PyObject *Owner); pkgIndexFile*& (*packageindexfile_tocpp)(PyObject *self); PyTypeObject *packagelist_type; + void *packagelist_fromcpp; // FIXME: need packagelist_fromcpp void *packagelist_tocpp; // FIXME: need packagelist_tocpp PyTypeObject *packagemanager_type; + PyObject* (*packagemanager_fromcpp)(pkgPackageManager* const &obj, bool Delete, PyObject *Owner); pkgPackageManager*& (*packagemanager_tocpp)(PyObject *self); PyTypeObject *packagerecords_type; + void *packagerecords_fromcpp; // FIXME: need packagerecords_fromcpp void *packagerecords_tocpp; // FIXME: need packagerecords_tocpp PyTypeObject *policy_type; + PyObject* (*policy_fromcpp)(pkgPolicy* const &obj, bool Delete, PyObject *Owner); pkgPolicy*& (*policy_tocpp)(PyObject *self); PyTypeObject *problemresolver_type; + PyObject* (*problemresolver_fromcpp)(pkgProblemResolver* const &obj, bool Delete, PyObject *Owner); pkgProblemResolver*& (*problemresolver_tocpp)(PyObject *self); PyTypeObject *sourcelist_type; + PyObject* (*sourcelist_fromcpp)(pkgSourceList* const &obj, bool Delete, PyObject *Owner); pkgSourceList*& (*sourcelist_tocpp)(PyObject *self); PyTypeObject *sourcerecords_type; + void *sourcerecords_fromcpp; // FIXME: need sourcerecords_fromcpp void *sourcerecords_tocpp; // FIXME: need sourcerecords_tocpp PyTypeObject *tagfile_type; + PyObject* (*tagfile_fromcpp)(pkgTagFile const &obj, bool Delete, PyObject *Owner); pkgTagFile& (*tagfile_tocpp)(PyObject *self); PyTypeObject *tagsection_type; + PyObject* (*tagsection_fromcpp)(pkgTagSection const &obj, bool Delete, PyObject *Owner); pkgTagSection& (*tagsection_tocpp)(PyObject *self); PyTypeObject *version_type; + PyObject* (*version_fromcpp)(pkgCache::VerIterator const &obj, bool Delete, PyObject *Owner); pkgCache::VerIterator& (*version_tocpp)(PyObject *self); + }; // Checking macros. @@ -208,24 +240,10 @@ static struct _PyAptPkgAPIStruct *_PyAptPkg_API; static int import_apt_pkg(void) { # if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCapsule_Import("apt_pkg._C_API", 0); - return (_PyAptPkg_API != NULL) ? 0 : -1; # else - - PyObject *module = PyImport_ImportModule("apt_pkg"); - - if (module == NULL) { - return -1; - } - if (module != NULL) { - PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API"); - if (c_api_object == NULL) - return -1; - if (PyCObject_Check(c_api_object)) - _PyAptPkg_API = (struct _PyAptPkgAPIStruct *)PyCObject_AsVoidPtr(c_api_object); - Py_DECREF(c_api_object); - } - return 0; + _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCObject_Import("apt_pkg", "_C_API"); # endif // PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 + return (_PyAptPkg_API != NULL) ? 0 : -1; } # define PyAcquire_Type *(_PyAptPkg_API->acquire_type) @@ -292,48 +310,38 @@ static int import_apt_pkg(void) { # define PyTagSection_ToCpp _PyAptPkg_API->tagsection_tocpp # define PyVersion_ToCpp _PyAptPkg_API->version_tocpp // Get the C++ object -# define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp +# define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp +# define PyAcquireFile_FromCpp _PyAptPkg_API->acquirefile_fromcpp +# define PyAcquireItem_FromCpp _PyAptPkg_API->acquireitem_fromcpp +# define PyAcquireItemDesc_FromCpp _PyAptPkg_API->acquireitemdesc_fromcpp +# define PyAcquireWorker_FromCpp _PyAptPkg_API->acquireworker_fromcpp +# define PyActionGroup_FromCpp _PyAptPkg_API->actiongroup_fromcpp +# define PyCache_FromCpp _PyAptPkg_API->cache_fromcpp +# define PyCacheFile_FromCpp _PyAptPkg_API->cachefile_fromcpp +# define PyCdrom_FromCpp _PyAptPkg_API->cdrom_fromcpp +# define PyConfiguration_FromCpp _PyAptPkg_API->configuration_fromcpp +# define PyDepCache_FromCpp _PyAptPkg_API->depcache_fromcpp +# define PyDependency_FromCpp _PyAptPkg_API->dependency_fromcpp +# define PyDependencyList_FromCpp _PyAptPkg_API->dependencylist_fromcpp // NULL +# define PyDescription_FromCpp _PyAptPkg_API->description_fromcpp +# define PyHashes_FromCpp _PyAptPkg_API->hashes_fromcpp +# define PyHashString_FromCpp _PyAptPkg_API->hashstring_fromcpp +# define PyIndexRecords_FromCpp _PyAptPkg_API->indexrecords_fromcpp +# define PyMetaIndex_FromCpp _PyAptPkg_API->metaindex_fromcpp +# define PyPackage_FromCpp _PyAptPkg_API->package_fromcpp +# define PyPackageFile_FromCpp _PyAptPkg_API->packagefile_fromcpp +# define PyIndexFile_FromCpp _PyAptPkg_API->packageindexfile_fromcpp +# define PyPackageList_FromCpp _PyAptPkg_API->packagelist_fromcpp // NULL +# define PyPackageManager_FromCpp _PyAptPkg_API->packagemanager_fromcpp +# define PyPackageRecords_FromCpp _PyAptPkg_API->packagerecords_fromcpp +# define PyPolicy_FromCpp _PyAptPkg_API->policy_fromcpp +# define PyProblemResolver_FromCpp _PyAptPkg_API->problemresolver_fromcpp +# define PySourceList_FromCpp _PyAptPkg_API->sourcelist_fromcpp +# define PySourceRecords_FromCpp _PyAptPkg_API->sourcerecords_fromcpp // NULL +# define PyTagFile_FromCpp _PyAptPkg_API->tagfile_fromcpp +# define PyTagSection_FromCpp _PyAptPkg_API->tagsection_fromcpp +# define PyVersion_FromCpp _PyAptPkg_API->version_fromcpp # endif // APT_PKGMODULE_H -// Template using a simpler version of from cpp -template -inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) -{ - CppPyObject *Obj = CppPyObject_NEW(Owner, pytype, obj); - Obj->NoDelete = (!Delete); - return Obj; -} - - -# define PyAcquireFile_FromCpp(...) FromCpp(&PyAcquireFile_Type, ##__VA_ARGS__) -# define PyAcquireItem_FromCpp(...) FromCpp(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCpp(&PyAcquireItemDesc_Type,##__VA_ARGS__) -# define PyAcquireWorker_FromCpp(...) FromCpp(&PyAcquireWorker_Type,##__VA_ARGS__) -# define PyActionGroup_FromCpp(...) FromCpp(&PyActionGroup_Type,##__VA_ARGS__) -# define PyCache_FromCpp(...) FromCpp(&PyCache_Type,##__VA_ARGS__) -# define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) -# define PyCdrom_FromCpp(...) FromCpp(&PyCdrom_Type,##__VA_ARGS__) -# define PyConfiguration_FromCpp(...) FromCpp(&PyConfiguration_Type, ##__VA_ARGS__) -# define PyDepCache_FromCpp(...) FromCpp(&PyDepCache_Type,##__VA_ARGS__) -# define PyDependency_FromCpp(...) FromCpp(&PyDependency_Type,##__VA_ARGS__) -//# define PyDependencyList_FromCpp(...) FromCpp(&PyDependencyList_Type,##__VA_ARGS__) -# define PyDescription_FromCpp(...) FromCpp(&PyDescription_Type,##__VA_ARGS__) -# define PyHashes_FromCpp(...) FromCpp(&PyHashes_Type,##__VA_ARGS__) -# define PyHashString_FromCpp(...) FromCpp(&PyHashString_Type,##__VA_ARGS__) -# define PyIndexRecords_FromCpp(...) FromCpp(&PyIndexRecords_Type,##__VA_ARGS__) -# define PyMetaIndex_FromCpp(...) FromCpp(&PyMetaIndex_Type,##__VA_ARGS__) -# define PyPackage_FromCpp(...) FromCpp(&PyPackage_Type,##__VA_ARGS__) -# define PyIndexFile_FromCpp(...) FromCpp(&PyIndexFile_Type,##__VA_ARGS__) -# define PyPackageFile_FromCpp(...) FromCpp(&PyPackageFile_Type,##__VA_ARGS__) -//# define PyPackageList_FromCpp(...) FromCpp(&PyPackageList_Type,##__VA_ARGS__) -# define PyPackageManager_FromCpp(...) FromCpp(&PyPackageManager_Type,##__VA_ARGS__) -//# define PyPackageRecords_FromCpp(...) FromCpp(&PyPackageRecords_Type,##__VA_ARGS__) -# define PyPolicy_FromCpp(...) FromCpp(&PyPolicy_Type,##__VA_ARGS__) -# define PyProblemResolver_FromCpp(...) FromCpp(&PyProblemResolver_Type,##__VA_ARGS__) -# define PySourceList_FromCpp(...) FromCpp(&PySourceList_Type,##__VA_ARGS__) -//# define PySourceRecords_FromCpp(...) FromCpp(&PySourceRecords_Type,##__VA_ARGS__) -# define PyTagFile_FromCpp(...) FromCpp(&PyTagFile_Type,##__VA_ARGS__) -# define PyTagSection_FromCpp(...) FromCpp(&PyTagSection_Type,##__VA_ARGS__) -# define PyVersion_FromCpp(...) FromCpp(&PyVersion_Type,##__VA_ARGS__) #endif diff --git a/setup.py b/setup.py index 635fee9b..2fa8198b 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', - 'lock.cc', 'acquire-item.cc'] + 'lock.cc', 'acquire-item.cc', 'python-apt-helpers.cc'] files = sorted(['python/' + fname for fname in files], key=lambda s: s[:-3]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) -- cgit v1.2.3 From a169fd15520d61303639c0dfa2aabec3f6446fb6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 27 Feb 2010 17:31:39 +0100 Subject: * python: - Handle deprecated attributes and methods in the tp_gettattro slot, this allows us to easily warn if a deprecated function is used. --- debian/changelog | 7 ++-- python/acquire-item.cc | 13 +------- python/acquire.cc | 12 +------ python/cache.cc | 88 ++++--------------------------------------------- python/cdrom.cc | 8 +++-- python/configuration.cc | 16 +-------- python/depcache.cc | 46 ++------------------------ python/generic.cc | 62 ++++++++++++++++++++++++++++++++++ python/generic.h | 6 ++++ python/indexfile.cc | 13 +------- python/metaindex.cc | 8 +---- python/pkgmanager.cc | 7 +--- python/pkgrecords.cc | 19 +---------- python/pkgsrcrecords.cc | 14 +------- python/sourcelist.cc | 10 +----- python/tag.cc | 19 ++--------- 16 files changed, 98 insertions(+), 250 deletions(-) (limited to 'python/configuration.cc') diff --git a/debian/changelog b/debian/changelog index 25553644..e5945ef4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.7.93.2) UNRELEASED; urgency=low +python-apt (0.7.93.2) unstable; urgency=low [ Julian Andres Klode ] * Fix some places where the old API was still used: @@ -8,6 +8,9 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * utils/migrate-0.8.py: - Improve C++ parsing and add apt.progress.old to the modules, reduces false positives. + * python: + - Handle deprecated attributes and methods in the tp_gettattro slot, this + allows us to easily warn if a deprecated function is used. * python/tagfile.cc: - Implement the iterator protocol in TagFile. * python/cache.cc: @@ -35,7 +38,7 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * python/progress.cc: - try to call compatibility functions first, then new functions - -- Julian Andres Klode Sun, 07 Feb 2010 19:58:40 +0100 + -- Julian Andres Klode Sat, 27 Feb 2010 14:00:43 +0100 python-apt (0.7.93.1) unstable; urgency=low diff --git a/python/acquire-item.cc b/python/acquire-item.cc index d5f9ad10..09f0d643 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -128,17 +128,6 @@ static PyGetSetDef acquireitem_getset[] = { {"is_trusted",acquireitem_get_is_trusted}, {"local",acquireitem_get_local}, {"status",acquireitem_get_status}, -#ifdef COMPAT_0_7 - {"Complete",acquireitem_get_complete}, - {"DescURI",acquireitem_get_desc_uri}, - {"DestFile",acquireitem_get_destfile}, - {"ErrorText",acquireitem_get_error_text}, - {"FileSize",acquireitem_get_filesize}, - {"ID",acquireitem_get_id}, - {"IsTrusted",acquireitem_get_is_trusted}, - {"Local",acquireitem_get_local}, - {"Status",acquireitem_get_status}, -#endif {} }; @@ -180,7 +169,7 @@ PyTypeObject PyAcquireItem_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | diff --git a/python/acquire.cc b/python/acquire.cc index 5e22280e..cc9ee310 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -229,10 +229,6 @@ static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) static PyMethodDef PkgAcquireMethods[] = { {"run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, {"shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, -#ifdef COMPAT_0_7 - {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, - {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, -#endif {} }; @@ -284,12 +280,6 @@ static PyGetSetDef PkgAcquireGetSet[] = { {"workers",PkgAcquireGetWorkers}, {"partial_present",PkgAcquireGetPartialPresent}, {"total_needed",PkgAcquireGetTotalNeeded}, -#ifdef COMPAT_0_7 - {"FetchNeeded",PkgAcquireGetFetchNeeded}, - {"Items",PkgAcquireGetItems}, - {"PartialPresent",PkgAcquireGetPartialPresent}, - {"TotalNeeded",PkgAcquireGetTotalNeeded}, -#endif {} }; @@ -354,7 +344,7 @@ PyTypeObject PyAcquire_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/cache.cc b/python/cache.cc index 5743d9df..3c9bc785 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -153,7 +153,6 @@ static PyMethodDef PkgCacheMethods[] = { {"update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, #ifdef COMPAT_0_7 - {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, {"Open", PkgCacheOpen, METH_VARARGS,"Open the cache"}, {"Close", PkgCacheClose, METH_VARARGS,"Close the cache"}, #endif @@ -216,16 +215,6 @@ static PyGetSetDef PkgCacheGetSet[] = { {"provides_count",PkgCacheGetProvidesCount}, {"ver_file_count",PkgCacheGetVerFileCount}, {"version_count",PkgCacheGetVersionCount}, -#ifdef COMPAT_0_7 - {"DependsCount",PkgCacheGetDependsCount}, - {"FileList",PkgCacheGetFileList}, - {"PackageCount",PkgCacheGetPackageCount}, - {"PackageFileCount",PkgCacheGetPackageFileCount}, - {"Packages",PkgCacheGetPackages}, - {"ProvidesCount",PkgCacheGetProvidesCount}, - {"VerFileCount",PkgCacheGetVerFileCount}, - {"VersionCount",PkgCacheGetVersionCount}, -#endif {} }; @@ -349,7 +338,7 @@ PyTypeObject PyCache_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -543,21 +532,6 @@ static PyGetSetDef PackageGetSet[] = { {"important",PackageGetImportant}, {"version_list",PackageGetVersionList}, {"current_ver",PackageGetCurrentVer}, - #ifdef COMPAT_0_7 - {"Name",PackageGetName}, - {"Section",PackageGetSection}, - {"RevDependsList",PackageGetRevDependsList}, - {"ProvidesList",PackageGetProvidesList}, - {"SelectedState",PackageGetSelectedState}, - {"InstState",PackageGetInstState}, - {"CurrentState",PackageGetCurrentState}, - {"ID",PackageGetID}, - {"Auto",PackageGetAuto}, - {"Essential",PackageGetEssential}, - {"Important",PackageGetImportant}, - {"VersionList",PackageGetVersionList}, - {"CurrentVer",PackageGetCurrentVer}, - #endif {} }; @@ -590,7 +564,7 @@ PyTypeObject PyPackage_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -641,10 +615,6 @@ static PyGetSetDef DescriptionGetSet[] = { {"language_code",DescriptionGetLanguageCode}, {"md5",DescriptionGetMd5}, {"file_list",DescriptionGetFileList}, - #ifdef COMPAT_0_7 - {"LanguageCode",DescriptionGetLanguageCode}, - {"FileList",DescriptionGetFileList}, - #endif {} }; @@ -675,7 +645,7 @@ PyTypeObject PyDescription_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -886,24 +856,6 @@ static PyGetSetDef VersionGetSet[] = { {"size",VersionGetSize}, {"translated_description",VersionGetTranslatedDescription}, {"ver_str",VersionGetVerStr}, -#ifdef COMPAT_0_7 - {"Arch",VersionGetArch}, - {"DependsList",VersionGetDependsList}, - {"DependsListStr",VersionGetDependsListStr}, - {"Downloadable",VersionGetDownloadable}, - {"FileList",VersionGetFileList}, - {"Hash",VersionGetHash}, - {"ID",VersionGetID}, - {"InstalledSize",VersionGetInstalledSize}, - {"ParentPkg",VersionGetParentPkg}, - {"Priority",VersionGetPriority}, - {"PriorityStr",VersionGetPriorityStr}, - {"ProvidesList",VersionGetProvidesList}, - {"Section",VersionGetSection}, - {"Size",VersionGetSize}, - {"TranslationDescription",VersionGetTranslatedDescription}, - {"VerStr",VersionGetVerStr}, -#endif {} }; @@ -926,7 +878,7 @@ PyTypeObject PyVersion_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -1053,21 +1005,6 @@ static PyGetSetDef PackageFileGetSet[] = { {(char*)"site",PackageFile_GetSite}, {(char*)"size",PackageFile_GetSize}, {(char*)"version",PackageFile_GetVersion}, - #ifdef COMPAT_0_7 - {"Architecture",PackageFile_GetArchitecture}, - {"Archive",PackageFile_GetArchive}, - {"Component",PackageFile_GetComponent}, - {"FileName",PackageFile_GetFileName}, - {"ID",PackageFile_GetID}, - {"IndexType",PackageFile_GetIndexType}, - {"Label",PackageFile_GetLabel}, - {"NotAutomatic",PackageFile_GetNotAutomatic}, - {"NotSource",PackageFile_GetNotSource}, - {"Origin",PackageFile_GetOrigin}, - {"Site",PackageFile_GetSite}, - {"Size",PackageFile_GetSize}, - {"Version",PackageFile_GetVersion}, - #endif {} }; @@ -1088,7 +1025,7 @@ PyTypeObject PyPackageFile_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -1158,10 +1095,6 @@ static PyMethodDef DependencyMethods[] = { {"smart_target_pkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, {"all_targets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, -#ifdef COMPAT_0_7 - {"SmartTargetPkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, - {"AllTargets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, -#endif {} }; @@ -1240,15 +1173,6 @@ static PyGetSetDef DependencyGetSet[] = { {"parent_ver",DependencyGetParentVer}, {"target_pkg",DependencyGetTargetPkg}, {"target_ver",DependencyGetTargetVer}, -#ifdef COMPAT_0_7 - {"CompType",DependencyGetCompType}, - {"DepType",DependencyGetDepType}, - {"ID",DependencyGetID}, - {"ParentPkg",DependencyGetParentPkg}, - {"ParentVer",DependencyGetParentVer}, - {"TargetPkg",DependencyGetTargetPkg}, - {"TargetVer",DependencyGetTargetVer}, -#endif {} }; @@ -1272,7 +1196,7 @@ PyTypeObject PyDependency_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags diff --git a/python/cdrom.cc b/python/cdrom.cc index 0b9ae578..9eae49dc 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -78,6 +78,9 @@ static PyObject *cdrom_ident(PyObject *Self,PyObject *Args) #ifdef COMPAT_0_7 static PyObject *cdrom_ident_old(PyObject *Self,PyObject *Args) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Method 'Ident' of the " + "'apt_pkg.Cdrom' object is deprecated, use 'ident' instead.", + 1); pkgCdrom &Cdrom = GetCpp(Self); PyObject *pyCdromProgressInst = 0; @@ -101,8 +104,7 @@ static PyMethodDef cdrom_methods[] = { {"add",cdrom_add,METH_VARARGS,cdrom_add_doc}, {"ident",cdrom_ident,METH_VARARGS,cdrom_ident_doc}, #ifdef COMPAT_0_7 - {"Add",cdrom_add,METH_VARARGS,"Add(progress) -> Add a cdrom"}, - {"Ident",cdrom_ident_old,METH_VARARGS,"Ident(progress) -> Ident a cdrom"}, + {"Ident",cdrom_ident_old,METH_VARARGS,"DEPRECATED. DO NOT USE"}, #endif {} }; @@ -134,7 +136,7 @@ PyTypeObject PyCdrom_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/configuration.cc b/python/configuration.cc index 974f6f3d..299e06ec 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -446,20 +446,6 @@ static PyMethodDef CnfMethods[] = {"value_list",CnfValueList,METH_VARARGS,doc_ValueList}, {"my_tag",CnfMyTag,METH_VARARGS,doc_MyTag}, {"clear",CnfClear,METH_VARARGS,doc_Clear}, -#ifdef COMPAT_0_7 - {"Find",CnfFind,METH_VARARGS,doc_Find}, - {"FindFile",CnfFindFile,METH_VARARGS,doc_FindFile}, - {"FindDir",CnfFindDir,METH_VARARGS,doc_FindDir}, - {"FindI",CnfFindI,METH_VARARGS,doc_FindI}, - {"FindB",CnfFindB,METH_VARARGS,doc_FindB}, - {"Set",CnfSet,METH_VARARGS,doc_Set}, - {"Exists",CnfExists,METH_VARARGS,doc_Exists}, - {"SubTree",CnfSubTree,METH_VARARGS,doc_SubTree}, - {"List",CnfList,METH_VARARGS,doc_List}, - {"ValueList",CnfValueList,METH_VARARGS,doc_ValueList}, - {"MyTag",CnfMyTag,METH_VARARGS,doc_MyTag}, - {"Clear",CnfClear,METH_VARARGS,doc_Clear}, -#endif // Python Special {"keys",CnfKeys,METH_VARARGS,doc_Keys}, #if PY_MAJOR_VERSION < 3 @@ -498,7 +484,7 @@ PyTypeObject PyConfiguration_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/depcache.cc b/python/depcache.cc index 53459c32..8b4e02b5 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -569,34 +569,8 @@ static PyMethodDef PkgDepCacheMethods[] = {"marked_keep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, {"marked_reinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, {"marked_downgrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - // Action {"commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, -#ifdef COMPAT_0_7 - {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, - {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, - {"SetCandidateVer",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, - {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, - {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, - {"ReadPinFile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, - {"MinimizeUpgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, - {"MarkKeep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, - {"MarkDelete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, - {"MarkInstall",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, - {"SetReInstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, - {"IsUpgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, - {"IsNowBroken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, - {"IsInstBroken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, - {"IsGarbage",PkgDepCacheIsGarbage,METH_VARARGS,"Is pkg garbage (mark-n-sweep)"}, - {"IsAutoInstalled",PkgDepCacheIsAutoInstalled,METH_VARARGS,"Is pkg marked as auto installed"}, - {"MarkedInstall",PkgDepCacheMarkedInstall,METH_VARARGS,"Is pkg marked for install"}, - {"MarkedUpgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"}, - {"MarkedDelete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"}, - {"MarkedKeep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, - {"MarkedReinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, - {"MarkedDowngrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - {"Commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, -#endif {} }; @@ -641,14 +615,6 @@ static PyGetSetDef PkgDepCacheGetSet[] = { {"keep_count",PkgDepCacheGetKeepCount}, {"usr_size",PkgDepCacheGetUsrSize}, {"policy",PkgDepCacheGetPolicy}, - #ifdef COMPAT_0_7 - {"BrokenCount",PkgDepCacheGetBrokenCount}, - {"DebSize",PkgDepCacheGetDebSize}, - {"DelCount",PkgDepCacheGetDelCount}, - {"InstCount",PkgDepCacheGetInstCount}, - {"KeepCount",PkgDepCacheGetKeepCount}, - {"UsrSize",PkgDepCacheGetUsrSize}, - #endif {} }; @@ -699,7 +665,7 @@ PyTypeObject PyDepCache_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -856,14 +822,6 @@ static PyMethodDef PkgProblemResolverMethods[] = // Actions {"resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, {"resolve_by_keep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, - #ifdef COMPAT_0_7 - {"Protect", PkgProblemResolverProtect, METH_VARARGS, "Protect(PkgIterator)"}, - {"Remove", PkgProblemResolverRemove, METH_VARARGS, "Remove(PkgIterator)"}, - {"Clear", PkgProblemResolverClear, METH_VARARGS, "Clear(PkgIterator)"}, - {"InstallProtect", PkgProblemResolverInstallProtect, METH_VARARGS, "ProtectInstalled()"}, - {"Resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, - {"ResolveByKeep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, - #endif {} }; @@ -886,7 +844,7 @@ PyTypeObject PyProblemResolver_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/generic.cc b/python/generic.cc index 640f0862..7af34d39 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -48,6 +48,68 @@ PyObject *HandleErrors(PyObject *Res) PyErr_SetString(PyExc_SystemError,Err.c_str()); return 0; } + +# ifdef COMPAT_0_7 +// Helpers for deprecation. + +// Given the name of the old attribute, return the name of the new attribute +// in a PyObject. +static PyObject *_PyApt_NewNameForAttribute(const char *attr) { + // Some exceptions from the standard algorithm. + if (strcasecmp(attr, "FileName") == 0) return PyString_FromString("filename"); + if (strcasecmp(attr, "DestFile") == 0) return PyString_FromString("destfile"); + if (strcasecmp(attr, "FileSize") == 0) return PyString_FromString("filesize"); + if (strcasecmp(attr, "SubTree") == 0) return PyString_FromString("subtree"); + if (strcasecmp(attr, "ReadPinFile") == 0) return PyString_FromString("read_pinfile"); + if (strcasecmp(attr, "SetReInstall") == 0) return PyString_FromString("set_reinstall"); + if (strcasecmp(attr, "URI") == 0) return PyString_FromString("uri"); + if (strcasecmp(attr, "MD5Hash") == 0) return PyString_FromString("md5_hash"); + if (strcasecmp(attr, "SHA1Hash") == 0) return PyString_FromString("sha1_hash"); + if (strcasecmp(attr, "SHA256Hash") == 0) return PyString_FromString("sha256_hash"); + size_t attrlen = strlen(attr); + // Reserve the old name + 5, this should reduce resize to a minimum. + string new_name; + new_name.reserve(attrlen + 5); + for(unsigned int i=0; i < attrlen; i++) { + // Replace all uppercase ASCII characters with their lower-case ones. + if (attr[i] > 64 && attr[i] < 91) { + if (i > 0) + new_name += "_"; + new_name += attr[i] + 32; + } else { + new_name += attr[i]; + } + } + return CppPyString(new_name); +} + +// Handle deprecated attributes by setting a warning and returning the new +// attribute. +PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr) { + PyObject *value = PyObject_GenericGetAttr(self, attr); + if (value == NULL) { + PyObject *ptype, *pvalue, *ptraceback; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + const char *attrname = PyObject_AsString(attr); + PyObject *newattr = _PyApt_NewNameForAttribute(attrname); + value = PyObject_GenericGetAttr(self, newattr); + if (value != NULL) { + const char *newattrname = PyString_AsString(newattr); + const char *cls = self->ob_type->tp_name; + char *warning_string = new char[strlen(newattrname) + strlen(cls) + + strlen(attrname) + 66]; + sprintf(warning_string, "Attribute '%s' of the '%s' object is " + "deprecated, use '%s' instead.", attrname, cls, newattrname); + PyErr_WarnEx(PyExc_DeprecationWarning, warning_string, 1); + delete[] warning_string; + } else { + PyErr_Restore(ptype, pvalue, ptraceback); + } + Py_DECREF(newattr); + } + return value; +} +# endif //COMPAT_0_7 /*}}}*/ // ListToCharChar - Convert a list to an array of char char /*{{{*/ // --------------------------------------------------------------------- diff --git a/python/generic.h b/python/generic.h index 7d2d6d3e..31c1bc2d 100644 --- a/python/generic.h +++ b/python/generic.h @@ -227,4 +227,10 @@ PyObject *HandleErrors(PyObject *Res = 0); const char **ListToCharChar(PyObject *List,bool NullTerm = false); PyObject *CharCharToList(const char **List,unsigned long Size = 0); +# ifdef COMPAT_0_7 +PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr); +# else +# define _PyAptObject_getattro 0 +# endif + #endif diff --git a/python/indexfile.cc b/python/indexfile.cc index e8df9cf2..c6d0b1cc 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -28,9 +28,6 @@ static PyObject *IndexFileArchiveURI(PyObject *Self,PyObject *Args) static PyMethodDef IndexFileMethods[] = { {"archive_uri",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, - #ifdef COMPAT_0_7 - {"ArchiveURI",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, - #endif {} }; @@ -76,14 +73,6 @@ static PyGetSetDef IndexFileGetSet[] = { {"is_trusted",IndexFileGetIsTrusted}, {"label",IndexFileGetLabel}, {"size",IndexFileGetSize}, - #ifdef COMPAT_0_7 - {"Describe",IndexFileGetDescribe}, - {"Exists",IndexFileGetExists}, - {"HasPackages",IndexFileGetHasPackages}, - {"IsTrusted",IndexFileGetIsTrusted}, - {"Label",IndexFileGetLabel}, - {"Size",IndexFileGetSize}, - #endif {} }; @@ -107,7 +96,7 @@ PyTypeObject PyIndexFile_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags diff --git a/python/metaindex.cc b/python/metaindex.cc index dee54521..2dcade7d 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -52,12 +52,6 @@ static PyGetSetDef MetaIndexGetSet[] = { {"index_files",MetaIndexGetIndexFiles}, {"is_trusted",MetaIndexGetIsTrusted}, {"uri",MetaIndexGetURI}, - #ifdef COMPAT_0_7 - {"Dist",MetaIndexGetDist}, - {"IndexFiles",MetaIndexGetIndexFiles}, - {"IsTrusted",MetaIndexGetIsTrusted}, - {"URI",MetaIndexGetURI}, - #endif {} }; @@ -91,7 +85,7 @@ PyTypeObject PyMetaIndex_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9b4a9ab7..2fda14ee 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -100,11 +100,6 @@ static PyMethodDef PkgManagerMethods[] = {"get_archives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, {"do_install",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, {"fix_missing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, -#ifdef COMPAT_0_7 - {"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"}, -#endif {} }; @@ -128,7 +123,7 @@ PyTypeObject PyPackageManager_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 1e43b2e8..0e00edcd 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -50,9 +50,6 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) static PyMethodDef PkgRecordsMethods[] = { {"lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, - #ifdef COMPAT_0_7 - {"Lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, - #endif {} }; @@ -132,20 +129,6 @@ static PyGetSetDef PkgRecordsGetSet[] = { {"short_desc",PkgRecordsGetShortDesc}, {"source_pkg",PkgRecordsGetSourcePkg}, {"source_ver",PkgRecordsGetSourceVer}, -#ifdef COMPAT_0_7 - {"FileName",PkgRecordsGetFileName}, - {"Homepage",PkgRecordsGetHomepage}, - {"LongDesc",PkgRecordsGetLongDesc}, - {"MD5Hash",PkgRecordsGetMD5Hash}, - {"Maintainer",PkgRecordsGetMaintainer}, - {"Name",PkgRecordsGetName}, - {"Record",PkgRecordsGetRecord}, - {"SHA1Hash",PkgRecordsGetSHA1Hash}, - {"SHA256Hash",PkgRecordsGetSHA256Hash}, - {"ShortDesc",PkgRecordsGetShortDesc}, - {"SourcePkg",PkgRecordsGetSourcePkg}, - {"SourceVer",PkgRecordsGetSourceVer}, -#endif {} }; @@ -180,7 +163,7 @@ PyTypeObject PyPackageRecords_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 41ee6276..95f35f23 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -71,10 +71,6 @@ static PyMethodDef PkgSrcRecordsMethods[] = { {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, -#ifdef COMPAT_0_7 - {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, - {"Restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, -#endif {} }; @@ -234,15 +230,7 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { {"section",PkgSrcRecordsGetSection}, {"version",PkgSrcRecordsGetVersion}, #ifdef COMPAT_0_7 - {"Binaries",PkgSrcRecordsGetBinaries}, {"BuildDepends",PkgSrcRecordsGetBuildDepends_old,0,"Deprecated function and deprecated output format."}, - {"Files",PkgSrcRecordsGetFiles}, - {"Index",PkgSrcRecordsGetIndex}, - {"Maintainer",PkgSrcRecordsGetMaintainer}, - {"Package",PkgSrcRecordsGetPackage}, - {"Record",PkgSrcRecordsGetRecord}, - {"Section",PkgSrcRecordsGetSection}, - {"Version",PkgSrcRecordsGetVersion}, #endif {} }; @@ -274,7 +262,7 @@ PyTypeObject PySourceRecords_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/sourcelist.cc b/python/sourcelist.cc index b705d8b8..6184fee3 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -77,11 +77,6 @@ static PyMethodDef PkgSourceListMethods[] = {"find_index",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, {"read_main_list",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, {"get_indexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, -#ifdef COMPAT_0_7 - {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, - {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, - {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, -#endif {} }; @@ -104,9 +99,6 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) static PyGetSetDef PkgSourceListGetSet[] = { {"list",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, -#ifdef COMPAT_0_7 - {"List",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, -#endif {} }; @@ -137,7 +129,7 @@ PyTypeObject PySourceList_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/tag.cc b/python/tag.cc index 4971a03d..6d327d27 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -458,12 +458,6 @@ static PyMethodDef TagSecMethods[] = {"find_raw",TagSecFindRaw,METH_VARARGS,doc_FindRaw}, {"find_flag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, {"bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, -#ifdef COMPAT_0_7 - {"Find",TagSecFind,METH_VARARGS,doc_Find}, - {"FindRaw",TagSecFindRaw,METH_VARARGS,doc_FindRaw}, - {"FindFlag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, - {"Bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, -#endif // Python Special {"keys",TagSecKeys,METH_VARARGS,doc_Keys}, @@ -503,7 +497,7 @@ PyTypeObject PyTagSection_Type = 0, // tp_hash 0, // tp_call TagSecStr, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -536,11 +530,6 @@ static PyMethodDef TagFileMethods[] = {"step",TagFileStep,METH_VARARGS,doc_Step}, {"offset",TagFileOffset,METH_VARARGS,doc_Offset}, {"jump",TagFileJump,METH_VARARGS,doc_Jump}, -#ifdef COMPAT_0_7 - {"Step",TagFileStep,METH_VARARGS,doc_Step}, - {"Offset",TagFileOffset,METH_VARARGS,doc_Offset}, - {"Jump",TagFileJump,METH_VARARGS,doc_Jump}, -#endif {} }; @@ -554,12 +543,10 @@ static PyObject *TagFileGetSection(PyObject *Self,void*) { static PyGetSetDef TagFileGetSet[] = { {"section",TagFileGetSection,0,"Return a TagSection.",0}, -#ifdef COMPAT_0_7 - {"Section",TagFileGetSection,0,"Return a TagSection.",0}, -#endif {} }; + static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" "TagFile() objects provide access to debian control files, which consists\n" "of multiple RFC822-like formatted sections.\n\n" @@ -593,7 +580,7 @@ PyTypeObject PyTagFile_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags -- cgit v1.2.3