diff options
| -rw-r--r-- | apt/progress.py | 57 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 3 | ||||
| -rw-r--r-- | python/depcache.cc | 39 | ||||
| -rw-r--r-- | python/progress.cc | 13 | ||||
| -rw-r--r-- | python/progress.h | 6 |
5 files changed, 79 insertions, 39 deletions
diff --git a/apt/progress.py b/apt/progress.py index 6fd2977a..8c264140 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -44,10 +44,23 @@ class OpTextProgress(OpProgress): -class FetchProgress: +class FetchProgress(object): """ Report the download/fetching progress Subclass this class to implement fetch progress reporting """ + + # download status constants + dlDone = 0 + dlQueued = 1 + dlFailed = 2 + dlHit = 3 + dlIgnored = 4 + dlStatusStr = {dlDone : "Done", + dlQueued : "Queued", + dlFailed : "Failed", + dlHit : "Hit", + dlIgnored : "Ignored"} + def __init__(self): pass @@ -61,13 +74,46 @@ class FetchProgress: pass def pulse(self): - """ called periodically (to update the gui) """ + """ called periodically (to update the gui), importend to + return True to continue or False to cancel + """ + self.percent = ((self.currentBytes + self.currentItems)*100.0)/float(self.totalBytes+self.totalItems) + if self.currentCPS > 0: + self.eta = (self.totalBytes-self.currentBytes)/float(self.currentCPS) return True - def mediaChange(self, medium, drive): pass - +class TextFetchProgress(FetchProgress): + """ Ready to use progress object for terminal windows """ + def __init__(self): + self.items = {} + def updateStatus(self, uri, descr, shortDescr, status): + if status != self.dlQueued: + print "\r%s %s" % (self.dlStatusStr[status], descr) + self.items[uri] = status + def pulse(self): + FetchProgress.pulse(self) + if self.currentCPS > 0: + s = "[%2.f%%] %sB/s %s" % (self.percent, + apt_pkg.SizeToStr(int(self.currentCPS)), + apt_pkg.TimeToStr(int(self.eta))) + else: + s = "%2.f%% [Working]" % (self.percent) + print "\r%s" % (s), + sys.stdout.flush() + return True + def stop(self): + print "\rDone " + def mediaChange(self, medium, drive): + """ react to media change events """ + res = True; + print "Media change: please insert the disc labeled \ + '%s' in the drive '%s' and press enter" % (medium,drive) + s = sys.stdin.readline() + if(s == 'c' or s == 'C'): + res = false; + return res class InstallProgress: """ Report the install progress @@ -105,3 +151,6 @@ if __name__ == "__main__": cache = apt_pkg.GetCache(progress) depcache = apt_pkg.GetDepCache(cache) depcache.Init(progress) + + fprogress = TextFetchProgress() + cache.Update(fprogress) diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 9a3aac37..ce337f0f 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -449,14 +449,13 @@ extern "C" void initapt_pkg() AddInt(Dict,"DepConflicts",pkgCache::Dep::Conflicts); AddInt(Dict,"DepReplaces",pkgCache::Dep::Replaces); AddInt(Dict,"DepObsoletes",pkgCache::Dep::Obsoletes); - + AddInt(Dict,"PriImportant",pkgCache::State::Important); AddInt(Dict,"PriRequired",pkgCache::State::Required); AddInt(Dict,"PriStandard",pkgCache::State::Standard); AddInt(Dict,"PriOptional",pkgCache::State::Optional); AddInt(Dict,"PriExtra",pkgCache::State::Extra); - } /*}}}*/ diff --git a/python/depcache.cc b/python/depcache.cc index 418ddd14..fb506c96 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -27,6 +27,9 @@ #include <iostream> #include "progress.h" +#ifndef _ +#define _(x) (x) +#endif @@ -124,15 +127,16 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) continue; } - //FIXME: report this error somehow -// fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), -// (*I)->ErrorText.c_str()); + _error->Warning(_("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"));*/ + { + _error->Error(_("--fix-missing and media swapping is not currently supported")); + return HandleErrors(Py_None); + } // Try to deal with missing package files if (Failed == true && PM->FixMissing() == false) @@ -141,7 +145,6 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) _error->Error("Aborting install."); return HandleErrors(Py_None); } -#endif _system->UnLock(); @@ -164,29 +167,7 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) } _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); } diff --git a/python/progress.cc b/python/progress.cc index fb56ea87..5267134f 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -9,6 +9,7 @@ #include <iostream> #include <sys/types.h> #include <sys/wait.h> +#include <apt-pkg/acquire-item.h> #include "progress.h" @@ -75,9 +76,6 @@ void PyOpProgress::Done() // fetcher interface -enum { - DLDone, DLQueued, DLFailed, DLHit -}; // apt interface @@ -122,6 +120,15 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { + // Ignore certain kinds of transient failures (bad code) + if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) + return; + + if (Itm.Owner->Status == pkgAcquire::Item::StatDone) + { + UpdateStatus(Itm, DLIgnored); + } + UpdateStatus(Itm, DLFailed); } diff --git a/python/progress.h b/python/progress.h index f116c811..f04bd683 100644 --- a/python/progress.h +++ b/python/progress.h @@ -15,6 +15,7 @@ #include <apt-pkg/cdrom.h> #include <Python.h> + class PyCallbackObj { protected: PyObject *callbackInst; @@ -44,6 +45,10 @@ struct PyOpProgress : public OpProgress, public PyCallbackObj struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj { + enum { + DLDone, DLQueued, DLFailed, DLHit, DLIgnored + }; + void UpdateStatus(pkgAcquire::ItemDesc & Itm, int status); virtual bool MediaChange(string Media, string Drive); @@ -58,7 +63,6 @@ struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj bool Pulse(pkgAcquire * Owner); PyFetchProgress() : PyCallbackObj() {}; - }; struct PyInstallProgress : public PyCallbackObj |
