tags:

views:

198

answers:

5

Is there an easy way to count the lines of code you have written for your django project?

Edit: The shell stuff is cool, but how about on Windows?

+2  A: 

Yep:

shell]$ find /my/source -name "*.py" -type f -exec cat {} + | wc -l

Job's a good 'un.

Aiden Bell
+1  A: 

Check out the wc command on unix.

Dan Lorenc
+2  A: 

Starting with Aiden's answer, and with a bit of help in a question of my own, I ended up with this god-awful mess:

# find the combined LOC of files
# usage: loc Documents/fourU py html
function loc {
    #find $1 -name $2 -type f -exec cat {} + | wc -l
    namelist=''
    let i=2
    while [ $i -le $# ]; do
     namelist="$namelist -name \"*.$@[$i]\""
     if [ $i != $# ]; then
      namelist="$namelist -or "
     fi
     let i=i+1
    done
    #echo $namelist
    #echo "find $1 $namelist" | sh
    #echo "find $1 $namelist" | sh | xargs cat
    echo "find $1 $namelist" | sh | xargs cat | wc -l
}

which allows you to specify any number of extensions you want to match. As far as I can tell, it outputs the right answer, but... I thought this would be a one-liner, else I wouldn't have started in bash, and it just kinda grew from there.

I'm sure that those more knowledgable than I can improve upon this, so I'm going to put it in community wiki.

Xiong Chiamiov
loc() { D=$1; shift echo "$@" | xargs -n 1 echo | sed 's,^, -or -name *.,' | xargs find $D -type f | xargs cat | wc -l}
rzab
Alright, oneliner: echo py html | xargs -n 1 echo | sed 's,^, -or -name *.,' | xargs find Documents -type f | xargs cat | wc -l
rzab
Ah, I didn't even think about shift! As I said, this answer is in community wiki, so you can edit it directly... if not, I might get around to fixing it later.
Xiong Chiamiov
A: 

Get wc command on Windows using GnuWin32 (http://gnuwin32.sourceforge.net/packages/coreutils.htm)

wc *.py

sharjeel
+2  A: 

You might want to look at CLOC -- it's not Django specific but it supports Python. It can show you lines counts for actual code, comments, blank lines, etc.

Steve Losh