-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 7 Sep 2008 18:18:05 +0200
"Sandro Tosi" <[EMAIL PROTECTED]> wrote:

> All applied as of r650.
> 
> Right after inserting bug text:
> 
> Traceback (most recent call last):
>   File "/usr/lib/python2.5/site-packages/reportbug/ui/gtk2_ui.py",
> line 1119, in on_prepare
>     self.showing_page.setup_focus ()
>   File "/usr/lib/python2.5/site-packages/reportbug/ui/gtk2_ui.py",
> line 1034, in setup_focus
>     if self.default:
> AttributeError: 'SelectOptionsPage' object has no attribute 'default'
> 
> Sandro
> 

I've forgotten the patches again, I'm sorry.


- -- 
http://syx.googlecode.com - Smalltalk YX
http://lethalman.blogspot.com - Thoughts about computer technologies
http://www.ammazzatecitutti.org - Ammazzateci tutti
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkjEFhgACgkQw9Qj+8Kak3EqZQCeO3JHfKdndN09+PADTnV3Ex7U
6FIAnAv97sEswyya+EV3zqv9FwPvedo+
=bJ0B
-----END PGP SIGNATURE-----
From 527206e1e97b77ced5bc074283c76ea9dc4db193 Mon Sep 17 00:00:00 2001
From: Luca Bruno <[EMAIL PROTECTED]>
Date: Sun, 7 Sep 2008 19:51:46 +0200
Subject: [PATCH] Fix handle_bugscript to use the UI.

---
 bin/reportbug           |   70 +++++++++++++++++++++++++++++++++++++++++++++-
 handle_bugscript        |   54 +++++++++++++++++-------------------
 reportbug/tempfiles.py  |    7 +++++
 reportbug/ui/gtk2_ui.py |    4 +++
 4 files changed, 105 insertions(+), 30 deletions(-)

diff --git a/bin/reportbug b/bin/reportbug
index 2414ce4..2f75646 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -47,6 +47,7 @@ from reportbug.utils import (
     )
 from reportbug.tempfiles import (
     TempFile,
+    TempFifo,
     tempfile_prefix,
     cleanup_temp_file,
     )
