Count lines of code in a Django Project

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?


Yep:

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

Job's a good 'un.


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.


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.

链接地址: http://www.djcxy.com/p/47254.html

上一篇: 如何只用linux`find`来获取文件名?

下一篇: 在Django项目中对代码行进行计数