diff options
| -rw-r--r-- | apt/cache.py | 26 | ||||
| -rw-r--r-- | apt/package.py | 19 | ||||
| -rw-r--r-- | apt/progress.py | 20 | ||||
| -rw-r--r-- | debian/changelog | 33 | ||||
| -rw-r--r-- | doc/examples/progress.py | 17 |
5 files changed, 81 insertions, 34 deletions
diff --git a/apt/cache.py b/apt/cache.py index fbca0f2a..9218263b 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -83,11 +83,7 @@ class Cache(object): raise StopIteration def has_key(self, key): - try: - self._dict[key] - except KeyError: - return False - return True + return self._dict.has_key(key) def __len__(self): return len(self._dict) @@ -116,8 +112,6 @@ class Cache(object): def _runFetcher(self, fetcher): # do the actual fetching res = fetcher.Run() - if res == fetcher.ResultFailed: - return False # now check the result (this is the code from apt-get.cc) failed = False @@ -152,7 +146,6 @@ class Cache(object): # now run the fetcher, throw exception if something fails to be # fetched res = self._runFetcher(fetcher) - # cleanup os.close(lock) return res @@ -169,8 +162,9 @@ class Cache(object): self._list.GetIndexes(fetcher) # now run the fetcher, throw exception if something fails to be # fetched - res = self._runFetcher(fetcher) - return res + if self._runFetcher(fetcher) == fetcher.ResultContinue: + return True + return False def installArchives(self, pm, installProgress): installProgress.startUpdate() @@ -266,11 +260,7 @@ class FilteredCache(object): return self._filtered.keys() def has_key(self, key): - try: - self._filtered[key] - except KeyError: - return False - return True + return self._filtered.has_key(key) def _reapplyFilter(self): " internal helper to refilter " @@ -337,9 +327,9 @@ if __name__ == "__main__": # see if fetching works - for dir in ["/tmp/pytest", "/tmp/pytest/partial"]: - if not os.path.exists(dir): - os.mkdir(dir) + for d in ["/tmp/pytest", "/tmp/pytest/partial"]: + if not os.path.exists(d): + os.mkdir(d) apt_pkg.Config.Set("Dir::Cache::Archives","/tmp/pytest") pm = apt_pkg.GetPackageManager(c._depcache) fetcher = apt_pkg.GetAcquire(apt.progress.TextFetchProgress()) diff --git a/apt/package.py b/apt/package.py index 4633123a..4fceb904 100644 --- a/apt/package.py +++ b/apt/package.py @@ -19,19 +19,22 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import apt_pkg, string, sys, random +import apt_pkg +import sys +import random +import string class Package(object): """ This class represents a package in the cache """ - def __init__(self, cache, depcache, records, list, pcache, pkgiter): + def __init__(self, cache, depcache, records, sourcelist, pcache, pkgiter): """ Init the Package object """ self._cache = cache # low level cache self._depcache = depcache self._records = records self._pkg = pkgiter - self._list = list # sourcelist + self._list = sourcelist # sourcelist self._pcache = pcache # python cache in cache.py pass @@ -52,8 +55,8 @@ class Package(object): if ver.FileList == None: print "No FileList for: %s " % self._pkg.Name() return False - file, index = ver.FileList.pop(0) - self._records.Lookup((file,index)) + f, index = ver.FileList.pop(0) + self._records.Lookup((f,index)) return True @@ -317,10 +320,10 @@ if __name__ == "__main__": cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) records = apt_pkg.GetPkgRecords(cache) - list = apt_pkg.GetPkgSourceList() + sourcelist = apt_pkg.GetPkgSourceList() - iter = cache["apt-utils"] - pkg = Package(cache, depcache, records, list, None, iter) + pkgiter = cache["apt-utils"] + pkg = Package(cache, depcache, records, sourcelist, None, pkgiter) print "Name: %s " % pkg.name print "ID: %s " % pkg.id print "Priority (Candidate): %s " % pkg.priority diff --git a/apt/progress.py b/apt/progress.py index 40cf8e48..4119067c 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -21,7 +21,7 @@ import sys, apt_pkg, os, fcntl, string, re -class OpProgress: +class OpProgress(object): """ Abstract class to implement reporting on cache opening Subclass this class to implement simple Operation progress reporting """ @@ -62,7 +62,7 @@ class FetchProgress(object): dlIgnored : "Ignored"} def __init__(self): - self.eta = "" + self.eta = 0.0 self.percent = 0.0 pass @@ -117,7 +117,7 @@ class TextFetchProgress(FetchProgress): res = false; return res -class DumbInstallProgress: +class DumbInstallProgress(object): """ Report the install progress Subclass this class to implement install progress reporting """ @@ -135,9 +135,10 @@ class DumbInstallProgress: class InstallProgress(DumbInstallProgress): """ A InstallProgress that is pretty useful. It supports the attributes 'percent' 'status' and callbacks - for the dpkg errors and conffiles (not implemented yet) + for the dpkg errors and conffiles and status changes """ def __init__(self): + DumbInstallProgress.__init__(self) (read, write) = os.pipe() self.writefd=write self.statusfd = os.fdopen(read, "r") @@ -151,6 +152,9 @@ class InstallProgress(DumbInstallProgress): def conffile(self,current,new): " called when a conffile question from dpkg is detected " pass + def statusChange(self, pkg, percent, status): + " called when the status changed " + pass def updateInterface(self): if self.statusfd != None: try: @@ -173,8 +177,12 @@ class InstallProgress(DumbInstallProgress): match = re.compile("\s*\'(.*)\'\s*\'(.*)\'.*").match(status_str) if match: self.conffile(match.group(1), match.group(2)) - self.percent = float(percent) - self.status = string.strip(status_str) + elif status == "pmstatus": + if float(percent) != self.percent or \ + status_str != self.status: + self.statusChange(pkg, float(percent), status_str.strip()) + self.percent = float(percent) + self.status = string.strip(status_str) self.read = "" def fork(self): diff --git a/debian/changelog b/debian/changelog index ddce68cb..75604746 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,11 +1,40 @@ -python-apt (0.6.16ubuntu3) dapper; urgency=low +python-apt (0.6.16.2ubuntu3) dapper; urgency=low + + * apt/package.py: undo some damager from pychecker + + -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 1 Mar 2006 15:34:23 +0100 + +python-apt (0.6.16.2ubuntu2) dapper; urgency=low + + * apt/progress.py: + - initialize FetchProgress.eta with the correct type + - strip the staus str before passing it to InstallProgress.statusChanged() + * apt/cache.py: + - return useful values on Cache.update() + * fix FTBFS + + -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 28 Feb 2006 14:07:06 +0100 + +python-apt (0.6.16.2ubuntu1) dapper; urgency=low + + * apt/progress.py: + - added InstallProgress.statusChange(pkg, percent, status) + - make DumbInstallProgress a new-style class + (thanks to kamion for the suggestions) + - fix various pychecker warnings + * apt/cache.py, apt/package.py: fix various pychecker warnings + + + -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 28 Feb 2006 12:04:37 +0100 + +python-apt (0.6.16.1) unstable; urgency=low * typos fixed (thanks to Gustavo Franco) * pkgRecords.Record added to get raw record data * python/cache.cc: "key" in pkgCache::VerIterator.DependsList[key] is no longer locale specific but always englis - -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 21 Feb 2006 19:23:09 +0100 + -- Michael Vogt <mvo@debian.org> Wed, 22 Feb 2006 10:41:13 +0100 python-apt (0.6.16ubuntu2) dapper; urgency=low diff --git a/doc/examples/progress.py b/doc/examples/progress.py index d820fcb2..2723c382 100644 --- a/doc/examples/progress.py +++ b/doc/examples/progress.py @@ -44,12 +44,16 @@ class TextFetchProgress(apt.FetchProgress): class TextInstallProgress(apt.InstallProgress): def __init__(self): + apt.InstallProgress.__init__(self) pass def startUpdate(self): print "StartUpdate" def finishUpdate(self): print "FinishUpdate" + def statusChange(self, pkg, percent, status): + print "[%s] %s: %s" % (percent, pkg, status) def updateInterface(self): + apt.InstallProgress.updateInterface(self) # usefull to e.g. redraw a GUI time.sleep(0.1) @@ -70,3 +74,16 @@ class TextCdromProgress(apt.CdromProgress): print "Please insert cdrom and press <ENTER>" answer = sys.stdin.readline() return True + + +if __name__ == "__main__": + c = apt.Cache() + pkg = c["3dchess"] + if pkg.isInstalled: + pkg.markDelete() + else: + pkg.markInstall() + + res = c.commit(TextFetchProgress(), TextInstallProgress()) + + print res |
