Friday, February 23, 2007

Statistics on Python code in a project

I wanted to know the number of lines of python code in my toy django project, and could not find a nice tool that would give me that on linux. "find . -name "*.py" |wc -l doesn't do the job. As lazy as I am, I wrote a crude linecount program in python. The result is lc.py.
The program takes the directory as an optional arg (defaults to current dir), finds all python programs and prints the number of lines, comments, docstrings, blank lines, classes and methods.And yes, it ignores .svn folders. :)
By no means it is tested well for its correctness, neither does it use exotic grammar parser techniques to accurately calculate the data. So, its only an approximation and slow at times.
Download it here

Labels: ,

Thursday, February 22, 2007

Fiddling with Django

Its been a few weeks playing with Django trunk. And a two more weeks than that, with Python. Initially, I was getting annoyed with the 'self'ishness of python. But got used to it. Python is refreshingly more powerful than Ruby,the only other dynamic language I know, IMHO. I won't go in to details of how, as this post is about Django.
These are a few things I've started liking about Django:
  • Database is driven by model classes, not the other way
  • The admin application(a.k.a CRUD on steroids) for free
  • Reasonably good template infrastructure
  • Reasonably good testing infrastructure (the client class)
And some I don't like:
  • No support for incremental model changes (syncdb cannot update existing tables!)
  • No fixtures yet(okay, i don't want to write SQL scripts for fixtures now)
The 'don't likes' come from my experience with Rails
Also, I played a bit with django.contrib.search and PyLucene.
django.contrib.search did not work out of the box, and I had to tweak it a bit. It did not support traversing Many-to-many relations for indexing and I added some crude support for that as well. I will publish the tweaks after adding full-fledged support for traversing relationships.


Labels: , , , , ,