diff options
Diffstat (limited to 'grc/gui/Executor.py')
-rw-r--r-- | grc/gui/Executor.py | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py index bab23dfdb8..480917f3f1 100644 --- a/grc/gui/Executor.py +++ b/grc/gui/Executor.py @@ -15,15 +15,16 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -import gobject +from __future__ import absolute_import + import os -import threading import shlex import subprocess -import sys -import re +import threading from distutils.spawn import find_executable +from gi.repository import GLib + from ..core import Messages @@ -33,19 +34,16 @@ class ExecFlowGraphThread(threading.Thread): def __init__(self, flow_graph_page, xterm_executable, callback): """ ExecFlowGraphThread constructor. - - Args: - action_handler: an instance of an ActionHandler """ threading.Thread.__init__(self) self.page = flow_graph_page # store page and don't use main window calls in run + self.flow_graph = self.page.flow_graph self.xterm_executable = xterm_executable self.update_callback = callback try: - self.process = self._popen() - self.page.set_proc(self.process) + self.process = self.page.process = self._popen() self.update_callback() self.start() except Exception as e: @@ -56,16 +54,9 @@ class ExecFlowGraphThread(threading.Thread): """ Execute this python flow graph. """ - run_command = self.page.get_flow_graph().get_option('run_command') generator = self.page.get_generator() - - try: - run_command = run_command.format( - python=shlex_quote(sys.executable), - filename=shlex_quote(generator.file_path)) - run_command_args = shlex.split(run_command) - except Exception as e: - raise ValueError("Can't parse run command {!r}: {0}".format(run_command, e)) + run_command = self.flow_graph.get_run_command(generator.file_path) + run_command_args = shlex.split(run_command) # When in no gui mode on linux, use a graphical terminal (looks nice) xterm_executable = find_executable(self.xterm_executable) @@ -86,36 +77,18 @@ class ExecFlowGraphThread(threading.Thread): def run(self): """ Wait on the executing process by reading from its stdout. - Use gobject.idle_add when calling functions that modify gtk objects. + Use GObject.idle_add when calling functions that modify gtk objects. """ # handle completion r = "\n" while r: - gobject.idle_add(Messages.send_verbose_exec, r) - r = os.read(self.process.stdout.fileno(), 1024) + GLib.idle_add(Messages.send_verbose_exec, r) + r = self.process.stdout.read(1024).decode('utf-8','ignore') self.process.poll() - gobject.idle_add(self.done) + GLib.idle_add(self.done) def done(self): """Perform end of execution tasks.""" Messages.send_end_exec(self.process.returncode) - self.page.set_proc(None) + self.page.process = None self.update_callback() - - -########################################################### -# back-port from python3 -########################################################### -_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search - - -def shlex_quote(s): - """Return a shell-escaped version of the string *s*.""" - if not s: - return "''" - if _find_unsafe(s) is None: - return s - - # use single quotes, and put single quotes into double quotes - # the string $'b is then quoted as '$'"'"'b' - return "'" + s.replace("'", "'\"'\"'") + "'" |