19 Kasım 2013 Salı

Python Script to View Todos in Code

Here's a little script I wrote to keep track of what to do. It lists all lines including a #TODO statement in the directory.
python todoer.py path/to/your/dictionary 

You may need to use python2 or modify the source code depending on your distro.
import re
import os
import sys

path = sys.argv[1]
files = os.listdir(path)
for fpath in files:    
    fileName, ext = os.path.splitext(fpath)
    if ext == ".py":
        print fpath
        print "=" * len(fpath)
        lines = open(fpath).readlines()
        for i in range(len(lines)):
            line = lines[i]
            match = re.search("#TODO", line)
            if match:
                line = re.sub("#TODO","",line)
                #Detect whitespace at the beginning
                j = 0
                while 1 < len(line) and line[j] in "\t ":
                    if line[j] in "\t ":
                        j += 1
                print "Line %s: %s" %(i, line[j:-1])
Sample output:
Line 34: right click menu
Line 30: remove dirs
Line 31: create confirmation popup / undo popup
Line 38: paste dirs
Line 47: load settings from a config file
Line 48: add settings and config file description to docstring
Line 53: load paths from a config file
Line 54: add config file description to docstring
Line 87: initialize dirTree with home folder of the user
Line 49: Implement loadIcon function, find icons for file types
Line 114: modify the code to draw only the selection to prevent flickering
Line 127: rewrite for better placing of newlines