diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2006-02-28 10:59:54 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2006-02-28 10:59:54 +0000 |
| commit | 55b2eeb0b63b544b3519b019f6d3969d88296618 (patch) | |
| tree | ef9a4ff5f89381b11d7fdd90de469758e7fa0ca4 | |
| parent | 9861af130e14ec76fd6b5e945ac5d57d8128503c (diff) | |
| download | python-apt-55b2eeb0b63b544b3519b019f6d3969d88296618.tar.gz | |
* interface fixes for kamion, pychecker fixes
| -rw-r--r-- | apt/cache.py | 18 | ||||
| -rw-r--r-- | apt/package.py | 18 | ||||
| -rw-r--r-- | apt/progress.py | 18 | ||||
| -rw-r--r-- | debian/changelog | 12 | ||||
| -rw-r--r-- | doc/examples/progress.py | 17 |
5 files changed, 57 insertions, 26 deletions
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): diff --git a/debian/changelog b/debian/changelog index 7b8925e0..4a37a69d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +python-apt (0.6.16.2) unstable; 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 11:40:38 +0100 + python-apt (0.6.16.1) unstable; urgency=low * memleak fixed when pkgCache objects are deallocated 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 |
