diff --git a/src/gui/qt/worker.py b/src/gui/qt/worker.py index b1b39ac..fca34bd 100644 --- a/src/gui/qt/worker.py +++ b/src/gui/qt/worker.py @@ -1,6 +1,5 @@ import sys,os import time -import re from tempfile import NamedTemporaryFile from PyQt4 import QtCore @@ -8,6 +7,7 @@ from PyQt4 import QtCore parentdir = sys.path[0].split(os.sep)[:-1] sys.path.append(os.sep.join(parentdir)) from tomblib.tomb import Tomb +from tomblib.parser import parse_line class TombCreateThread(QtCore.QThread): line_received = QtCore.pyqtSignal(QtCore.QString) @@ -58,7 +58,6 @@ class TombOutputThread(QtCore.QThread): #This could be simplified, and s/search/match, if --no-color supported #see #59 #TODO: this should be moved to tomblib.parse - err_regex = re.compile(r'\[!\][^ ]* +(.+)$') - match = err_regex.search(line) - if match: - self.error_received.emit(match.group(1)) + parsed = parse_line(line) + if parsed and parsed['type'] == 'error': + self.error_received.emit(parsed.content) diff --git a/src/gui/tomblib/parser.py b/src/gui/tomblib/parser.py new file mode 100644 index 0000000..5edc7cf --- /dev/null +++ b/src/gui/tomblib/parser.py @@ -0,0 +1,20 @@ +''' +Utilities to analyze tomb output +''' +import re + +_err_regex = re.compile(r'\[!\][^ ]* +(.+)$') +def parse_line(line): + '''Analyze a single line. + Return None if no standard format is detected, a dict otherwise. + The fields 'type' and 'content' are always in the dict; 'content' may be + empty + 'type' can be 'error', 'progress' + ''' + + match = _err_regex.search(line) + if match: + return { 'type': 'error', 'content': match.group(1) } + return None + + diff --git a/src/gui/tomblib/tomb.py b/src/gui/tomblib/tomb.py index 6f5abe1..7597351 100644 --- a/src/gui/tomblib/tomb.py +++ b/src/gui/tomblib/tomb.py @@ -28,7 +28,7 @@ class Tomb(object): Returns None on error, the path on success. ''' try: - path=subprocess.check_output(['which', 'tomb']) + path = subprocess.check_output(['which', 'tomb']) except subprocess.CalledProcessError: return None return path @@ -47,7 +47,7 @@ class Tomb(object): return True @classmethod - def create(cls, tombpath,tombsize,keypath, stdout=None, stderr=None, no_color=True, ignore_swap=False): + def create(cls, tombpath, tombsize,keypath, stdout=None, stderr=None, no_color=True, ignore_swap=False): '''If keypath is None, it will be created adjacent to the tomb. This is unsafe, and you should NOT do it.