cc_checkedout 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #!/bin/ksh
  2. #
  3. # cc_checkedout
  4. #
  5. ########################################################################
  6. # set -x
  7. ##########################################################################
  8. #
  9. # Script setup: THIS NEEDS TO BE FIRST
  10. #
  11. SCRIPTS_DIR="`dirname $0`"
  12. PROG_NAME="`basename $0`"
  13. if [ "" = "$SCRIPTS_DIR" ]; then
  14. SCRIPTS_DIR=/project/dt/scripts
  15. fi
  16. if [ ! -f $SCRIPTS_DIR/script_setup.ksh ]; then
  17. print -u2 "$PROG_NAME: File '$SCRIPTS_DIR/script_setup.ksh' NOT found!"
  18. print -u2 "$PROG_NAME: Exiting ..."
  19. exit 1
  20. fi
  21. . $SCRIPTS_DIR/script_setup.ksh
  22. ##########################################################################
  23. #
  24. # Script specific global variables
  25. #
  26. COMPONENTS_FILES=""
  27. COMPONENTS=""
  28. DEBUG="False"
  29. DO_DELETE="True"
  30. DO_LISTING="True"
  31. DO_SUMMARY="True"
  32. DO_TMPFILE="True"
  33. HAVE_EVENTS="True"
  34. CHECKEDOUT_LOG=""
  35. LOG_PATH=""
  36. MAIL_LIST=""
  37. PROG_NAME="`basename $0`"
  38. WHAT_TO_SEARCH="-avobs"
  39. ##########################################################################
  40. #
  41. # FUNCTION: do_executive_summary ()
  42. #
  43. do_executive_summary ()
  44. {
  45. AWK_EXEC_CO_SUMMARY='{printf("%-40s [CheckedOut= %-3s; Users= ", $1,$2)}'
  46. AWK_EXEC_USER_SUMMARY='{printf("%s ", $1)}'
  47. AWK_EXEC_TERM_SUMMARY='{printf("]\n")}'
  48. COMPONENT=$1
  49. if [ "True" = "$DEBUG" ]; then
  50. print -u2 "summarizing events in $COMPONENT"
  51. fi
  52. TOTAL_CHECKEDOUT=`$EXTRACT_MSG -l $CHECKEDOUT_LOG $COMPONENT | wc -l |
  53. awk '{printf("%s",$1)}'`
  54. if [ $TOTAL_CHECKEDOUT -ne 0 ]; then
  55. USERS=`$EXTRACT_MSG -l $CHECKEDOUT_LOG $COMPONENT |
  56. awk '{ print $1 }' FS="::" | sort | uniq`
  57. echo "$COMPONENT $TOTAL_CHECKEDOUT" | awk "$AWK_EXEC_CO_SUMMARY"
  58. for u in $USERS
  59. do
  60. echo "$u" | awk "$AWK_EXEC_USER_SUMMARY"
  61. done
  62. echo "" | awk "$AWK_EXEC_TERM_SUMMARY"
  63. fi
  64. }
  65. ##########################################################################
  66. #
  67. # FUNCTION: usage ()
  68. #
  69. usage ()
  70. {
  71. cat <<eof
  72. USAGE: $PROG_NAME
  73. [-d | -debug] # Print output to stdout
  74. [-h | -? | -help] # Print usage and exit
  75. [{-l | -log_path} <file>] # Specifies the output file for the report.
  76. [{-m | -mail | -mail_list} <user_name(s)>]
  77. [{-t | -tmpfile} <file>] # Specifies the tmp file to be extracted from.
  78. [{-w | -what | -what_to_search} <option or directory>]
  79. # The default is: $WHAT_TO_SEARCH
  80. [-no_delete]
  81. [-no_listing]
  82. [-no_summary]
  83. # '$PROG_NAME' calls clearcase commands to determine which files
  84. # are currently checked out and then delivers the report. The
  85. # report can be sent to a list of mail recipients, or a log file
  86. # or both. If neither is specified, the report is sent to stdout
  87. # by default.
  88. eof
  89. }
  90. ######################################################################
  91. #
  92. # Exit if no view is set
  93. #
  94. $CLEAR_CASE_TOOL pwv | grep 'Set view' | grep NONE > /dev/null
  95. if [ $? -eq 0 ]; then
  96. print -u2 "$PROG_NAME: Exiting ... NO ClearCase view is set!"
  97. exit 1
  98. fi
  99. ##########################################################################
  100. #
  101. # Do command-line processing
  102. #
  103. while [ $# -gt 0 ]; do
  104. case $1 in
  105. -debug)
  106. DEBUG="True"
  107. shift 1 ;;
  108. -h | -? | -help)
  109. usage $PROG_NAME
  110. do_exit 1 ;;
  111. -l | -log_path)
  112. if [ $# -lt 2 ]; then
  113. print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
  114. do_exit 1
  115. fi
  116. LOG_PATH=$2
  117. shift 2 ;;
  118. -m | -mail | -mail_list)
  119. if [ $# -lt 2 ]; then
  120. print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
  121. do_exit 1
  122. fi
  123. MAIL_LIST=$2
  124. shift 2 ;;
  125. -t | -tmpfile)
  126. if [ $# -lt 2 ]; then
  127. print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
  128. do_exit 1
  129. fi
  130. DO_TMPFILE="false"
  131. CHECKEDOUT_LOG=$2
  132. shift 2 ;;
  133. -w | -what | -what_to_search)
  134. if [ $# -lt 2 ]; then
  135. print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
  136. do_exit 1
  137. fi
  138. WHAT_TO_SEARCH=$2
  139. shift 2 ;;
  140. -no_listing)
  141. DO_LISTING="False"
  142. shift 1 ;;
  143. -no_summary)
  144. DO_SUMMARY="False"
  145. shift 1 ;;
  146. -no_delete)
  147. DO_DELETE="False"
  148. shift 1 ;;
  149. *)
  150. usage $PROG_NAME
  151. do_exit 1 ;;
  152. esac
  153. done
  154. if [ "True" = "$DO_TMPFILE" ]; then
  155. CHECKEDOUT_LOG=/tmp/$PROG_NAME.checkedout.$$
  156. CHECKEDOUT_LOG_PRIME=/tmp/$PROG_NAME.checkedout.1.$$
  157. do_register_temporary_file $CHECKEDOUT_LOG
  158. do_register_temporary_file $CHECKEDOUT_LOG_PRIME
  159. #
  160. # First get the list of files
  161. #
  162. $CLEAR_CASE_TOOL lsco -fmt "%u %n %f\n" $WHAT_TO_SEARCH > $CHECKEDOUT_LOG
  163. #
  164. # Since it is possible for more than one person to have a
  165. # file checked-out must get all locks. Note that it also
  166. # desireable to get each user's comments attached to the
  167. # checkout.
  168. #
  169. cat $CHECKEDOUT_LOG | while read LINE; do
  170. FILE="`echo $LINE | awk '{printf "%s", $2}'`"
  171. $CLEAR_CASE_TOOL lsco -d -fmt "%u::%Ad::days::%Tf::(%Rf)::%n::%f\n" \
  172. $FILE >> $CHECKEDOUT_LOG_PRIME
  173. done
  174. #
  175. # Sort the files and remove dups.
  176. #
  177. sort $CHECKEDOUT_LOG_PRIME | uniq > $CHECKEDOUT_LOG
  178. cp $CHECKEDOUT_LOG $CHECKEDOUT_LOG_PRIME
  179. sed -e 's/\.cde-1/cde/
  180. s/\.cde-2/cde/
  181. s/\.cde-3/cde/
  182. s/\.cde-test-1/cde-test/
  183. s/\.cde-test-2/cde-test/
  184. s/\.cde-test-3/cde-test/
  185. s/\.motif-1/motif/
  186. s/\.motif-2/motif/' $CHECKEDOUT_LOG_PRIME > $CHECKEDOUT_LOG
  187. fi
  188. PROJECTS="cde cde-contrib cde-cts cde-misc cde-test cde-test-misc
  189. motif motif-cts motif-misc x11/misc x11/unsupported x11"
  190. #
  191. # Redirect output
  192. #
  193. if [ "$DEBUG" = "False" ]; then
  194. EXECUTIVE_SUMMARY_LOG=/tmp/$PROG_NAME.execsum.$$
  195. do_register_temporary_file $EXECUTIVE_SUMMARY_LOG
  196. touch $EXECUTIVE_SUMMARY_LOG
  197. exec 9>&1
  198. exec > $EXECUTIVE_SUMMARY_LOG
  199. fi
  200. DATE=`date "$BTAG_DFMT"`
  201. print -u1 " CLEARCASE CHECKEDOUT SUMMARY FOR: $DATE"
  202. print -u1 " ++++++++++++++++++++++++++++++++++++++++++++++++++++"
  203. print -u1
  204. print -u1
  205. if [ ! -s $CHECKEDOUT_LOG ]; then
  206. if [ "$DEBUG" = "True" ]; then
  207. print -u1 "Log file '$CHECKEDOUT_LOG' is empty"
  208. fi
  209. HAVE_EVENTS="False"
  210. print -u1 "NO events were found."
  211. fi
  212. if [ "True" = "$DO_SUMMARY" -a "True" = "$HAVE_EVENTS" ]; then
  213. for p in $PROJECTS
  214. do
  215. COMPONENTS_FILE=$SCRIPTS_DIR/$p.components
  216. if [ -f $COMPONENTS_FILE ]; then
  217. #
  218. # Correct for the missing 'xc' subdirectory in x11.components
  219. #
  220. if [ "$p" = "x11" ]; then
  221. p=x11/xc
  222. fi
  223. for c in `cat $COMPONENTS_FILE`
  224. do
  225. do_executive_summary /proj/$p/$c
  226. done
  227. else
  228. do_executive_summary /proj/$p
  229. fi
  230. done
  231. fi
  232. if [ "True" = "$DO_LISTING" -a "True" = "$HAVE_EVENTS" ]; then
  233. print -u1
  234. print -u1
  235. print -u1 " CLEARCASE CHECKEDOUT LISTING"
  236. print -u1 " ++++++++++++++++++++++++++++"
  237. print -u1
  238. print -u1
  239. cat $CHECKEDOUT_LOG | while read LINE; do
  240. USER="`echo $LINE | awk '{FS="::"; printf "%s", $1}'`"
  241. FILE="`echo $LINE | awk '{FS="::"; printf "%s", $6}'`"
  242. echo $LINE | \
  243. sed '/::1::days/s//::1:: day/' | \
  244. sed '/\(unreserved\)/s//U/' | \
  245. sed '/\(reserved\)/s//R/' | \
  246. awk '{ FS="::"; printf "%-8s %3d %s %s %s\n %s@@%s\n", $1,$2,$3,$4,$5,$6,$7 }'
  247. #
  248. # Attach the WIP if present
  249. #
  250. WIP="`$CLEAR_CASE_TOOL lsco -d -user $USER -fmt '%[WIP]a' $FILE`"
  251. if [ "" != "$WIP" ]; then
  252. print -u1 " $WIP"
  253. fi
  254. #
  255. # Attach the (possibly mult-line) comment
  256. #
  257. $CLEAR_CASE_TOOL lsco -d -user $USER -fmt "%c" $FILE \
  258. | awk '{printf " %s\n", $0}'
  259. done
  260. fi
  261. #####################################################################
  262. #
  263. # If no files were found, create a descriptive message; else
  264. # tack on a legend
  265. #
  266. if [ ! -s $CHECKEDOUT_LOG ]; then
  267. print -u1 "NO files are checked out!"
  268. else
  269. mv $CHECKEDOUT_LOG_PRIME $CHECKEDOUT_LOG
  270. print -u1 "\n(R) = reserved checkout"
  271. print -u1 "(U) = unreseved checkout"
  272. fi
  273. ##########################################################################
  274. #
  275. # Complete the build summary and deliver it
  276. #
  277. if [ "" != "$MAIL_LIST" ]; then
  278. mailx -s "$SUBJECT_CHECKOUTS (`date $SUBJECT_DATE`)" "$MAIL_LIST" < \
  279. $EXECUTIVE_SUMMARY_LOG
  280. fi
  281. if [ "" != "$LOG_PATH" ]; then
  282. cp $EXECUTIVE_SUMMARY_LOG $LOG_PATH
  283. fi
  284. if [ "$DEBUG" = "False" -a "" = "$MAIL_LIST" -a "" = "$LOG_PATH" ]; then
  285. exec >&9
  286. cat $EXECUTIVE_SUMMARY_LOG
  287. fi
  288. ##########################################################################
  289. #
  290. # Clean up temporary files and exit
  291. #
  292. if [ "True" = "$DO_DELETE" ]; then
  293. do_exit 0
  294. fi
  295. exit 0