[Reportbug-maint] [PATCH] Delegate system() to the UI

Luca Bruno lethalman88 at gmail.com
Sat Sep 13 13:42:04 UTC 2008


---
 bin/reportbug            |   12 ++----------
 debian/control           |    2 +-
 reportbug/submit.py      |   10 +---------
 reportbug/ui/gtk2_ui.py  |   33 ++++++++++++++++++++++++++++++++-
 reportbug/ui/newt_ui.py  |    1 +
 reportbug/ui/text_ui.py  |    7 +++++++
 reportbug/ui/urwid_ui.py |    1 +
 7 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/bin/reportbug b/bin/reportbug
index 2414ce4..9d69a3e 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -94,14 +94,6 @@ def stopmsg(filename):
         'it as bug report body, please take a look at the "-i FILE, '
         '--include=FILE" option.\n', filename)
 
-# Obscene hack :)
-def system(cmdline):
-    try:
-        x = os.getcwd()
-    except OSError:
-        os.chdir('/')
-    os.system(cmdline)
-
 def include_file_in_report(message, message_filename,
                            attachment_filenames, package_name,
                            include_filename, charset, inline=False):
@@ -1469,7 +1461,7 @@ orphaned for a long period of time are often removed from the archive.\n''')
                         break
                     elif x == 'd':
                         PAGER = os.environ.get('PAGER', '/usr/bin/sensible-pager')
-                        system(PAGER+' '+' '.join(changed))
+                        ui.system(PAGER+' '+' '.join(changed))
                     else:
                         break
 
@@ -1684,7 +1676,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),
+            ui.system('%s %s %s' % (handler, commands.mkarg(bugexec),
                                  commands.mkarg(filename)))
 
             addinfo = None
diff --git a/debian/control b/debian/control
index c1d591c..2ed4ca5 100644
--- a/debian/control
+++ b/debian/control
@@ -15,7 +15,7 @@ Homepage: http://alioth.debian.org/projects/reportbug/
 Package: reportbug
 Architecture: all
 Depends: ${python:Depends}, apt, python-reportbug
-Suggests: postfix | exim4 | mail-transport-agent, gnupg | pgp, debconf-utils (>> 1.1.0), debsums, file (>> 1.30), dlocate, python-urwid, python-gtk2
+Suggests: postfix | exim4 | mail-transport-agent, gnupg | pgp, debconf-utils (>> 1.1.0), debsums, file (>> 1.30), dlocate, python-urwid, python-gtk2, python-vte
 Conflicts: python-urwid (<< 0.9.8-1), python-central (<< 0.5.13)
 XB-Python-Version: ${python:Versions}
 Description: reports bugs in the Debian distribution
diff --git a/reportbug/submit.py b/reportbug/submit.py
index aba99b8..64a2f8f 100644
--- a/reportbug/submit.py
+++ b/reportbug/submit.py
@@ -49,14 +49,6 @@ import ui.text_ui as ui
 
 quietly = False
 
-# Obscene hack :)
-def system(cmdline):
-    try:
-        x = os.getcwd()
-    except OSError:
-        os.chdir('/')
-    os.system(cmdline)
-
 ascii_range = ''.join([chr(ai) for ai in range(32,127)])
 notascii = re.compile(r'[^'+re.escape(ascii_range)+']')
 notascii2 = re.compile(r'[^'+re.escape(ascii_range)+r'\s]')
@@ -425,7 +417,7 @@ def send_report(body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
         ewrite("Spawning %s...\n", bit or mua)
         if '%s' not in mua:
             mua += ' %s'
-        system(mua % commands.mkarg(filename)[1:])
+        ui.system(mua % commands.mkarg(filename)[1:])
     elif not failed and (using_sendmail or smtphost):
         if kudos:
             ewrite('\nMessage sent to: %s\n', sendto)
diff --git a/reportbug/ui/gtk2_ui.py b/reportbug/ui/gtk2_ui.py
index c21b72a..e8a3509 100644
--- a/reportbug/ui/gtk2_ui.py
+++ b/reportbug/ui/gtk2_ui.py
@@ -29,6 +29,11 @@ try:
 except ImportError:
     raise UINotImportable, 'Please install the python-gtk2 package to use this interface.'
 
+try:
+    import vte
+except ImportError:
+    raise UINotImportable, 'Please install the python-vte package to use this interface.'
+
 gdk.threads_init ()
 
 import sys
@@ -1068,6 +1073,31 @@ class SelectOptionsPage (Page):
 
         self.vbox.show_all ()
 
+class SystemPage (Page):
+    default_complete = False
+
+    def create_widget (self):
+        hbox = gtk.HBox ()
+
+        self.terminal = vte.Terminal ()
+        self.terminal.set_cursor_blinks (True)
+        self.terminal.set_emulation ("xterm")
+        self.terminal.connect ('child-exited', self.on_child_exited)
+        hbox.pack_start (self.terminal)
+
+        scrollbar = gtk.VScrollbar ()
+        scrollbar.set_adjustment (self.terminal.get_adjustment ())
+        hbox.pack_start (scrollbar)
+
+        return hbox
+
+    def on_child_exited (self, terminal):
+        self.set_page_complete (True)
+
+    def execute (self, cmdline):
+        print cmdline
+        self.terminal.fork_command ('/bin/bash', ['/bin/bash', '-c', cmdline])
+
 class ProgressPage (Page):
     page_type = gtk.ASSISTANT_PAGE_PROGRESS
 
@@ -1238,7 +1268,8 @@ pages = { 'get_string': GetStringPage,
           'final_message': FinalMessagePage,
           'spawn_editor': EditorPage,
           'select_options': SelectOptionsPage,
-          'get_list': GetListPage }
+          'get_list': GetListPage,
+          'system': SystemPage }
 dialogs = { 'yes_no': YesNoDialog,
             'get_filename': GetFilenameDialog,
             'display_failure': DisplayFailureDialog, }
diff --git a/reportbug/ui/newt_ui.py b/reportbug/ui/newt_ui.py
index 38fd461..064bd18 100644
--- a/reportbug/ui/newt_ui.py
+++ b/reportbug/ui/newt_ui.py
@@ -28,6 +28,7 @@ from reportbug_exceptions import (
     UINotImportable,
     NoPackage, NoBugs, NoNetwork,
     )
+from text_ui import system
 from urlutils import launch_browser
 
 try:
diff --git a/reportbug/ui/text_ui.py b/reportbug/ui/text_ui.py
index add7121..887f42e 100644
--- a/reportbug/ui/text_ui.py
+++ b/reportbug/ui/text_ui.py
@@ -67,6 +67,13 @@ def ewrite(message, *args):
 log_message = ewrite
 display_failure = ewrite
 
+def system(cmdline):
+    try:
+        x = os.getcwd()
+    except OSError:
+        os.chdir('/')
+    os.system(cmdline)
+
 def indent_wrap_text(text, starttext='', indent=0, linelen=None):
     """Wrapper for textwrap.fill to the existing API."""
     if not linelen:
diff --git a/reportbug/ui/urwid_ui.py b/reportbug/ui/urwid_ui.py
index 900d92b..f1386fa 100644
--- a/reportbug/ui/urwid_ui.py
+++ b/reportbug/ui/urwid_ui.py
@@ -35,6 +35,7 @@ from reportbug.urlutils import launch_browser
 from text_ui import (
     ewrite,
     spawn_editor,
+    system
     )
 from reportbug import VERSION
 
-- 
1.5.6.5


-- 
http://syx.googlecode.com - Smalltalk YX
http://lethalman.blogspot.com - Thoughts about computer technologies
http://www.ammazzatecitutti.org - Ammazzateci tutti
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/reportbug-maint/attachments/20080913/c3b71f65/attachment.pgp 


More information about the Reportbug-maint mailing list