Commit 45cdd4f2 authored by Julian Andres Klode's avatar Julian Andres Klode

* 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.
parent 6472bb37
......@@ -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<pkgAcquire*> *FetcherObj =
CppPyObject_NEW<pkgAcquire*>(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<pkgAcquire*>), // 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<pkgAcquire*> *FetcherObj =
CppPyObject_NEW<pkgAcquire*>(&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<pkgAcquire*>(pyfetcher);
pkgAcqFile *af = new pkgAcqFile(fetcher, // owner
uri, // uri
md5, // md5
size, // size
descr, // descr
shortDescr,
destDir,
destFile); // short-desc
CppPyObject<pkgAcqFile*> *AcqFileObj = CppPyObject_NEW<pkgAcqFile*>(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<pkgAcqFile*>),// 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;
}
/*}}}*/
......@@ -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));
......
......@@ -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);
......
......@@ -235,6 +235,61 @@ void PkgCacheFileDealloc(PyObject *Self)
CppOwnedDealloc<pkgCache *>(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<pkgCacheFile*> *CacheFileObj =
CppOwnedPyObject_NEW<pkgCacheFile*>(0,&PkgCacheFileType, Cache);
CppOwnedPyObject<pkgCache *> *CacheObj =
CppOwnedPyObject_NEW<pkgCache *>(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<pkgCache *>), // 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<PkgListStruct>), // 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<pkgCache::PkgIterator>), // 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<pkgCache::DescIterator>), // 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<pkgCache::VerIterator>), // 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<pkgCache::PkgFileIterator>), // 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<pkgCache::DepIterator>), // 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<RDepListStruct>), // 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<pkgCacheFile*> *CacheFileObj =
CppOwnedPyObject_NEW<pkgCacheFile*>(0,&PkgCacheFileType, Cache);
CppOwnedPyObject<pkgCache *> *CacheObj =
CppOwnedPyObject_NEW<pkgCache *>(CacheFileObj,&PkgCacheType,
(pkgCache *)(*Cache));
//Py_DECREF(CacheFileObj);
return CacheObj;
return PkgCacheNew(&PkgCacheType,Args,0);
}
......@@ -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<pkgCdrom> *CdromObj =
CppOwnedPyObject_NEW<pkgCdrom>(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<PkgCdromStruct>), // 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<pkgCdrom> *CdromObj =
CppOwnedPyObject_NEW<pkgCdrom>(0,&PkgCdromType, *cdrom);
return CdromObj;
return PkgCdromNew(&PkgCdromType,Args,0);
}
......
......@@ -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<Configuration>(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<Configuration>), // 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<Configuration *>), // 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
......
......@@ -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<pkgCache*>(Owner);
// get the pkgCacheFile from the cachefile
pkgCacheFile *CacheF = GetCpp<pkgCacheFile*>(CacheFilePy);
// and now the depcache
pkgDepCache *depcache = (pkgDepCache *)(*CacheF);
CppOwnedPyObject<pkgDepCache*> *DepCachePyObj;
DepCachePyObj = CppOwnedPyObject_NEW<pkgDepCache*>(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<pkgDepCache *>), // 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<pkgCache*>(Owner);
// get the pkgCacheFile from the cachefile
pkgCacheFile *CacheF = GetCpp<pkgCacheFile*>(CacheFilePy);
// and now the depcache
pkgDepCache *depcache = (pkgDepCache *)(*CacheF);
CppOwnedPyObject<pkgDepCache*> *DepCachePyObj;
DepCachePyObj = CppOwnedPyObject_NEW<pkgDepCache*>(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<pkgDepCache*>(Owner);
pkgProblemResolver *fixer = new pkgProblemResolver(depcache);
CppOwnedPyObject<pkgProblemResolver*> *PkgProblemResolverPyObj;
PkgProblemResolverPyObj = CppOwnedPyObject_NEW<pkgProblemResolver*>(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<pkgProblemResolver *>), // 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[] =
{}
};