X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/blobdiff_plain/0a55d5e7c3a56be520fc0806b970a59d50ae3c2f..2c37e29bb427694643b92fbada6eb0986a815950:/tasklib/task.py?ds=sidebyside diff --git a/tasklib/task.py b/tasklib/task.py index c3f8f3e..9246e1f 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -8,6 +8,7 @@ import subprocess DATE_FORMAT = '%Y%m%dT%H%M%SZ' REPR_OUTPUT_SIZE = 10 PENDING = 'pending' +COMPLETED = 'completed' logger = logging.getLogger(__name__) @@ -24,7 +25,6 @@ class Task(object): def __init__(self, warrior, data={}): self.warrior = warrior self._data = data - print data self._modified_fields = set() def __unicode__(self): @@ -76,7 +76,7 @@ class Task(object): }) def done(self): - self.warrior.execute_comamnd([self['id'], 'done']) + self.warrior.execute_command([self['id'], 'done']) def save(self): args = [self['id'], 'modify'] if self['id'] else ['add'] @@ -195,6 +195,9 @@ class TaskQuerySet(object): def pending(self): return self.filter(status=PENDING) + def completed(self): + return self.filter(status=COMPLETED) + def filter(self, *args, **kwargs): """ Returns a new TaskQuerySet with the given filters added. @@ -227,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), @@ -249,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') @@ -260,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):