getStatistics.sh
Go to the documentation of this file.
1 #!/usr/bin/env bash
2 
3 # Usage function
4 function usage() {
5  echo "$(basename $0) [-h] -t <modules|authors|code|this_year> <directory list>"
6  echo " search the listed directories for information"
7 }
8 
9 # Determine command options (just -h for help)
10 while getopts "h:t:" OPTION
11 do
12  case $OPTION in
13  h ) usage ; exit 0 ;;
14  t ) type=$OPTARG ;;
15  * ) echo "ERROR: Unknown option" ; usage ; exit 1 ;;
16  esac
17 done
18 shift $((OPTIND - 1))
19 
20 
21 if [ -z "${type}" ]
22 then
23  echo 'ERROR: no type specified'
24  usage
25  exit 1
26 fi
27 
28 # can we find the code?
29 if [ $# -lt 1 ]; then
30  echo "ERROR: Please specify a list of directories"
31  usage
32  exit 1
33 fi
34 directory_list=$@
35 for REP in ${directory_list}
36 do
37  if [ ! -d ${REP} ]; then
38  echo "ERROR: ${REP} is not a directory"
39  exit 1
40  fi
41  if [ ! -d ${REP}/.git ]; then
42  echo "ERROR: cannot find ${REP}/.git"
43  echo "ERROR: ${REP} must be the top of a git repository"
44  exit 1
45  fi
46  ##echo "will search ${REP} for ${type}"
47 done
48 
49 # now get the info
50 thisdir=`pwd`
51 ##echo "we are here: ${thisdir}"
52 if [ "${type}" = "modules" ]; then
53  for REP in ${directory_list}; do
54  listm=`find ${REP} -name "*_*.cc" | grep -v test`
55  module_list=`echo ${module_list} ${listm}`
56  done
57  num_mod=`echo ${module_list} | wc -w`
58  ##echo ${module_list}
59  echo "found ${num_mod} modules"
60 elif [ "${type}" = "authors" ]; then
61  for REP in ${directory_list}; do
62  cd ${REP}
63  lista=`git log --all --format='"%cN"' | sort -u`
64  author_list=`echo ${author_list} ${lista}`
65  cd ${thisdir}
66  echo "${lista}"
67  done
68  ##echo ${author_list}
69 elif [ "${type}" = "code" ]; then
70  if [[ `type cloc` ]]; then
71  echo "lines of code excluding fcl files and anything in the ups directory"
72  cloc --exclude-dir=ups ${directory_list}
73  else
74  echo "ERROR: cannot find the cloc utilitiy"
75  exit 1
76  fi
77 elif [ "${type}" = "this_year" ]; then
78  for REP in ${directory_list}; do
79  cd ${REP}
80  listy=`git log --pretty='' --numstat --since 1.year origin/master | grep -v '-' | grep -v ups | cut -f 1 | paste -sd+ - | bc`
81  cd ${thisdir}
82  echo "${REP}: ${listy} lines changed in the last year"
83  done
84 else
85  echo "ERROR: unrecognized type ${type}"
86 fi
87 
88 exit 0