-
Notifications
You must be signed in to change notification settings - Fork 0
/
django-lines
executable file
·73 lines (57 loc) · 1.04 KB
/
django-lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
set -e
function error_exit {
rm -f *djangolines.tmp
}
usage() {
cat << EOF
Usage: django-lines [OPTIONS] <path>
COMMANDS:
--help, -h
Show this message
-p
Show only production code (excluding tests).
-t
Show only test code
EOF
}
trap error_exit ERR
if [[ $1 = "--help" ]] || [[ $1 = "-h" ]]; then
error_exit
usage
exit 0
fi
if [ $# -gt 0 ]; then
for dir; do true; done
else
dir=./
fi
if [ $dir = "-p" ]; then
dir=./
elif [ $dir = "-t" ]; then
dir=./
fi
file=temp_`date +%s`_djangolines.tmp
find $dir -type f |
egrep '.*\.(py|html|css|js)$' |
grep -wvG .*_old |
grep -wvG .*manage.py$ |
grep -wv 'migrations' > $file
newfile=newfile_`date +%s`_djangolines.tmp
cp $file $newfile
cat $newfile |
while getopts ":pt" opt; do
case $opt in
p)
egrep -v '.*tests.*$' > $file
;;
t)
grep -G tests > $file
;;
esac
done
cat $file |
grep -wv __init__ |
xargs wc -l
rm $file
rm $newfile