diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-11-28 13:01:29 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-11-28 13:01:29 +0000 |
| commit | 311111a187216e25957c08e7c2e114b0118a48e2 (patch) | |
| tree | 8fc864ae10bf3c90fb7ab45ff6b1418ea94c4c72 | |
| parent | 0a8598b3b728e0445f84186b3f302734d1347371 (diff) | |
| download | python-apt-311111a187216e25957c08e7c2e114b0118a48e2.tar.gz | |
* cache.commit() uses the packagemanager python code now (+fix the gui-inst example)
| -rw-r--r-- | apt/cache.py | 7 | ||||
| -rw-r--r-- | apt/progress.py | 2 | ||||
| -rwxr-xr-x | doc/examples/gui-inst.py | 53 |
3 files changed, 38 insertions, 24 deletions
diff --git a/apt/cache.py b/apt/cache.py index ab3775aa..259d7b9d 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -158,8 +158,11 @@ class Cache(object): return res def installArchives(self, pm, installProgress): - return pm.DoInstall() - + installProgress.startUpdate() + res = installProgress.run(pm) + installProgress.finishUpdate() + return res + def commit(self, fetchProgress=None, installProgress=None): """ Apply the marked changes to the cache """ # FIXME: diff --git a/apt/progress.py b/apt/progress.py index 6b4a10e3..552c9e75 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -123,6 +123,8 @@ class InstallProgress: pass def startUpdate(self): pass + def run(self, pm): + return pm.DoInstall() def finishUpdate(self): pass def updateInterface(self): diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py index 38417e10..1cb551ef 100755 --- a/doc/examples/gui-inst.py +++ b/doc/examples/gui-inst.py @@ -2,6 +2,7 @@ # example how to install in a custom terminal widget # see also gnome bug: #169201 +import apt import apt_pkg import sys, os, fcntl import copy @@ -13,6 +14,7 @@ pygtk.require('2.0') import gtk import vte import time +import posix from apt.progress import OpProgress, FetchProgress, InstallProgress @@ -50,11 +52,16 @@ class TermInstallProgress(InstallProgress, gtk.Window): self.add(box) self.term = vte.Terminal() self.term.show() + # check for the child + self.reaper = vte.reaper_get() + self.reaper.connect("child-exited",self.child_exited) + self.finished = False + box.pack_start(self.term) self.progressbar = gtk.ProgressBar() self.progressbar.show() box.pack_start(self.progressbar) - + (read, write) = os.pipe() self.writefd=write self.status = os.fdopen(read, "r") @@ -62,7 +69,12 @@ class TermInstallProgress(InstallProgress, gtk.Window): print "read-fd: %s" % self.status.fileno() print "write-fd: %s" % self.writefd self.read = "" - + + def child_exited(self,term, pid, status): + print "child_exited: %s %s %s %s" % (self,term,pid,status) + self.apt_status = posix.WEXITSTATUS(status) + self.finished = True + def startUpdate(self): print "start" self.show() @@ -84,29 +96,26 @@ class TermInstallProgress(InstallProgress, gtk.Window): self.read = "" while gtk.events_pending(): gtk.main_iteration() + def finishUpdate(self): sys.stdin.readline() - def fork(self): + def run(self, pm): print "fork" env = ["VTE_PTY_KEEP_FD=%s"%self.writefd] print env pid = self.term.forkpty(envv=env) + if pid == 0: + res = pm.DoInstall(self.writefd) + print res + sys.exit(res) print "After fork: %s " % pid - return pid - - -# init -apt_pkg.init() - -progress = OpProgress() -cache = apt_pkg.GetCache(progress) -print "Available packages: %s " % cache.PackageCount + while not self.finished: + self.updateInterface() + return self.apt_status +cache = apt.Cache() +print "Available packages: %s " % cache._cache.PackageCount -# get depcache -depcache = apt_pkg.GetDepCache(cache) -depcache.ReadPinFile() -depcache.Init(progress) # update the cache fprogress = GuiFetchProgress() @@ -125,15 +134,15 @@ while gtk.events_pending(): gtk.main_iteration() -iter = cache["3dchess"] -print "\n%s"%iter +pkg = cache["3dchess"] +print "\n%s"%pkg.name # install or remove, the importend thing is to keep us busy :) -if iter.CurrentVer == None: - depcache.MarkInstall(iter) +if pkg.isInstalled: + pkg.markDelete() else: - depcache.MarkDelete(iter) -depcache.Commit(fprogress, iprogress) + pkg.markInstall() +cache.commit(fprogress, iprogress) print "Exiting" sys.exit(0) |
