The Artima Developer Community
Sponsored Link

Python Buzz Forum
Listing TODO items in your source

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Richard Jones

Posts: 55
Nickname: rjones
Registered: Jul, 2003

Richard Jones is an over-eager Python Open Source programmer
Listing TODO items in your source Posted: Jul 6, 2003 10:10 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Richard Jones.
Original Post: Listing TODO items in your source
Feed Title: Richard's stuff
Feed URL: http://mechanicalcat.net/cgi-bin/log?flav=rss
Feed Description: Stuff I'm interested in
Latest Python Buzz Posts
Latest Python Buzz Posts by Richard Jones
Latest Posts From Richard's stuff

Advertisement

This afternoon is TODO time (since my main job of the day - generating nice little help tooltips - was solved by the very cool overlib.) So, in usual fashion I avoid the job for a while and write a script to help me. The following is the result, finding all TODO items in source trees and printing them out with some context:

#! /usr/bin/env python2.3

import sys, os

def walker(args, path, filenames):
    for filename in filenames:
        joined = os.path.join(path, filename)
        if os.path.isdir(joined):
            continue

        # find lines to display, at least 2 either side of a TODO marker
        lines = open(joined).readlines()
        display = {}
        for i, line in enumerate(lines):
            if 'TODO' not in line:
                continue
            for n in range(i-2, i+3):
                display[n] = 1
        if not display:
            continue

        # organise the lines to display
        display = [n for n in display.keys() if n >= 0 and n < len(lines)]
        display.sort()

        # print them
        print '**', joined
        last = None
        for n in display:
            if last is not None and n > last+1:
                print '---'
            last = n
            sys.stdout.write(lines[n])
        print '*'*75

if __name__=='__main__':
    for arg in sys.argv[1:]:
        os.path.walk(arg, walker, None)

Yes, I took the time to have a look at some new python 2.3 features too (see if you can spot them :)

Read: Listing TODO items in your source

Topic: Note on notes of EuroPython 2003 Previous Topic   Next Topic Topic: Simple FTP uploading with Python

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use