@@ -286,6 +287,72 @@ def handle_editing(filename, dmessage, options, sendto, attachments, package,
 
     return open(filename).read()
 
+class BugScript (object):
+    def __init__ (self, fifo):
+        self.fifo = fifo
+        self.message = ""
+
+    def yes_no (self, arg):
+        default = arg.rsplit(' ', 1)[-1]
+        prompt = arg[:-len(default)].strip ()
+        prompt = re.sub ('\[[yYnN/yYnN]\]', '', prompt).strip ()
+        if prompt[-1] == '?':
+            prompt = prompt[:-1]
+        res = ui.yes_no (prompt, "Yes", "No", default=default == 'yep')
+        if res:
+            return 'yep'
+        else:
+            return 'nop'
+
+    def append_message (self, line):
+        self.message += line
+
+    def long_message (self, arg=None):
+        if self.message:
+            ui.long_message (self.message)
+            self.message = ""
+
+    def handle_command (self, command):
+        op = command.split(' ', 1)[0].strip ()
+        arg = command[len(op):].strip ()
+        if op == 'end':
+            os.unlink (self.fifo)
+            return
+        if op == 'append_message':
+            self.append_message (arg)
+            return
+
+        # Show the message before each command
+        self.long_message ()
+        # Run the operation
+        result = getattr(self, op)(arg)
+
+        if result is not None:
+            fifo = os.open (self.fifo, os.O_WRONLY)
+            os.write (fifo, result)
+            os.close (fifo)
+
+    def run (self):
+        while True:
+            try:
+                fifo = os.fdopen (os.open (self.fifo, os.O_RDONLY), "r")
+            except:
+                break
+
+            commands = []
+            for line in fifo.readlines ():
+                commands.append (line)
+
+            fifo.close ()
+            for command in commands:
+                self.handle_command (command)
+
+def handle_bugscript (file, *args):
+    # We act as an UI server for the bugscript
+    fifo = TempFifo ("bugscript")
+    os.spawnl (os.P_NOWAIT, file, file, *(args + (fifo,)))
+    BugScript(fifo).run ()
+
 def find_package_for(filename, notatty=False, pathonly=False):
     ewrite("Finding package for '%s'...\n", filename)
     (newfilename, packages) = utils.find_package_for(filename, pathonly)
@@ -1684,8 +1751,7 @@ orphaned for a long period of time are often removed from the archive.\n''')
 
             fh, filename = TempFile(prefix=tfprefix)
             fh.close()
-            system('%s %s %s' % (handler, commands.mkarg(bugexec),
-                                 commands.mkarg(filename)))
+            handle_bugscript(handler, bugexec, filename)
 
             addinfo = None
             if not self.options.noconf:
diff --git a/handle_bugscript b/handle_bugscript
index 66c89cd..c519021 100755
--- a/handle_bugscript
+++ b/handle_bugscript
@@ -14,14 +14,32 @@
 
 set -e
 
+export FIFO=$3
+
+# Replace the original cat for backward compatibility
+cat()
+{
+    if [ -n "$1" ]; then
+        /usr/bin/env cat $@
+        return
+    fi
+
+    while [ $? -eq 0 ]; do
+        read -r WE
+        if [ -z "$WE" ]; then
+            return
+        fi
+        echo $WE
+        echo "append_message $WE" > $FIFO
+    done
+}
+
+export -f cat
+
 # Wait for a keypress and put it in $KEY
 getkey()
 {
-	stty -icanon min 1 || true 2> /dev/null
-	KEY=$(dd bs=1 count=1 2> /dev/null)
-	stty icanon || true 2> /dev/null
-	KEY="${KEY:0:1}"
-	echo
+    echo "long_message" > $FIFO
 }
 
 export -f getkey
@@ -31,32 +49,12 @@ export YESNO="yYnN"
 #	output: REPLY
 yesno()
 {
-	while true; do
-		echo -n "$1"
-
-		getkey
-
-		# if 'n'
-		if [ "$KEY" = "${YESNO:2:1}" ] || [ "$KEY" = "${YESNO:3:1}" ]; then
-			REPLY=nop
-			return
-		fi
-
-		# if 'y'
-		if [ "$KEY" = "${YESNO:0:1}" ] || [ "$KEY" = "${YESNO:1:1}" ]; then
-			REPLY=yep
-			return
-		fi
-
-		# if \n
-		if [ "$KEY" = "" ]; then
-			REPLY=$2
-			return
-		fi
-	done
+    echo "yes_no $1 $2" > $FIFO
+    REPLY=`/usr/bin/env cat $FIFO`
 }
 
 export -f yesno
 
 #&>3
 $1 3>|$2
+echo "end" > $FIFO
diff --git a/reportbug/tempfiles.py b/reportbug/tempfiles.py
index dcaa847..f3adf79 100644
--- a/reportbug/tempfiles.py
+++ b/reportbug/tempfiles.py
@@ -74,6 +74,13 @@ def TempFile(suffix="", prefix=template, dir=None, text=True,
     fd = os.fdopen(fh, mode, bufsize)
     return (fd, filename)
 
+# Wrapper for mkfifo; main difference is that it creates a temporary fifo
+# and returns the filename
+def TempFifo(suffix="", prefix=template, dir=None):
+    filename = tempfile.mktemp(suffix, prefix, dir)
+    os.mkfifo (filename)
+    return filename
+
 def cleanup_temp_file(temp_filename):
     """ Clean up a temporary file.
 
diff --git a/reportbug/ui/gtk2_ui.py b/reportbug/ui/gtk2_ui.py
index 740f56e..b2b093f 100644
--- a/reportbug/ui/gtk2_ui.py
+++ b/reportbug/ui/gtk2_ui.py
@@ -1164,6 +1164,10 @@ class YesNoDialog (ReportbugConnector, gtk.MessageDialog):
 
     def execute_operation (self, msg, yeshelp=None, nohelp=None, default=True, nowrap=False):
         self.set_markup (msg+"?")
+        if default:
+            self.set_default_response (gtk.RESPONSE_YES)
+        else:
+            self.set_default_response (gtk.RESPONSE_NO)
         self.show_all ()
 
 class DisplayFailureDialog (ReportbugConnector, gtk.MessageDialog):
-- 
1.5.6.5

From f0cb66049234e38b34fc5c34edb0e645b292bf1d Mon Sep 17 00:00:00 2001
From: Luca Bruno <[EMAIL PROTECTED]>
Date: Sun, 7 Sep 2008 19:52:00 +0200
Subject: [PATCH] Fix SelectOptions bug on focus

---
 reportbug/ui/gtk2_ui.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/reportbug/ui/gtk2_ui.py b/reportbug/ui/gtk2_ui.py
index b2b093f..77c4056 100644
--- a/reportbug/ui/gtk2_ui.py
+++ b/reportbug/ui/gtk2_ui.py
@@ -1024,6 +1024,7 @@ class SelectOptionsPage (Page):
         self.label = gtk.Label ()
         self.vbox = gtk.VBox (spacing=6)
         self.vbox.pack_start (self.label, expand=False, padding=6)
+        self.default = None
         return self.vbox
 
     def on_clicked (self, button, menuopt):
@@ -1034,11 +1035,11 @@ class SelectOptionsPage (Page):
         if self.default:
             self.default.set_flags (gtk.CAN_DEFAULT | gtk.HAS_DEFAULT)
             self.default.grab_default ()
+            self.default.grab_focus ()
 
     def execute (self, prompt, menuopts, options):
         self.label.set_text (prompt)
 
-        self.default = None
         buttons = []
         for menuopt in menuopts:
             desc = options[menuopt.lower ()]
-- 
1.5.6.5

_______________________________________________
Reportbug-maint mailing list
Reportbug-maint@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/reportbug-maint

Reply via email to