]> git.madduck.net Git - etc/taskwarrior.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Improve get_tasks to allow arbitrary filtering
authorRob Golding <rob@robgolding.com>
Wed, 10 Apr 2013 13:13:28 +0000 (14:13 +0100)
committerRob Golding <rob@robgolding.com>
Wed, 10 Apr 2013 13:13:28 +0000 (14:13 +0100)
tasklib/task.py

index f74e0d25510028853f52c4511b09d37956f32371..5e2b71b66a48d4b87e6ad8c27ccbb932bb76ace4 100644 (file)
@@ -47,6 +47,9 @@ class Task(object):
 
 
 class TaskWarrior(object):
+    DEFAULT_FILTERS = {
+        'status': 'pending',
+    }
 
     def __init__(self, data_location='~/.task', create=True):
         if not os.path.exists(data_location):
@@ -70,10 +73,19 @@ class TaskWarrior(object):
             raise TaskWarriorException(stderr.strip())
         return stdout.strip().split('\n')
 
-    def get_tasks(self, project=None, status=PENDING):
-        command = 'export status:{0}'.format(status)
-        if project is not None:
-            command += ' project:{0}'.format(project)
+    def _format_filter_kwarg(self, kwarg):
+        key, val = kwarg[0], kwarg[1]
+        if key in ['tag', 'tags']:
+            key = 'tags.equal'
+        key = key.replace('__', '.')
+        return '{0}:{1}'.format(key, val)
+
+    def get_tasks(self, **filter_kwargs):
+        filters = self.DEFAULT_FILTERS
+        filters.update(filter_kwargs)
+        filter_commands = ' '.join(map(self._format_filter_kwarg,
+                                       filters.items()))
+        command = '{0} export'.format(filter_commands)
         tasks = []
         for line in self._execute(command):
             if line: