[Reportbug-commits] [SCM] Reportbug - reports bugs in the Debian distribution branch, master, updated. 4.9-24-g20c16d9

Sandro Tosi morph at debian.org
Mon Jan 4 18:32:15 UTC 2010


The following commit has been merged in the master branch:
commit b321f8a514827ad1211431e80f7d5635cdc4b0cb
Author: Sandro Tosi <morph at debian.org>
Date:   Mon Jan 4 10:05:12 2010 +0100

    MUA handling now done with a OO-style, reworked emacs integration to use emacsclient to reuse an existing emacs instance (if any); thanks to Dan Jacobson for the report and Håkon Stordahl for the patch; Closes: #367298

diff --git a/debian/changelog b/debian/changelog
index 22a406b..c3198a2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -43,8 +43,13 @@ reportbug (4.10~WIP) UNRELEASED; urgency=low
       email; thanks to Andrei Popescu for the report; Closes: #526631
     - clarified the menu showing bugs already present, changing the title and
       the buttons; thanks to Nick for the report; Closes: #462614
+  * reportbug/{submit.py, utils.py}, share/reportbug.el, doc/README.Users,
+    debian/control
+    - MUA handling now done with a OO-style, reworked emacs integration to use
+      emacsclient to reuse an existing emacs instance (if any); thanks to Dan
+      Jacobson for the report and Håkon Stordahl for the patch; Closes: #367298
 
- -- Sandro Tosi <morph at debian.org>  Sun, 03 Jan 2010 20:10:03 +0100
+ -- Sandro Tosi <morph at debian.org>  Mon, 04 Jan 2010 10:01:15 +0100
 
 reportbug (4.9) unstable; urgency=low
 
diff --git a/debian/control b/debian/control
index 6cce94b..bd630fe 100644
--- a/debian/control
+++ b/debian/control
@@ -14,7 +14,7 @@ Homepage: http://alioth.debian.org/projects/reportbug/
 Package: reportbug
 Architecture: all
 Depends: ${python:Depends}, apt, python-reportbug (= ${source:Version})
-Suggests: postfix | exim4 | mail-transport-agent, gnupg | pgp, debconf-utils (>> 1.1.0), debsums (>= 2.0.47), file (>> 1.30), dlocate, python-urwid, python-gtk2, python-vte, python-gtkspell, xdg-utils
+Suggests: postfix | exim4 | mail-transport-agent, gnupg | pgp, debconf-utils (>> 1.1.0), debsums (>= 2.0.47), file (>> 1.30), dlocate, python-urwid, python-gtk2, python-vte, python-gtkspell, xdg-utils, emacs22-bin-common | emacs23-bin-common
 Conflicts: python-urwid (<< 0.9.8-1), python-central (<< 0.5.13), debsums (<< 2.0.47)
 XB-Python-Version: ${python:Versions}
 Description: reports bugs in the Debian distribution
diff --git a/doc/README.Users b/doc/README.Users
index 7d9709f..6e376fe 100644
--- a/doc/README.Users
+++ b/doc/README.Users
@@ -50,3 +50,30 @@ If after installing both of them still GTK+ UI doesn't show up, please
 file a report (in text ui :) ).
 
 Thanks to: Sandro Tosi <morph at debian.org>
