novoid / lazyblorg

Blogging with Org-mode for very lazy people
GNU General Public License v3.0
397 stars 33 forks source link

Finished headings are not recognized when no prior state was assigned #61

Open novoid opened 2 years ago

novoid commented 2 years ago

The regex LOG_REGEX in https://github.com/novoid/lazyblorg/blob/master/lib/orgparser.py does not recognize the following snippet as a closed heading:

******* DONE no prior state
CLOSED: [2021-11-11 Thu 10:59]
:PROPERTIES:
:CREATED:  [2021-11-11 Thu 10:59]
:END:
:LOGBOOK:
- State "DONE"       from              [2021-11-11 Thu 10:59]
:END:

The issue is related to the missing double quotes similar to:

******* DONE with prior state
CLOSED: [2021-10-11 Mon 14:24] SCHEDULED: <2021-10-08 Fri>
:PROPERTIES:
:CREATED:  [2021-10-05 Tue 13:07]
:END:
:LOGBOOK:
- State "DONE"       from "STARTED"    [2021-10-11 Mon 14:24]
- State "STARTED"    from "WAITING"    [2021-10-07 Thu 17:46]
- State "WAITING"    from "NEXT"       [2021-10-05 Tue 14:16]
:END:

Analysis

>>> import re
>>> LOG_REGEX = re.compile(r'^- State\s+DONE\s+from\s+("\S*"\s+)?([\[{].*[\]}])$',re.IGNORECASE)
>>> LOG_REGEX.match('- State "DONE"     from ""      [2021-11-11 Thu 10:59]')
>>> LOG_REGEX.match('- State "DONE"       from "STARTED"    [2021-10-11 Mon 14:24]')
>>> LOG_REGEX.match('- State "DONE"     from       [2021-11-11 Thu 10:59]')
>>>

And:

>>> LOG_REGEX.match('- State DONE     from       [2021-11-11 Thu 10:59]')
<re.Match object; span=(0, 50), match='- State DONE     from       [2021-11-11 Thu 10:59>
>>> LOG_REGEX.match('- State DONE       from "STARTED"    [2021-10-11 Mon 14:24]')
<re.Match object; span=(0, 59), match='- State DONE       from "STARTED"    [2021-10-11 >

Proposed Solution

Modify the regex so that:

  1. the double quotes around the target status as well as
  2. the double quotes the previous status are optional
  3. improvement: do not make the time-stamp optional (* vs. +)
  4. generate test data with and without double quotes for:
    • no status -> DONE
    • no status -> STARTED -> DONE
  5. test it well.