summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-04-08 00:51:04 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-04-08 00:51:04 +0000
commit8f914ef267ab1bbcbda1c6694edd2e4c9b6401ec (patch)
treeed06ac66d1e0675a77080bf5a5d6f33e3c492d52
parent7e76103c2b13d27f4a9987b1f9fca50504177268 (diff)
downloadpython-apt-8f914ef267ab1bbcbda1c6694edd2e4c9b6401ec.tar.gz
* started the DepCache.Commit() interface
-rw-r--r--doc/examples/action.py26
-rw-r--r--doc/examples/inst.py140
-rw-r--r--doc/examples/progress.py30
-rw-r--r--python/cache.cc4
-rw-r--r--python/depcache.cc134
5 files changed, 308 insertions, 26 deletions
diff --git a/doc/examples/action.py b/doc/examples/action.py
index 09ded0a7..3eb58d9e 100644
--- a/doc/examples/action.py
+++ b/doc/examples/action.py
@@ -4,31 +4,7 @@
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 UpdateStatus(self, uri, descr, shortDescr, status):
- print "UpdateStatus: '%s' '%s' '%s' '%i'" % (uri,descr,shortDescr, status)
- def Pulse(self):
- print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (apt_pkg.SizeToStr(self.CurrentCPS), apt_pkg.SizeToStr(self.CurrentBytes), apt_pkg.SizeToStr(self.TotalBytes), self.CurrentItems, self.TotalItems)
-
+from progress import OpProgress, FetchProgress
# init
diff --git a/doc/examples/inst.py b/doc/examples/inst.py
new file mode 100644
index 00000000..3854805b
--- /dev/null
+++ b/doc/examples/inst.py
@@ -0,0 +1,140 @@
+#!/usr/bin/python
+# example how to deal with the depcache
+
+import apt_pkg
+import sys
+import copy
+
+from progress import OpProgress, FetchProgress
+
+
+# init
+apt_pkg.init()
+
+progress = OpProgress()
+cache = apt_pkg.GetCache(progress)
+print "Available packages: %s " % cache.PackageCount
+
+# get depcache
+depcache = apt_pkg.GetDepCache(cache)
+depcache.ReadPinFile()
+depcache.Init(progress)
+
+# do something
+fprogress = FetchProgress()
+iprogress = "lala"
+iter = cache["base-config"]
+print "\n%s"%iter
+
+# install or remove, the importend thing is to keep us busy :)
+if iter.CurrentVer == None:
+ depcache.MarkInstall(iter)
+else:
+ depcache.MarkDelete(iter)
+depcache.Commit(fprogress, iprogress)
+
+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/doc/examples/progress.py b/doc/examples/progress.py
new file mode 100644
index 00000000..f6cf1495
--- /dev/null
+++ b/doc/examples/progress.py
@@ -0,0 +1,30 @@
+import apt_pkg
+import sys
+
+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 UpdateStatus(self, uri, descr, shortDescr, status):
+ print "UpdateStatus: '%s' '%s' '%s' '%i'" % (uri,descr,shortDescr, status)
+ def Pulse(self):
+ print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (apt_pkg.SizeToStr(self.CurrentCPS), apt_pkg.SizeToStr(self.CurrentBytes), apt_pkg.SizeToStr(self.TotalBytes), self.CurrentItems, self.TotalItems)
+
+ def MediaChange(self, medium, drive):
+ print "Please insert medium %s in drive %s" % (medium, drive)
+ sys.stdin.readline() \ No newline at end of file
diff --git a/python/cache.cc b/python/cache.cc
index 126ab15d..e8b947f4 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -17,6 +17,8 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgsystem.h>
#include <Python.h>
#include "progress.h"
@@ -114,9 +116,11 @@ static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args)
}
+
static PyMethodDef PkgCacheMethods[] =
{
{"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"},
+ {}
};
static PyObject *CacheAttr(PyObject *Self,char *Name)
diff --git a/python/depcache.cc b/python/depcache.cc
index dcccf75c..2a57a41a 100644
--- a/python/depcache.cc
+++ b/python/depcache.cc
@@ -16,7 +16,12 @@
#include <apt-pkg/algorithms.h>
#include <apt-pkg/policy.h>
#include <apt-pkg/sptr.h>
-
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/acquire-item.h>
#include <Python.h>
#include <iostream>
@@ -65,6 +70,128 @@ static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args)
return HandleErrors(Py_None);
}
+static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args)
+{
+ PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self);
+
+ PyObject *pyInstallProgressInst = 0;
+ PyObject *pyFetchProgressInst = 0;
+ if (PyArg_ParseTuple(Args, "OO",
+ &pyFetchProgressInst, &pyInstallProgressInst) == 0) {
+ return 0;
+ }
+ FileFd Lock;
+ if (_config->FindB("Debug::NoLocking", false) == false) {
+ Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
+ if (_error->PendingError() == true)
+ return HandleErrors();
+ }
+
+ pkgRecords Recs(*Struct.depcache);
+ if (_error->PendingError() == true)
+ HandleErrors(Py_None);
+
+ pkgSourceList List;
+ if(!List.ReadMainList())
+ return HandleErrors(Py_None);
+
+ PyFetchProgress progress;
+ progress.setCallbackInst(pyFetchProgressInst);
+
+ pkgAcquire Fetcher(&progress);
+ pkgPackageManager *PM;
+ PM = _system->CreatePM(Struct.depcache);
+ if(PM->GetArchives(&Fetcher, &List, &Recs) == false ||
+ _error->PendingError() == true) {
+ std::cerr << "Error in GetArchives" << std::endl;
+ return HandleErrors();
+ }
+
+ std::cout << "PM created" << std::endl;
+
+ // Run it
+ while (1)
+ {
+ bool Transient = false;
+
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ return false;
+
+ // Print out errors
+ bool Failed = false;
+ for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
+ {
+ if ((*I)->Status == pkgAcquire::Item::StatDone &&
+ (*I)->Complete == true)
+ continue;
+
+ if ((*I)->Status == pkgAcquire::Item::StatIdle)
+ {
+ Transient = true;
+ // Failed = true;
+ continue;
+ }
+
+ //FIXME: report this error somehow
+// fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
+// (*I)->ErrorText.c_str());
+ Failed = true;
+ }
+
+#if 0 // check that stuff
+ if (Transient == true && Failed == true)
+ return Py_None; /*_error->Error(_("--fix-missing and media swapping is not currently supported"));*/
+
+ // Try to deal with missing package files
+ if (Failed == true && PM->FixMissing() == false)
+ {
+ //std::cerr << "Unable to correct missing packages." << std::endl;
+ _error->Error("Aborting install.");
+ return HandleErrors(Py_None);
+ }
+#endif
+
+ _system->UnLock();
+ pkgPackageManager::OrderResult Res = PM->DoInstall();
+ if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
+ return Py_None/*false;*/;
+ if (Res == pkgPackageManager::Completed)
+ return Py_None /*true;*/;
+
+ // Reload the fetcher object and loop again for media swapping
+ Fetcher.Shutdown();
+ if (PM->GetArchives(&Fetcher,&List,&Recs) == false)
+ return Py_None /*false;*/;
+
+ _system->Lock();
+ }
+
+
+
+#if 0
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ return HandleErrors(Py_None);
+
+ std::cout << "Fetcher was run" << std::endl;
+
+ // FIXME: incomplete, see apt-get.cc
+ _system->UnLock();
+
+ pkgPackageManager::OrderResult Res = PM->DoInstall();
+ if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
+ return Py_None/*false;*/;
+ if (Res == pkgPackageManager::Completed)
+ return Py_None /*true;*/;
+
+ _system->Lock();
+#endif
+
+ // FIXME: open the cache here again
+
+ return HandleErrors(Py_None);
+}
+
+
static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args)
{
PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self);
@@ -282,6 +409,7 @@ static PyMethodDef PkgDepCacheMethods[] =
{
{"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"},
{"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get 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"},
@@ -298,6 +426,10 @@ static PyMethodDef PkgDepCacheMethods[] =
{"MarkedUpgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"},
{"MarkedDelete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"},
{"MarkedKeep",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for keep"},
+
+ // Action
+ {"Commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"},
+
{}
};