X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/blobdiff_plain/a56304e62b2363d77510bc5727c5a4ba82f4549f..2c37e29bb427694643b92fbada6eb0986a815950:/tasklib/task.py?ds=sidebyside diff --git a/tasklib/task.py b/tasklib/task.py index e346f67..9246e1f 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -230,7 +230,7 @@ class TaskQuerySet(object): class TaskWarrior(object): def __init__(self, data_location='~/.task', create=True): data_location = os.path.expanduser(data_location) - if not os.path.exists(data_location): + if create and not os.path.exists(data_location): os.makedirs(data_location) self.config = { 'data.location': os.path.expanduser(data_location), @@ -252,9 +252,12 @@ class TaskWarrior(object): logger.debug(' '.join(command_args)) p = subprocess.Popen(command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = p.communicate() + stdout, stderr = [x.decode() for x in p.communicate()] if p.returncode: - error_msg = stderr.strip().splitlines()[-1] + if stderr.strip(): + error_msg = stderr.strip().splitlines()[-1] + else: + error_msg = stdout.strip() raise TaskWarriorException(error_msg) return stdout.strip().split('\n') @@ -263,7 +266,11 @@ class TaskWarrior(object): tasks = [] for line in self.execute_command(args): if line: - tasks.append(Task(self, json.loads(line.strip(',')))) + data = line.strip(',') + try: + tasks.append(Task(self, json.loads(data))) + except ValueError: + raise TaskWarriorException('Invalid JSON: %s' % data) return tasks def merge_with(self, path, push=False):