summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-11-22 11:21:49 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-11-22 11:21:49 +0000
commitf398b1a5833fdf50f8c0c541958d5770ea767be8 (patch)
tree95d91a49f637820cd0b554cf381d35105b7e75cc
parentc26431eebbd6d9b90bba2498355e1874a15aba60 (diff)
downloadpython-apt-f398b1a5833fdf50f8c0c541958d5770ea767be8.tar.gz
* fix in the pkgmanager.cc code (/me needs to be hit with a clue-stick)
-rw-r--r--debian/changelog2
-rw-r--r--doc/examples/acquire.py20
-rw-r--r--python/acquire.cc8
-rw-r--r--python/pkgmanager.cc56
4 files changed, 63 insertions, 23 deletions
diff --git a/debian/changelog b/debian/changelog
index b0fe307f..9ffd5b12 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ python-apt (0.6.15) unstable; urgency=low
* fix a invalid return from cache.commit(), fail if a download failed
* apt.Package.candidateOrigin returns a class now
- * added basic pkgAcquire and pkgPackageManager support
+ * added pkgAcquire, pkgPackageManager and a example (acquire.py)
-- Michael Vogt <michael.vogt@ubuntu.com> Thu, 17 Nov 2005 13:00:14 +0100
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py
index 0031fa18..a5de0029 100644
--- a/doc/examples/acquire.py
+++ b/doc/examples/acquire.py
@@ -1,9 +1,14 @@
import apt
import apt_pkg
import os
+import sys
apt_pkg.init()
+#apt_pkg.Config.Set("Debug::pkgDPkgPM","1");
+#apt_pkg.Config.Set("Debug::pkgPackageManager","1");
+#apt_pkg.Config.Set("Debug::pkgDPkgProgressReporting","1");
+
cache = apt_pkg.GetCache()
depcache = apt_pkg.GetDepCache(cache)
@@ -16,7 +21,7 @@ try:
os.mkdir("/tmp/pyapt-test/partial")
except OSError:
pass
-#apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test")
+apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test")
pkg = cache["3ddesktop"]
depcache.MarkInstall(pkg)
@@ -32,18 +37,19 @@ print fetcher
pm.GetArchives(fetcher,list,recs)
for item in fetcher.Items:
- print "%s -> %s:\n Status: %s Complete: %s IsTrusted: %s" % (item.DescURI,
- item.DestFile,
- item.Status,
- item.Complete,
- item.IsTrusted)
+ print item
if item.Status == item.StatError:
print "Some error ocured: '%s'" % item.ErrorText
if item.Complete == False:
- print "No error, still nothing downloaded"
+ print "No error, still nothing downloaded (%s)" % item.ErrorText
print
res = fetcher.Run()
print "fetcher.Run() returned: %s" % res
+print "now runing pm.DoInstall()"
+res = pm.DoInstall(1)
+print "pm.DoInstall() returned: %s"% res
+
+
diff --git a/python/acquire.cc b/python/acquire.cc
index 91d75a6b..87f2717a 100644
--- a/python/acquire.cc
+++ b/python/acquire.cc
@@ -60,8 +60,12 @@ static PyObject *AcquireItemRepr(PyObject *Self)
char S[300];
snprintf(S,sizeof(S),"<pkgAcquire::ItemIterator object: "
- "DestFile:'%s' ID:%i>",
- (*I)->DestFile.c_str(),(*I)->ID);
+ "Status: %i Complete: %i Local: %i IsTrusted: %i "
+ "FileSize: %i DestFile:'%s' "
+ "DescURI: '%s' ID:%i ErrorText: '%s'>",
+ (*I)->Status, (*I)->Complete, (*I)->Local, (*I)->IsTrusted(),
+ (*I)->FileSize, (*I)->DestFile.c_str(), (*I)->DescURI().c_str(),
+ (*I)->ID,(*I)->ErrorText.c_str());
return PyString_FromString(S);
}
diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc
index 9504fd94..b4c64d3e 100644
--- a/python/pkgmanager.cc
+++ b/python/pkgmanager.cc
@@ -14,18 +14,14 @@
#include <apt-pkg/packagemanager.h>
#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/error.h>
#include <iostream>
-struct PkgManagerStruct
-{
- pkgPackageManager pm;
-};
-
static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args)
{
- PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+ pkgPackageManager *pm = GetCpp<pkgPackageManager*>(Self);
PyObject *fetcher, *list, *recs;
if (PyArg_ParseTuple(Args, "O!O!O!",
@@ -38,24 +34,53 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args)
PkgSourceListStruct &s_list = GetCpp<PkgSourceListStruct>(list);
PkgRecordsStruct &s_records = GetCpp<PkgRecordsStruct>(recs);
- bool res = Struct.pm.GetArchives(&s_fetcher.fetcher,
+ bool res = pm->GetArchives(&s_fetcher.fetcher,
&s_list.List,
&s_records.Records);
- return HandleErrors(Py_None);
+ return HandleErrors(Py_BuildValue("b",res));
+}
+
+static PyObject *PkgManagerDoInstall(PyObject *Self,PyObject *Args)
+{
+ //PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+ pkgPackageManager *pm = GetCpp<pkgPackageManager*>(Self);
+ int status_fd = -1;
+
+ if (PyArg_ParseTuple(Args, "|i", &status_fd) == 0)
+ return 0;
+
+ pkgPackageManager::OrderResult res = pm->DoInstall(status_fd);
+
+ return HandleErrors(Py_BuildValue("i",res));
}
+static PyObject *PkgManagerFixMissing(PyObject *Self,PyObject *Args)
+{
+ //PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+ pkgPackageManager *pm = GetCpp<pkgPackageManager*>(Self);
+
+ if (PyArg_ParseTuple(Args, "") == 0)
+ return 0;
+
+ bool res = pm->FixMissing();
+
+ return HandleErrors(Py_BuildValue("b",res));
+}
static PyMethodDef PkgManagerMethods[] =
{
{"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archvies 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"},
{}
};
static PyObject *PkgManagerAttr(PyObject *Self,char *Name)
{
- PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+ //PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+ pkgPackageManager *pm = GetCpp<pkgPackageManager*>(Self);
// some constants
if(strcmp("ResultCompleted",Name) == 0)
@@ -74,10 +99,10 @@ PyTypeObject PkgManagerType =
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"PackageManager", // tp_name
- sizeof(CppOwnedPyObject<PkgManagerStruct>), // tp_basicsize
+ sizeof(CppOwnedPyObject<pkgPackageManager*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<PkgManagerStruct>, // tp_dealloc
+ CppOwnedDealloc<pkgPackageManager*>, // tp_dealloc
0, // tp_print
PkgManagerAttr, // tp_getattr
0, // tp_setattr
@@ -89,6 +114,9 @@ PyTypeObject PkgManagerType =
0, // tp_hash
};
+#include <apt-pkg/init.h>
+#include <apt-pkg/configuration.h>
+
PyObject *GetPkgManager(PyObject *Self,PyObject *Args)
{
PyObject *Owner;
@@ -97,9 +125,11 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args)
pkgPackageManager *pm = _system->CreatePM(GetCpp<pkgDepCache*>(Owner));
- CppOwnedPyObject<pkgPackageManager> *PkgManagerObj =
- CppOwnedPyObject_NEW<pkgPackageManager>(0,&PkgManagerType, *pm);
+ CppPyObject<pkgPackageManager*> *PkgManagerObj =
+ CppPyObject_NEW<pkgPackageManager*>(&PkgManagerType,pm);
+ // FIXME: mem-leak???
+ Py_INCREF(PkgManagerObj);
return PkgManagerObj;
}