Skip to content
Browse files

Refactor the tasks to taskline parsing, and add padding to the textfile.

  • Loading branch information...
1 parent c71453b commit eccc4d5aaf07dcd5ea5f1ae5ecafa8906c32182d @sjl sjl committed Sep 28, 2009
Showing with 18 additions and 6 deletions.
  1. +18 −6 t.py
View
24 t.py
@@ -4,7 +4,8 @@
from __future__ import with_statement
-import os, re, sys, hashlib, operator
+import os, re, sys, hashlib
+from operator import itemgetter
from optparse import OptionParser, OptionGroup
@@ -56,6 +57,19 @@ def _task_from_taskline(taskline):
task[label.strip()] = data.strip()
return task
+def _tasklines_from_tasks(tasks):
+ """Parse a list of tasks into tasklines suitable for writing."""
+
+ tasklines = []
+ tlen = max(map(lambda t: len(t['text']), tasks))
+
+ for task in tasks:
+ meta = [m for m in task.items() if m[0] != 'text']
+ meta_str = ', '.join('%s:%s' % m for m in meta)
+ tasklines.append('%s | %s\n' % (task['text'].ljust(tlen), meta_str))
+
+ return tasklines
+
def _prefixes(ids):
"""Return a mapping of ids to prefixes.
@@ -179,11 +193,9 @@ def write(self):
if os.path.isdir(path):
raise InvalidTaskfile
with open(path, 'w') as tfile:
- tasks = getattr(self, kind).values()
- for task in sorted(tasks, key=operator.itemgetter('id')):
- meta = [m for m in task.items() if m[0] != 'text']
- meta_str = ', '.join('%s:%s' % m for m in meta)
- tfile.write('%s | %s\n' % (task['text'], meta_str))
+ tasks = sorted(getattr(self, kind).values(), key=itemgetter('id'))
+ for taskline in _tasklines_from_tasks(tasks):
+ tfile.write(taskline)

0 comments on commit eccc4d5

Please sign in to comment.
Something went wrong with that request. Please try again.