summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog2
-rw-r--r--doc/examples/action.py147
-rw-r--r--python/cache.cc61
-rw-r--r--python/progress.cc78
-rw-r--r--python/progress.h27
5 files changed, 310 insertions, 5 deletions
diff --git a/debian/changelog b/debian/changelog
index c83d737a..10e5cda2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-python-apt (0.5.37) hoary; urgency=low
+python-apt (0.5.36ubuntu1) hoary; urgency=low
* DepCache.ReadPinFile() added
* Fixed a bug in DepCache.Upgrade()
diff --git a/doc/examples/action.py b/doc/examples/action.py
new file mode 100644
index 00000000..d3cddbc4
--- /dev/null
+++ b/doc/examples/action.py
@@ -0,0 +1,147 @@
+#!/usr/bin/python
+# example how to deal with the depcache
+
+import apt_pkg
+import sys
+import copy
+
+class OpProgress:
+ def __init__(self):
+ self.last = 0.0
+
+ def Update(self, percent):
+ if (self.last + 1.0) <= percent:
+ sys.stdout.write("\rProgress: %i.2 " % (percent))
+ self.last = percent
+ if percent >= 100:
+ self.last = 0.0
+
+
+ def Done(self):
+ self.last = 0.0
+ print "\rDone "
+
+
+class FetchProgress:
+ def __init__(self):
+ pass
+ def Pulse(self, CurrentCPS, CurrentBytes, CurrentItems):
+ print "Pulse: CPS: %s Bytes: %s Item: %s" % (CurrentCPS, CurrentBytes, CurrentItems)
+
+
+
+# init
+apt_pkg.init()
+
+progress = OpProgress()
+cache = apt_pkg.GetCache(progress)
+print "Available packages: %s " % cache.PackageCount
+
+progress = FetchProgress()
+cache.Update(progress)
+
+print "Exiting"
+sys.exit(0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+iter = cache["base-config"]
+print "example package iter: %s" % iter
+
+# get depcache
+print "\n\n depcache"
+depcache = apt_pkg.GetDepCache(cache, progress)
+depcache.ReadPinFile()
+print "got a depcache: %s " % depcache
+print "Marked for install: %s " % depcache.InstCount
+
+print "\n\n Reinit"
+depcache.Init(progress)
+
+#sys.exit()
+
+
+# get a canidate version
+ver= depcache.GetCandidateVer(iter)
+print "Candidate version: %s " % ver
+
+print "\n\nQuerry interface"
+print "%s.IsUpgradable(): %s" % (iter.Name, depcache.IsUpgradable(iter))
+
+print "\nMarking interface"
+print "Marking '%s' for install" % iter.Name
+depcache.MarkInstall(iter)
+print "Install count: %s " % depcache.InstCount
+print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter))
+print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter))
+print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
+
+print "Marking %s for delete" % iter.Name
+depcache.MarkDelete(iter)
+print "DelCount: %s " % depcache.DelCount
+print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
+
+
+iter = cache["3dchess"]
+print "\nMarking '%s' for install" % iter.Name
+depcache.MarkInstall(iter)
+print "Install count: %s " % depcache.InstCount
+print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter))
+print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter))
+print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
+
+print "Marking %s for keep" % iter.Name
+depcache.MarkKeep(iter)
+print "Install: %s " % depcache.InstCount
+
+iter = cache["3dwm-server"]
+print "\nMarking '%s' for install" % iter.Name
+depcache.MarkInstall(iter)
+print "Install: %s " % depcache.InstCount
+print "Broken count: %s" % depcache.BrokenCount
+print "FixBroken() "
+depcache.FixBroken()
+print "Broken count: %s" % depcache.BrokenCount
+
+print "\nPerforming Upgrade"
+depcache.Upgrade()
+print "Keep: %s " % depcache.KeepCount
+print "Install: %s " % depcache.InstCount
+print "Delete: %s " % depcache.DelCount
+print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize)
+print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize)
+
+for pkg in cache.Packages:
+ if pkg.CurrentVer != None and not depcache.MarkedInstall(pkg) and depcache.IsUpgradable(pkg):
+ print "Upgrade didn't upgrade (kept): %s" % pkg.Name
+
+
+print "\nPerforming DistUpgrade"
+depcache.Upgrade(True)
+print "Keep: %s " % depcache.KeepCount
+print "Install: %s " % depcache.InstCount
+print "Delete: %s " % depcache.DelCount
+print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize)
+print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize)
+
+# overview about what would happen
+for pkg in cache.Packages:
+ if depcache.MarkedInstall(pkg):
+ if pkg.CurrentVer != None:
+ print "Marked upgrade: %s " % pkg.Name
+ else:
+ print "Marked install: %s" % pkg.Name
+ elif depcache.MarkedDelete(pkg):
+ print "Marked delete: %s" % pkg.Name
+ elif depcache.MarkedKeep(pkg):
+ print "Marked keep: %s" % pkg.Name
diff --git a/python/cache.cc b/python/cache.cc
index 7ba53fd9..aff5854a 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -14,6 +14,9 @@
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/sptr.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/error.h>
#include <Python.h>
#include "progress.h"
@@ -66,6 +69,57 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I)
// Cache Class /*{{{*/
// ---------------------------------------------------------------------
+static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args)
+{
+ pkgCacheFile *Cache = GetCpp<pkgCacheFile *>(Self);
+
+ PyObject *pyOpProgressInst = 0;
+ PyObject *pyFetchProgressInst = 0;
+ if (PyArg_ParseTuple(Args, "O|O", &pyFetchProgressInst,&pyOpProgressInst) == 0)
+ return 0;
+
+ FileFd Lock;
+ if (_config->FindB("Debug::NoLocking", false) == false) {
+ Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
+ if (_error->PendingError() == true)
+ return HandleErrors();
+ }
+
+ pkgSourceList List;
+ if(!List.ReadMainList())
+ return HandleErrors(Py_None);
+
+ PyFetchProgress progress;
+ progress.setCallbackInst(pyFetchProgressInst);
+
+ pkgAcquire Fetcher(&progress);
+ if (!List.GetIndexes(&Fetcher))
+ return HandleErrors();
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ return HandleErrors(Py_None);
+
+
+
+ if(pyOpProgressInst != 0) {
+ PyOpProgress progress;
+ progress.setCallbackInst(pyOpProgressInst);
+ if (Cache->Open(progress,false) == false)
+ return HandleErrors();
+ } else {
+ OpTextProgress Prog;
+ if (Cache->Open(Prog,false) == false)
+ return HandleErrors(Py_None);
+ }
+
+ return HandleErrors(Py_None);
+}
+
+
+static PyMethodDef PkgCacheMethods[] =
+{
+ {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"},
+};
+
static PyObject *CacheAttr(PyObject *Self,char *Name)
{
pkgCache *Cache = GetCpp<pkgCache *>(Self);
@@ -96,9 +150,8 @@ static PyObject *CacheAttr(PyObject *Self,char *Name)
}
return List;
}
-
- PyErr_SetString(PyExc_AttributeError,Name);
- return 0;
+
+ return Py_FindMethod(PkgCacheMethods,Self,Name);
}
// Map access, operator []
@@ -766,6 +819,6 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args)
CppOwnedPyObject_NEW<pkgCache *>(CacheFileObj,&PkgCacheType,
(pkgCache *)(*Cache));
- Py_DECREF(CacheFileObj);
+ //Py_DECREF(CacheFileObj);
return CacheObj;
}
diff --git a/python/progress.cc b/python/progress.cc
index d414ca15..75c531fe 100644
--- a/python/progress.cc
+++ b/python/progress.cc
@@ -6,9 +6,12 @@
##################################################################### */
+#include <iostream>
#include "progress.h"
+// OpProgress interface
+// FIXME: add "string Op, string SubOp" as attribute to the callbackInst
void PyOpProgress::Update()
{
if(callbackInst == 0)
@@ -33,6 +36,7 @@ void PyOpProgress::Update()
return;
};
+
void PyOpProgress::Done()
{
if(callbackInst == 0)
@@ -53,3 +57,77 @@ void PyOpProgress::Done()
Py_XDECREF(method);
Py_DECREF(arglist);
}
+
+
+
+// fetcher interface
+// PyFetchProgress::
+
+// apt interface
+bool PyFetchProgress::MediaChange(string Media, string Drive)
+{
+ std::cout << "MediaChange" << std::endl;
+}
+
+void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "IMSHit" << std::endl;
+}
+
+void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "Fetch" << std::endl;
+}
+
+void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "Done" << std::endl;
+}
+
+void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "Fail" << std::endl;
+}
+
+void PyFetchProgress::Start()
+{
+ std::cout << "Start" << std::endl;
+ pkgAcquireStatus::Start();
+
+}
+
+void PyFetchProgress::Stop()
+{
+ std::cout << "Stop" << std::endl;
+ pkgAcquireStatus::Stop();
+}
+
+// FIXME: it should just set the attribute for
+// CurrentCPS, Current...
+bool PyFetchProgress::Pulse(pkgAcquire * Owner)
+{
+ pkgAcquireStatus::Pulse(Owner);
+
+ //std::cout << "Pulse" << std::endl;
+ if(callbackInst == 0)
+ return false;
+
+ // Build up the argument list...
+ PyObject *arglist = Py_BuildValue("(ffi)", CurrentCPS, CurrentBytes, CurrentItems);
+
+ // ...for calling the Python compare function.
+ PyObject *method = PyObject_GetAttrString(callbackInst, "Pulse");
+ if(method == NULL) {
+ // FIXME: make this silent
+ Py_DECREF(arglist);
+ return false;
+ }
+ PyObject *result = PyEval_CallObject(method,arglist);
+
+ Py_XDECREF(result);
+ Py_XDECREF(method);
+ Py_DECREF(arglist);
+
+ // this can be canceld by returning false
+ return true;
+}
diff --git a/python/progress.h b/python/progress.h
index b18778b1..6ea0b16b 100644
--- a/python/progress.h
+++ b/python/progress.h
@@ -10,6 +10,7 @@
#define PROGRESS_H
#include <apt-pkg/progress.h>
+#include <apt-pkg/acquire.h>
#include <Python.h>
struct PyOpProgress : public OpProgress
@@ -26,4 +27,30 @@ struct PyOpProgress : public OpProgress
PyOpProgress() : OpProgress(), callbackInst(0) {};
};
+
+struct PyFetchProgress : public pkgAcquireStatus
+{
+ PyObject *callbackInst;
+
+ void setCallbackInst(PyObject *o) {
+ callbackInst = o;
+ }
+
+
+ void updateStatus(pkgAcquire::ItemDesc & Itm, int status);
+
+ // apt interface
+ virtual bool MediaChange(string Media, string Drive);
+ virtual void IMSHit(pkgAcquire::ItemDesc &Itm);
+ virtual void Fetch(pkgAcquire::ItemDesc &Itm);
+ virtual void Done(pkgAcquire::ItemDesc &Itm);
+ virtual void Fail(pkgAcquire::ItemDesc &Itm);
+ virtual void Start();
+ virtual void Stop();
+
+ bool Pulse(pkgAcquire * Owner);
+};
+
+
+
#endif