[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 02/07: grc: escape run command vars for shl
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 02/07: grc: escape run command vars for shlex handling (bug #868) |
Date: |
Wed, 3 Feb 2016 20:00:59 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch maint
in repository gnuradio.
commit 9a37b65a7b8ba2728dccf161703d3a6a53faed9a
Author: Sebastian Koslowski <address@hidden>
Date: Mon Dec 28 10:58:46 2015 +0100
grc: escape run command vars for shlex handling (bug #868)
Thanks, Kevin McQuiggin for reporting this.
---
grc/gui/Messages.py | 2 +-
grc/python/Generator.py | 49 +++++++++++++++++++++++++++++++++++++------------
2 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/grc/gui/Messages.py b/grc/gui/Messages.py
index 32c6cf1..551a8ce 100644
--- a/grc/gui/Messages.py
+++ b/grc/gui/Messages.py
@@ -122,7 +122,7 @@ def send_fail_gen(error):
def send_start_exec(file_path):
- send('\nExecuting: %r\n' % file_path)
+ send('\nExecuting: %s\n' % file_path)
def send_verbose_exec(verbose):
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index d688beb..56e3a6e 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -23,6 +23,7 @@ import subprocess
import tempfile
import shlex
import codecs
+import re # for shlex_quote
from distutils.spawn import find_executable
from Cheetah.Template import Template
@@ -125,24 +126,30 @@ class TopBlockGenerator(object):
Returns:
a popen object
"""
- def args_to_string(args):
- """Accounts for spaces in args"""
- return ' '.join(repr(arg) if ' ' in arg else arg for arg in args)
-
run_command = self._flow_graph.get_option('run_command')
- cmds = shlex.split(run_command.format(python=sys.executable,
- filename=self.get_file_path()))
+ try:
+ run_command = run_command.format(
+ python=shlex_quote(sys.executable),
+ filename=shlex_quote(self.get_file_path()))
+ run_command_args = shlex.split(run_command)
+ except Exception as e:
+ raise ValueError("Can't parse run command {!r}:
{}".format(run_command, e))
# when in no gui mode on linux, use a graphical terminal (looks nice)
xterm_executable = find_executable(XTERM_EXECUTABLE)
if self._generate_options == 'no_gui' and xterm_executable:
- cmds = [xterm_executable, '-e', args_to_string(cmds)]
+ run_command_args = [xterm_executable, '-e', run_command]
- Messages.send_start_exec(args_to_string(cmds))
- p = subprocess.Popen(
- args=cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- shell=False, universal_newlines=True)
- return p
+ # this does not reproduce a shell executable command string, if a
graphical
+ # terminal is used. Passing run_command though shlex_quote would do it
but
+ # it looks really ugly and confusing in the console panel.
+ Messages.send_start_exec(' '.join(run_command_args))
+
+ return subprocess.Popen(
+ args=run_command_args,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ shell=False, universal_newlines=True
+ )
def _build_python_code_from_template(self):
"""
@@ -420,3 +427,21 @@ class QtHierBlockGenerator(HierBlockGenerator):
"\n${gui_hint()($win)}"
)
return n
+
+
+###########################################################
+# back-port from python3
+###########################################################
+_find_unsafe = re.compile(r'address@hidden:,./-]').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("'", "'\"'\"'") + "'"
- [Commit-gnuradio] [gnuradio] branch maint updated (11973c6 -> 15b8f49), git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 02/07: grc: escape run command vars for shlex handling (bug #868),
git <=
- [Commit-gnuradio] [gnuradio] 07/07: Merge remote-tracking branch 'tom/issue890' into maint, git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 03/07: qtgui: fixes issue #889., git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 01/07: grc: better message port handling for embedded python blocks, git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 06/07: Merge remote-tracking branch 'tom/issue889' into maint, git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 04/07: digital: addresses issue #890., git, 2016/02/03
- [Commit-gnuradio] [gnuradio] 05/07: gnuradio-runtime/hier_block2: Allow changing of IO sig in the constructor, git, 2016/02/03