Browse Source

Add option to suppress progress regex matches in stdout

pull/473/head
Conrrad 6 years ago
committed by Chris
parent
commit
28df915f29
5 changed files with 18 additions and 10 deletions
  1. 1
      gooey/gui/containers/application.py
  2. 12
      gooey/gui/processor.py
  3. 2
      gooey/python_bindings/config_generator.py
  4. 1
      gooey/python_bindings/gooey_decorator.py
  5. 12
      gooey/tests/test_processor.py

1
gooey/gui/containers/application.py

@ -48,6 +48,7 @@ class GooeyApplication(wx.Frame):
self.clientRunner = ProcessController(
self.buildSpec.get('progress_regex'),
self.buildSpec.get('progress_expr'),
self.buildSpec.get('hide_progress_msg'),
self.buildSpec.get('encoding'),
self.buildSpec.get('requires_shell'),
)

12
gooey/gui/processor.py

@ -13,10 +13,12 @@ from gooey.util.functional import unit, bind
class ProcessController(object):
def __init__(self, progress_regex, progress_expr, encoding, shell=True):
def __init__(self, progress_regex, progress_expr, hide_progress_msg,
encoding, shell=True):
self._process = None
self.progress_regex = progress_regex
self.progress_expr = progress_expr
self.hide_progress_msg = hide_progress_msg
self.encoding = encoding
self.wasForcefullyStopped = False
self.shell_execution = shell
@ -66,9 +68,11 @@ class ProcessController(object):
line = process.stdout.readline()
if not line:
break
pub.send_message(events.CONSOLE_UPDATE, msg=line.decode(self.encoding))
pub.send_message(events.PROGRESS_UPDATE,
progress=self._extract_progress(line))
_progress = self._extract_progress(line)
pub.send_message(events.PROGRESS_UPDATE, progress=_progress)
if _progress is None or self.hide_progress_msg is False:
pub.send_message(events.CONSOLE_UPDATE,
msg=line.decode(self.encoding))
pub.send_message(events.EXECUTION_COMPLETE)
def _extract_progress(self, text):

2
gooey/python_bindings/config_generator.py

@ -63,6 +63,7 @@ def create_from_parser(parser, source_path, **kwargs):
'language_dir': kwargs.get('language_dir'),
'progress_regex': kwargs.get('progress_regex'),
'progress_expr': kwargs.get('progress_expr'),
'hide_progress_msg': kwargs.get('hide_progress_msg', False),
'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
'disable_stop_button': kwargs.get('disable_stop_button'),
@ -81,6 +82,7 @@ def create_from_parser(parser, source_path, **kwargs):
'header_image_center': kwargs.get('header_image_center', False),
'footer_bg_color': kwargs.get('footer_bg_color', '#f0f0f0'),
'sidebar_bg_color': kwargs.get('sidebar_bg_color', '#f2f2f2'),
# font family, weight, and size are determined at runtime
'terminal_panel_color': kwargs.get('terminal_panel_color', '#F0F0F0'),
'terminal_font_color': kwargs.get('terminal_font_color', '#000000'),

1
gooey/python_bindings/gooey_decorator.py

@ -36,6 +36,7 @@ def Gooey(f=None,
language_dir=getResourcePath('languages'),
progress_regex=None, # TODO: add this to the docs
progress_expr=None, # TODO: add this to the docs
hide_progress_msg=False, # TODO: add this to the docs
disable_progress_bar_animation=False,
disable_stop_button=False,
group_by_type=True,

12
gooey/tests/test_processor.py

@ -9,27 +9,27 @@ class TestProcessor(unittest.TestCase):
def test_extract_progress(self):
# should pull out a number based on the supplied
# regex and expression
processor = ProcessController("^progress: (\d+)%$", None, 'utf-8')
processor = ProcessController("^progress: (\d+)%$", None, False, 'utf-8')
self.assertEqual(processor._extract_progress(b'progress: 50%'), 50)
processor = ProcessController("total: (\d+)%$", None, 'utf-8')
processor = ProcessController("total: (\d+)%$", None, False, 'utf-8')
self.assertEqual(processor._extract_progress(b'my cool total: 100%'), 100)
def test_extract_progress_returns_none_if_no_regex_supplied(self):
processor = ProcessController(None, None, 'utf-8')
processor = ProcessController(None, None, False, 'utf-8')
self.assertIsNone(processor._extract_progress(b'Total progress: 100%'))
def test_extract_progress_returns_none_if_no_match_found(self):
processor = ProcessController(r'(\d+)%$', None, 'utf-8')
processor = ProcessController(r'(\d+)%$', None, False, 'utf-8')
self.assertIsNone(processor._extract_progress(b'No match in dis string'))
def test_eval_progress(self):
# given a match in the string, should eval the result
regex = r'(\d+)/(\d+)$'
processor = ProcessController(regex, r'x[0] / x[1]', 'utf-8')
processor = ProcessController(regex, r'x[0] / x[1]', False, 'utf-8')
match = re.search(regex, '50/50')
self.assertEqual(processor._eval_progress(match), 1.0)
@ -37,6 +37,6 @@ class TestProcessor(unittest.TestCase):
def test_eval_progress_returns_none_on_failure(self):
# given a match in the string, should eval the result
regex = r'(\d+)/(\d+)$'
processor = ProcessController(regex, r'x[0] *^/* x[1]', 'utf-8')
processor = ProcessController(regex, r'x[0] *^/* x[1]', False, 'utf-8')
match = re.search(regex, '50/50')
self.assertIsNone(processor._eval_progress(match))
Loading…
Cancel
Save