Browse Source

refactor progress_from_line()

pull/120/head
Alexander Gordeyev 9 years ago
parent
commit
463696b1f5
1 changed files with 19 additions and 17 deletions
  1. 36
      gooey/gui/controller.py

36
gooey/gui/controller.py

@ -134,26 +134,28 @@ class Controller(object):
return None
progress_expr = self.build_spec['progress_expr']
if progress_expr:
def safe_float(x):
try:
return float(x)
except ValueError:
return x
eval_locals = {k: safe_float(v) for k, v in match.groupdict().items()}
if "x" not in eval_locals:
eval_locals["x"] = [safe_float(x) for x in match.groups()]
try:
value = eval(progress_expr, {}, eval_locals)
except:
return None
return self._eval_progress(match, progress_expr)
else:
return self._search_progress(match)
def _search_progress(self, match):
try:
return int(float(match.group(1)))
except:
return None
def _eval_progress(self, match, eval_expr):
def safe_float(x):
try:
value = match.group(1)
except IndexError:
return None
return float(x)
except ValueError:
return x
_locals = {k: safe_float(v) for k, v in match.groupdict().items()}
if "x" not in _locals:
_locals["x"] = [safe_float(x) for x in match.groups()]
try:
return int(value)
except ValueError:
return int(float(eval(eval_expr, {}, _locals)))
except:
return None
def process_result(self, process):

Loading…
Cancel
Save