651f8f37228b

Clean up a few things.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 16 Sep 2009 20:19:04 -0400
parents 2688abb7ae12
children c4d85f19c869
branches/tags (none)
files t.py

Changes

--- a/t.py	Wed Sep 16 20:14:06 2009 -0400
+++ b/t.py	Wed Sep 16 20:19:04 2009 -0400
@@ -50,7 +50,7 @@
     
     """
     text, _, meta = taskline.partition('|')
-    task = {'text': text.strip()}
+    task = { 'text': text.strip() }
     for piece in meta.strip().split(','):
         label, data = piece.split(':')
         task[label.strip()] = data.strip()
@@ -98,7 +98,7 @@
                 raise InvalidTaskfile
             if os.path.exists(path):
                 with open(path, 'r') as tfile:
-                    tls = [tl.strip() for tl in tfile.xreadlines() if tl]
+                    tls = [tl.strip() for tl in tfile if tl]
                     tasks = map(_task_from_taskline, tls)
                     for task in tasks:
                         getattr(self, kind)[task['id']] = task
@@ -133,8 +133,9 @@
         """Edit the task with the given prefix.
         
         If more than one task matches the prefix an AmbiguousPrefix exception
-        will be raised, if no tasks match it an UnknownPrefix exception will
-        be raised.
+        will be raised, unless the prefix is the entire ID of one task.
+        
+        If no tasks match the prefix an UnknownPrefix exception will be raised.
         
         """
         task = self[prefix]
@@ -167,7 +168,7 @@
         
         plen = max(map(lambda t: len(t[label]), tasks.values())) if tasks else 0
         for task in tasks.values():
-            p = (('%-' + str(plen) + 's - ') % task[label]) if not quiet else ''
+            p = '%s - ' % task[label].ljust(plen) if not quiet else ''
             print p + task['text']
     
     def write(self):
@@ -179,8 +180,7 @@
                 raise InvalidTaskfile
             with open(path, 'w') as tfile:
                 tasks = getattr(self, kind).values()
-                tasks.sort(key=operator.itemgetter('id'))
-                for task in tasks:
+                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))