[Debconf-devel] Bug#678311: apt-listchanges: debconf passthrough frontend for use with packagekit

Julien Cristau jcristau at debian.org
Wed Jun 20 19:47:38 UTC 2012


Package: apt-listchanges
Version: 2.85.10
Severity: normal
Tags: patch
X-Debbugs-Cc: packagekit at packages.debian.org, debconf at packages.debian.org

Hi,

when using packagekit, which seems to be the way gnome is going for
graphical package management nowadays, the apt-listchanges output
doesn't go anywhere, and the gpk window just seems to hang.
In order to fix that, it'd be nice if apt-listchanges could send its
output using the debconf protocol so it could show up in the packagekit
frontend.  The below patch is a proof of concept to that effect.  pk
would have to set APT_LISTCHANGES_FRONTEND=debconf for this to work (it
already sets APT_LISTBUGS_FRONTEND=none).  packagekit and debconf
maintainers cc:ed in case they have comments.

I'm not too happy about the tempfile thing instead of just using
db.subst to change the contents of the note, but I couldn't figure out
how to SUBST something with newlines (it didn't seem to work when I
tested with the dialog frontend, anyway).

Cheers,
Julien

diff --git a/apt-listchanges/apt_listchanges.py b/apt-listchanges/apt_listchanges.py
index 180a3dc..c5b62ac 100644
--- a/apt-listchanges/apt_listchanges.py
+++ b/apt-listchanges/apt_listchanges.py
@@ -103,6 +103,7 @@ def mail_changes(address, changes, subject):
 def make_frontend(name, packages, config):
     frontends = { 'text' : text,
                   'pager' : pager,
+                  'debconf': debconf,
                   'mail' : mail,
                   'browser' : browser,
                   'xterm-pager' : xterm_pager,
@@ -172,6 +173,50 @@ class frontend:
     def set_title(self, text):
         pass
 
+class debconf(frontend):
+    def set_title(self, text):
+        self.title = text
+
+    def display_output(self, text):
+        import socket
+        import debconf as dc
+        if 'DEBIAN_FRONTEND' not in os.environ or os.environ['DEBIAN_FRONTEND'] != 'passthrough':
+            return
+        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0)
+        sock.connect(os.environ['DEBCONF_PIPE'])
+        dcfd = sock.makefile()
+        sock.close()
+        db = dc.Debconf(read=dcfd, write=dcfd)
+        tmp = tempfile.NamedTemporaryFile(prefix="apt-listchanges-tmp")
+        os.fchmod(tmp.fileno(), 0644)
+        tmp.write('''Template: apt-listchanges/info
+Type: title
+Description: NEWS
+
+Template: apt-listchanges/title
+Type: title
+Description: ${title}
+
+Template: apt-listchanges/news
+Type: note
+Description: ${packages} packages''')
+        for line in text.split('\n'):
+            if line.strip():
+                tmp.write('  ' + line + '\n')
+            else:
+                tmp.write(' .\n')
+        tmp.flush()
+        db.command('x_loadtemplatefile', tmp.name)
+        tmp.close()
+        db.info('apt-listchanges/info')
+        db.subst('apt-listchanges/title', 'title', self.title)
+        db.subst('apt-listchanges/news', 'packages', self.packages)
+        db.settitle('apt-listchanges/title')
+        db.fset('apt-listchanges/news', 'seen', 'false')
+        db.input('high', 'apt-listchanges/news')
+        db.go()
+        dcfd.close()
+
 class ttyconfirm:
     def confirm(self):
         try:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/debconf-devel/attachments/20120620/b0d9cd0d/attachment.pgp>


More information about the Debconf-devel mailing list