From 55b2eeb0b63b544b3519b019f6d3969d88296618 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 10:59:54 +0000 Subject: * interface fixes for kamion, pychecker fixes --- apt/cache.py | 18 +++++------------- apt/package.py | 18 ++++++++++-------- apt/progress.py | 18 +++++++++++++----- 3 files changed, 28 insertions(+), 26 deletions(-) (limited to 'apt') diff --git a/apt/cache.py b/apt/cache.py index fbca0f2a..c98c0d49 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) @@ -266,11 +262,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 +329,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..9a4a90e6 100644 --- a/apt/package.py +++ b/apt/package.py @@ -19,19 +19,21 @@ # 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 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 +54,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 +319,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..9958b9b7 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 """ @@ -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, percent, status_str) + self.percent = float(percent) + self.status = string.strip(status_str) self.read = "" def fork(self): -- cgit v1.2.3 From ef973e43572c5748f908ae0e353e71d61028b479 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 11:51:52 +0000 Subject: * initalize FetchProgress.eta as float and pass a float to InstallProgress.statusChanged() for percent --- apt/progress.py | 4 ++-- debian/changelog | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apt') diff --git a/apt/progress.py b/apt/progress.py index 9958b9b7..1b437a46 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -62,7 +62,7 @@ class FetchProgress(object): dlIgnored : "Ignored"} def __init__(self): - self.eta = "" + self.eta = 0.0 self.percent = 0.0 pass @@ -180,7 +180,7 @@ class InstallProgress(DumbInstallProgress): elif status == "pmstatus": if float(percent) != self.percent or \ status_str != self.status: - self.statusChange(pkg, percent, status_str) + self.statusChange(pkg, float(percent), status_str) self.percent = float(percent) self.status = string.strip(status_str) self.read = "" diff --git a/debian/changelog b/debian/changelog index 77e5794b..aef1f70c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.6.16.2) unstable; urgency=low +python-apt (0.6.16.2ubuntu1) dapper; urgency=low * apt/progress.py: - added InstallProgress.statusChange(pkg, percent, status) @@ -8,7 +8,7 @@ python-apt (0.6.16.2) unstable; urgency=low * apt/cache.py, apt/package.py: fix various pychecker warnings - -- + -- Michael Vogt Tue, 28 Feb 2006 12:04:37 +0100 python-apt (0.6.16.1) unstable; urgency=low -- cgit v1.2.3 From 6192052ee2e16c88303772c466016af6aa781ed0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 11:58:42 +0000 Subject: * strip status string before passing it, changelog updates --- apt/progress.py | 2 +- debian/changelog | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'apt') diff --git a/apt/progress.py b/apt/progress.py index 1b437a46..4119067c 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -180,7 +180,7 @@ class InstallProgress(DumbInstallProgress): elif status == "pmstatus": if float(percent) != self.percent or \ status_str != self.status: - self.statusChange(pkg, float(percent), status_str) + self.statusChange(pkg, float(percent), status_str.strip()) self.percent = float(percent) self.status = string.strip(status_str) self.read = "" diff --git a/debian/changelog b/debian/changelog index aef1f70c..94283b9d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +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() + + -- + python-apt (0.6.16.2ubuntu1) dapper; urgency=low * apt/progress.py: -- cgit v1.2.3 From cc3414d9a1a42e1978834392a2bead330c19ec99 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 13:11:50 +0000 Subject: * fix the return value of Cache.update() --- apt/cache.py | 6 +++--- debian/changelog | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'apt') diff --git a/apt/cache.py b/apt/cache.py index c98c0d49..459ffc40 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -148,7 +148,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 @@ -165,8 +164,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() diff --git a/debian/changelog b/debian/changelog index 94283b9d..cc7e7e56 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,10 @@ 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() - -- + -- Michael Vogt Tue, 28 Feb 2006 14:07:06 +0100 python-apt (0.6.16.2ubuntu1) dapper; urgency=low -- cgit v1.2.3 From 04fd391bf8f1b627f98b0aac4e4aa59c933eabe4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 13:18:48 +0000 Subject: * remove a useless check in Cache.update() --- apt/cache.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'apt') diff --git a/apt/cache.py b/apt/cache.py index 459ffc40..9218263b 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -112,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 -- cgit v1.2.3 From eb14999105a40543ee791bfa1c22b5dcf3d6fe37 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 1 Mar 2006 14:29:21 +0000 Subject: * undo some damage from pychecker --- apt/package.py | 1 + 1 file changed, 1 insertion(+) (limited to 'apt') diff --git a/apt/package.py b/apt/package.py index 9a4a90e6..4fceb904 100644 --- a/apt/package.py +++ b/apt/package.py @@ -22,6 +22,7 @@ import apt_pkg import sys import random +import string class Package(object): -- cgit v1.2.3 From 4e7cf23803ea29eb90b9c663cb6ded845067a6c7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 21 Mar 2006 15:08:34 +0100 Subject: * fix lock-releasing on exception (thanks to kamion) --- apt/cache.py | 42 +++++++++++++++++++++++------------------- debian/changelog | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'apt') diff --git a/apt/cache.py b/apt/cache.py index 9218263b..01034cf9 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -140,31 +140,35 @@ class Cache(object): if lock < 0: raise IOError, "Failed to lock %s" % lockfile - # this may as well throw a SystemError exception - if not pm.GetArchives(fetcher, self._list, self._records): - return False - # now run the fetcher, throw exception if something fails to be - # fetched - res = self._runFetcher(fetcher) - # cleanup - os.close(lock) - return res + try: + # this may as well throw a SystemError exception + if not pm.GetArchives(fetcher, self._list, self._records): + return False + # now run the fetcher, throw exception if something fails to be + # fetched + return self._runFetcher(fetcher) + finally: + os.close(lock) def update(self, fetchProgress=None): lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" lock = apt_pkg.GetLock(lockfile) if lock < 0: raise IOError, "Failed to lock %s" % lockfile - if fetchProgress == None: - fetchProgress = apt.progress.FetchProgress() - fetcher = apt_pkg.GetAcquire(fetchProgress) - # this can throw a exception - self._list.GetIndexes(fetcher) - # now run the fetcher, throw exception if something fails to be - # fetched - if self._runFetcher(fetcher) == fetcher.ResultContinue: - return True - return False + + try: + if fetchProgress == None: + fetchProgress = apt.progress.FetchProgress() + fetcher = apt_pkg.GetAcquire(fetchProgress) + # this can throw a exception + self._list.GetIndexes(fetcher) + # now run the fetcher, throw exception if something fails to be + # fetched + if self._runFetcher(fetcher) == fetcher.ResultContinue: + return True + return False + finally: + os.close(lock) def installArchives(self, pm, installProgress): installProgress.startUpdate() diff --git a/debian/changelog b/debian/changelog index 23f586d9..e621b8d6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,7 @@ python-apt (0.6.16.2) unstable; urgency=low * apt/cache.py: - return useful values on Cache.update() * apt/cache.py, apt/package.py: fix various pychecker warnings - + * apt/cache.py: Release locks on failure (thanks to Colin Watson) -- -- cgit v1.2.3