+
+How to Use `gnus` MUA effectively
+=================================
+
+reportbug is now able to use an already running instance of emacs,
+instead of spawning a new one.
+
+In order to obtain that, you have to install:
+
+- `emacs22-bin-common` or `emacs23-bin-common` (as mentioned in
+  Suggests control field)
+
+that contains the `emacsclient` program needed for the integration to
+work (minimum version is 22 because earlier versions of `emacsclient`
+did not support the `--eval` option).
+
+Then a change to ~/.emacs file is needed, in order to add:
+
+  (server-start)
+
+or else Emacs won't listen for connections from emacsclient (and a new
+`emacs` instance is executed).
+
+With this changes, using the `gnus` MUA, the mail is opened in the
+running `emacs`, or if there's none, a new instance is executed.
+
+Thanks to: Håkon Stordahl <hakon at stordahl.org>
\ No newline at end of file
diff --git a/reportbug/submit.py b/reportbug/submit.py
index 0d8af0d..e47ed22 100644
--- a/reportbug/submit.py
+++ b/reportbug/submit.py
@@ -430,15 +430,11 @@ def send_report(body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
             ewrite('Original write failed, wrote bug report to %s\n', msgname)
 
     if mua:
-        for bit in mua.split():
-            if '%s' not in bit: break
-        ewrite("Spawning %s...\n", bit or mua)
-        if '%s' not in mua:
-            mua += ' %s'
+        ewrite("Spawning %s...\n", mua.name)
         returnvalue = 0
         succeeded = False
         while not succeeded:
-            returnvalue = ui.system(mua % commands.mkarg(filename)[1:])
+            returnvalue = mua.send(filename)
             if returnvalue != 0:
                 ewrite("Mutt users should be aware it is mandatory to edit the draft before sending.\n")
                 mtitle = 'Report has not been sent yet; what do you want to do now?'
diff --git a/reportbug/utils.py b/reportbug/utils.py
index 932b25d..92c99ba 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -46,6 +46,9 @@ import subprocess
 import debianbts
 from string import ascii_letters, digits
 
+# needed for MUA send
+import ui.text_ui as ui
+
 # Paths for dpkg
 DPKGLIB = '/var/lib/dpkg'
 AVAILDB = os.path.join(DPKGLIB, 'available')
@@ -752,13 +755,43 @@ CONFIG_ARGS = (
     'printonly', 'offline', 'check_uid', 'smtptls', 'smtpuser', 'smtppasswd',
     'paranoid')
 
+class Mua:
+    command = ""
+    name = ""
+
+    def __init__(self, command):
+        self.command = command
+        self.name = command.split()[0]
+
+    def send(self, filename):
+        mua = self.command
+        if '%s' not in mua:
+            mua += ' %s'
+        return ui.system(mua % commands.mkarg(filename)[1:])
+
+class Gnus(Mua):
+    name = "gnus"
+
+    def __init__(self):
+        pass
+
+    def send(self, filename):
+        elisp = """(progn
+                      (load-file "/usr/share/reportbug/reportbug.el")
+                      (tfheen-reportbug-insert-template "%s"))"""
+        filename = re.sub("[\"\\\\]", "\\\\\\g<0>", filename)
+        elisp = commands.mkarg(elisp % filename)
+        return ui.system("emacsclient --no-wait --eval %s 2>/dev/null"
+                         " || emacs --eval %s" % (elisp, elisp))
+
 MUA = {
-    'mutt' : 'mutt -H',
-    'mh' : '/usr/bin/mh/comp -use -file',
-    'gnus' : 'REPORTBUG=%s emacs -l /usr/share/reportbug/reportbug.el -f tfheen-reportbug-insert-template',
+    'mutt' : Mua('mutt -H'),
+    'mh' : Mua('/usr/bin/mh/comp -use -file'),
+    'gnus' : Gnus(),
     }
 MUA['nmh'] = MUA['mh']
 
+# TODO: convert them to class methods
 MUAVERSION = {
     MUA['mutt'] : 'mutt -v',
     MUA['mh'] : '/usr/bin/mh/comp -use -file',
@@ -774,7 +807,9 @@ def mua_is_supported(mua):
     elif mua == 'gnus' or mua == MUA['gnus']:
         mua = 'gnus'
     else:
-        mua = mua.split()[0]
+        pass
+	# FIXME: to adapt to new OO-style; previously it was:
+	# mua = mua.split()[0]
     if mua not in MUA:
         return False
     else:
@@ -789,7 +824,7 @@ def mua_exists(mua):
     elif mua == 'gnus' or mua == MUA['gnus']:
         mua = MUA['gnus']
     else:
-        mua = MUA[mua.split()[0]]
+        mua = MUA[mua]
     output = '/dev/null'
     if os.path.exists(output):
         try:
diff --git a/share/reportbug.el b/share/reportbug.el
index df7bf8b..3b88e15 100644
--- a/share/reportbug.el
+++ b/share/reportbug.el
@@ -10,10 +10,10 @@
 (if (or
      ;; Check for a separately packaged release of Gnus
      ;; (second component of version number even):
-     (= (% (string-to-int (match-string 2 gnus-version-number)) 2) 0)
+     (= (% (string-to-number (match-string 2 gnus-version-number)) 2) 0)
      ;; Check for a separately packaged pre-release of Gnus
      ;; (first component of version number 0):
-     (= (string-to-int (match-string 1 gnus-version-number)) 0))
+     (= (string-to-number (match-string 1 gnus-version-number)) 0))
     (require 'gnus-load))
 
 (defun tfheen-set-header (header value)
@@ -24,10 +24,10 @@
   (insert value)
   (widen))
 
-(defun tfheen-reportbug-insert-template ()
+(defun tfheen-reportbug-insert-template (reportbug-template)
   (interactive)
   (require 'gnus)
-  (find-file (getenv "REPORTBUG"))
+  (find-file reportbug-template)
   (let ((subject (message-fetch-field "Subject"))
         (toaddr (or (message-fetch-field "To") "submit at bugs.debian.org")))
     (gnus-narrow-to-body)
@@ -37,5 +37,7 @@
       (tfheen-set-header "To" toaddr)
       (gnus-narrow-to-body)
       (insert body)
+      (goto-char (point-min))
+      (search-forward "\n\n" nil t)
       (widen)))
-  (kill-buffer (find-buffer-visiting (getenv "REPORTBUG"))))
+  (kill-buffer (find-buffer-visiting reportbug-template)))

-- 
Reportbug - reports bugs in the Debian distribution



More information about the Reportbug-commits mailing list