Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / bin / files4lab
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         files4bug
5 # Description:  Displays the files related to a bug ID
6 # Author:       Andrew@DeFaria.com
7 # Created:      Wed Jun 11 13:22:11 PDT 2003
8 # Language:     Bash Shell
9 # Modifications:06/17/2003 AD: Changed 2310_onu -> onu2310 as the card directory
10 #               has changed. Also added -to and -cc options.
11 #
12 # (c) Copyright 2003, Andrew@DeFaria.com, all rights reserved
13 #
14 ################################################################################
15 # Set me to command name
16 me=$(basename $0)
17
18 # Set adm_base
19 adm_base="$SITE_TOOLS_PATH/adm"
20
21 # Set adm_fpath
22 adm_fpath="${adm_fpath:-$adm_base/functions}"
23
24 # Source functions
25 . "$adm_fpath/common"
26
27 function usage {
28   display "$me: [ -view <viewtag> ] <bugid> [<bugid>]"
29   display
30   display "Where:"
31   display
32   display "\t-view\tView path to use (default $SITE_OFFICIAL_VIEW)"
33   display "\t<bugid>\tBug ID(s) to search for"
34  
35   exit 1
36 } # usage
37
38 function cleanup {
39   debug "ENTER cleanup"
40   rm -f /tmp/$me.$$
41   debug "EXIT cleanup"
42   exit
43 } # cleanup
44
45 trap cleanup INT EXIT ERR
46
47 # Get parameters                                                                
48 view_path=""
49 bugs=""
50 while (($# > 0)); do
51   case "$1" in
52       -usage)
53         usage
54       ;;
55
56       -v|-verbose)
57         verbose=yes
58       ;;                                                                        
59
60       -d|-debug)
61         debug=yes
62       ;;                                                                        
63
64       -view)
65         shift
66         view_path="$1"
67       ;;
68
69       *)
70         bugs="$bugs $1"
71       ;;
72   esac
73   shift
74 done
75
76 if [ -z "$view_path" ]; then
77   vob="$SITE_SNAPSHOT_VIEW_PATH/$SITE_OFFICIAL_VIEW/salira"
78   view_name="$SITE_OFFICIAL_VIEW"
79 else
80   vob="$view_path/salira"
81 fi
82
83 cd $vob > /dev/null 2>&1
84
85 if (($? != 0)); then
86   error "Unable to cd to $vob" 1
87 fi
88
89 if [ -z "$view_name" ]; then
90   view_name=$(cleartool pwv -short)
91 fi
92
93 for bug in $bugs; do
94   # Check for bug IDs supplied as numbers only. Prepend "BUGS2" and 
95   # number of required zeros to make bug ID. IOW you can specify "7"
96   # or BUGS200000007 but not "BUGS07", etc
97   if ((${#bug} < 13)); then
98     declare -i len=13-${#bug}
99     if (($len < 5)); then
100       # Can't even prepend "BUGS2"!
101       display "Invalid bug id \"$bug\" encounterd - skipping..."
102       continue
103     else
104       bugid="BUGS2"
105       declare -i zeros=len-5
106       while (($zeros > 0)); do
107         bugid="${bugid}0"
108         ((zeros--))
109       done
110       newbug=$bugid$bug
111       declare -i nbr=${newbug:4}
112       declare str=${newbug:4}
113       if [ $nbr != $str ]; then
114         warning "Invalid bug ID encountered: $bug"
115         continue
116       fi
117       bug=$newbug
118     fi
119   fi
120
121   display "Files involved in bug ID $bug:"
122   cleartool find -all -version "lbtype($bug)" -print | tr "\\\\" "/" >/tmp/$me.$$
123
124   declare -i i=0
125
126   while read element_version; do
127     ((i++))
128     # Chop off leading view path
129     element_version=$(echo ${element_version##*$view_name})
130     # Extract element portion
131     element=$(echo $element_version | cut -f1 -d@)
132     # Extract version portion
133     version=$(echo $element_version | cut -f3 -d@)
134     display "\t$element\t$version"
135   done < /tmp/$me.$$
136
137   if (($i == 0)); then
138     display "No files involved in bug ID $bug"
139   elif [ $i -eq 1 ]; then
140     display "1 file involved in bug ID $bug"
141   else
142     display "$i files involved in bug ID $bug"
143   fi
144 done 
145
146 cleanup