summaryrefslogtreecommitdiff
path: root/python/acquire.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-04-19 15:17:32 +0200
committerJulian Andres Klode <jak@debian.org>2009-04-19 15:17:32 +0200
commit45cdd4f2c6b04bfdfd37ef0e1a6358b29680afb8 (patch)
treeabe54ecca53fa226b4fd354a8b5f5e4224d47b50 /python/acquire.cc
parent6472bb377c1effbf2b9a17188e5e057acdf9d195 (diff)
downloadpython-apt-45cdd4f2c6b04bfdfd37ef0e1a6358b29680afb8.tar.gz
* 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.
Diffstat (limited to 'python/acquire.cc')
-rw-r--r--python/acquire.cc119
1 files changed, 98 insertions, 21 deletions
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<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;
}
-
-
- /*}}}*/