Commits

Anonymous committed 184acc1

add funtion find_property for organizing code. Effort_ALL property is converted to int.

Comments (0)

Files changed (3)

             alltags |= set(tag2.split(':')) - set([''])
     return (tag1, alltags, heading)
 
+_RE_PROP_SRCH = re.compile('^\s*:(.*?):\s*(.*?)\s*$')
+def find_property(line):
+    """
+    Find property from given string.
+    Return (key, value)-pair if found else (None, None).
+    """
+    prop_key = None
+    prop_val = None
+    prop_srch = _RE_PROP_SRCH.search(line)
+    if prop_srch:
+        prop_key = prop_srch.group(1)
+        prop_val = prop_srch.group(2)
+        if prop_key == 'Effort_ALL':
+            (h, m) = prop_val.split(":", 2)
+            if h.isdigit() and m.isdigit():
+                prop_val = int(h)*60 + int(m)
+    return (prop_key, prop_val)
+
 
 _RE_HEADING = re.compile('^(\*+)\s(.*?)\s*$')
 _RE_TODO_KWDS = re.compile(' ([A-Z][A-Z0-9]+)\(?')
-_RE_PROP_SRCH = re.compile('^\s*:(.*?):\s*(.*?)\s*$')
 _RE_TODO_SRCH = re.compile('([A-Z][A-Z0-9]+)\s(.*?)$')
 _RE_PRTY_SRCH = re.compile('^\[\#(A|B|C)\] (.*?)$')
 
                 continue
             if line.find(':PROPERTIES:') >= 0: continue
             if line.find(':END:') >= 0: continue
-            prop_srch = _RE_PROP_SRCH.search(line)
-            if prop_srch:
-                propdict[prop_srch.group(1)] = prop_srch.group(2)
+            (prop_key, prop_val) = find_property(line)
+            if prop_key:
+                propdict[prop_key] = prop_val
                 continue
             _sched_date = find_scheduled(line)
             _deadline_date = find_deadline(line)
 * Heading
   SCHEDULED: <2010-08-06 Fri> DEADLINE: <2010-08-10 Tue>
   :PROPERTIES:
-  :Effort_ALL: 0:10
+  :Effort_ALL: 1:10
   :END:
   - <2010-08-16 Mon> DateList
   - <2010-08-07 Sat>--<2010-08-08 Sun>
     dict(Heading = "Heading",
          Scheduled = date(2010, 8, 6),
          Deadline = date(2010, 8, 10),
-         Properties = dict(Effort_ALL='0:10'),
+         Properties = dict(Effort_ALL=70),
          DateList = [date(2010, 8, 16)],
          RangeList = [
              (date(2010, 8, 7), date(2010, 8, 8)),