[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 02/08: grc: move run command getter to core
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 02/08: grc: move run command getter to core |
Date: |
Wed, 28 Sep 2016 11:42:40 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch next
in repository gnuradio.
commit 554ccb816cfaad5650513837f820a408105a87f2
Author: Sebastian Koslowski <address@hidden>
Date: Fri Sep 16 09:50:33 2016 -0600
grc: move run command getter to core
---
grc/core/FlowGraph.py | 16 +++++++++++++---
grc/core/utils/shlex.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
grc/gui/Executor.py | 41 ++++++++---------------------------------
3 files changed, 68 insertions(+), 36 deletions(-)
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index 949eeca..2c3c787 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -16,16 +16,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA
import imp
-import time
from itertools import ifilter, chain
from operator import methodcaller, attrgetter
-
import re
+import sys
+import time
from . import Messages
from .Constants import FLOW_GRAPH_FILE_FORMAT_VERSION
from .Element import Element
-from .utils import odict, expr_utils
+from .utils import odict, expr_utils, shlex
_parameter_matcher = re.compile('^(parameter)$')
_monitors_searcher = re.compile('(ctrlport_monitor)')
@@ -186,6 +186,16 @@ class FlowGraph(Element):
"""
return self._options_block.get_param(key).get_evaluated()
+ def get_run_command(self, file_path, split=False):
+ run_command = self.get_option('run_command')
+ try:
+ run_command = run_command.format(
+ python=shlex.quote(sys.executable),
+ filename=shlex.quote(file_path))
+ return shlex.split(run_command) if split else run_command
+ except Exception as e:
+ raise ValueError("Can't parse run command {!r}:
{}".format(run_command, e))
+
##############################################
# Access Elements
##############################################
diff --git a/grc/core/utils/shlex.py b/grc/core/utils/shlex.py
new file mode 100644
index 0000000..6b620fa
--- /dev/null
+++ b/grc/core/utils/shlex.py
@@ -0,0 +1,47 @@
+# Copyright 2016 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+from __future__ import absolute_import
+
+import re
+import shlex
+
+# 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("'", "'\"'\"'") + "'"
+
+
+if not hasattr(shlex, 'quote'):
+ quote = _shlex_quote
+else:
+ quote = shlex.quote
+
+split = shlex.split
diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py
index bf9eecb..f5a75ab 100644
--- a/grc/gui/Executor.py
+++ b/grc/gui/Executor.py
@@ -15,15 +15,14 @@
# 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
-import os
-import threading
-import shlex
import subprocess
-import sys
-import re
+import threading
from distutils.spawn import find_executable
+import gobject
+import os
+
+from ..core.utils import shlex
from ..core import Messages
@@ -40,6 +39,7 @@ class ExecFlowGraphThread(threading.Thread):
threading.Thread.__init__(self)
self.page = flow_graph_page # store page and dont use main window
calls in run
+ self.flow_graph = self.page.get_flow_graph()
self.xterm_executable = xterm_executable
self.update_callback = callback
@@ -56,16 +56,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}:
{}".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)
@@ -101,21 +94,3 @@ class ExecFlowGraphThread(threading.Thread):
Messages.send_end_exec(self.process.returncode)
self.page.set_proc(None)
self.update_callback()
-
-
-###########################################################
-# 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 next updated (bd7890f -> 0878c5c), git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 02/08: grc: move run command getter to core,
git <=
- [Commit-gnuradio] [gnuradio] 07/08: Merge branch 'master' into next, git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 04/08: grc: rewrite grcc, git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 03/08: grc: make recursive flow graph load and generate more flexible, git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 08/08: Merge remote-tracking branch 'skoslowski/grcc_refactor' into next, git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 05/08: grc: add some test code for grcc, git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 06/08: grc: changes to grcc CLI, git, 2016/09/28
- [Commit-gnuradio] [gnuradio] 01/08: grc: move grcc into grc subtree, git, 2016/09/28