| 1 | #!/usr/bin/perl |
| 2 | ################################################################################ |
| 3 | # |
| 4 | # File: cqc,v |
| 5 | # Revision: 1.1.1.1 |
| 6 | # Description: This script is a test client for cqd. |
| 7 | # Author: Andrew@DeFaria.com |
| 8 | # Created: Fri May 31 15:34:50 2002 |
| 9 | # Modified: 2007/05/17 07:45:48 |
| 10 | # Language: Perl |
| 11 | # |
| 12 | # (c) Copyright 2007, ClearSCM, Inc. , all rights reserved. |
| 13 | # |
| 14 | ################################################################################ |
| 15 | use strict; |
| 16 | |
| 17 | BEGIN { |
| 18 | # Add the appropriate path to our modules to @INC array. We use ipconfig to |
| 19 | # get the current host's IP address then determine whether we are in the US |
| 20 | # or China. |
| 21 | my @ipconfig = grep (/IP Address/, `ipconfig`); |
| 22 | my ($ipaddr) = ($ipconfig[0] =~ /(\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/); |
| 23 | |
| 24 | # US is in the subnets of 192 and 172 while China is in the subnet of 10 |
| 25 | if ($ipaddr =~ /^192|^172/) { |
| 26 | unshift (@INC, "//sons-clearcase/Views/official/Tools/lib"); |
| 27 | } elsif ($ipaddr =~ /^10/) { |
| 28 | unshift (@INC, "//sons-cc/Views/official/Tools/lib"); |
| 29 | } else { |
| 30 | die "Internal Error: Unable to find our modules!\n" |
| 31 | } # if |
| 32 | } # BEGIN |
| 33 | |
| 34 | use cqc; |
| 35 | |
| 36 | %cqc::fields; |
| 37 | $cqc::command; |
| 38 | |
| 39 | my $len; |
| 40 | my $key; |
| 41 | my $value; |
| 42 | my $servername = $ENV {CQDSERVER}; |
| 43 | my $bugid; |
| 44 | my @query_fields; |
| 45 | my $result; |
| 46 | |
| 47 | sub Usage { |
| 48 | print "Usage: cqc [ -s servername ] bugid [ fieldname... ]\n"; |
| 49 | exit 1; |
| 50 | } # Usage |
| 51 | |
| 52 | $bugid = ""; |
| 53 | @query_fields = (); |
| 54 | |
| 55 | sub GetParms { |
| 56 | my $i = 0; |
| 57 | |
| 58 | if ($ARGV [0] && $ARGV [0] eq "-s") { |
| 59 | shift (@ARGV); |
| 60 | if (!$ARGV [0]) { |
| 61 | Usage; |
| 62 | } else { |
| 63 | $servername = shift (@ARGV); |
| 64 | } # if |
| 65 | } # if |
| 66 | |
| 67 | if ($ARGV [0]) { |
| 68 | $bugid = shift (@ARGV); |
| 69 | } # if |
| 70 | |
| 71 | @query_fields = @ARGV; |
| 72 | |
| 73 | # Downshift any query_fields |
| 74 | foreach (@query_fields) { |
| 75 | $query_fields [$i++] = lc $_; |
| 76 | } # foreach |
| 77 | } # GetParms |
| 78 | |
| 79 | sub fix_bugid { |
| 80 | my $bugid = shift; |
| 81 | |
| 82 | if ($bugid =~ /^\d+$/) { |
| 83 | if (length ($bugid) < 13) { |
| 84 | $len = 13 - length ($bugid); |
| 85 | if ($len < 5) { |
| 86 | # Can't even prepend "BUGS2"! |
| 87 | print "Invalid bug id \"$bugid\" encountered!\n"; |
| 88 | exit 1; |
| 89 | } else { |
| 90 | $bugid = "BUGS2" . "0" x ($len - 5) . $bugid; |
| 91 | } # if |
| 92 | } # if |
| 93 | } # if |
| 94 | |
| 95 | return $bugid; |
| 96 | } # fix_bugid |
| 97 | |
| 98 | # Main code |
| 99 | GetParms; |
| 100 | |
| 101 | if (defined ($servername)) { |
| 102 | die "Unable to connect to $servername\n" if cqc::Connect ($servername) < 0; |
| 103 | } # if |
| 104 | |
| 105 | if ($bugid) { |
| 106 | $result = cqc::GetBugRecord (fix_bugid ($bugid), %fields); |
| 107 | die "Unable to connect to server\n" if $result < 0; |
| 108 | if ($result) { |
| 109 | print "Bug ID $bugid was not found\n"; |
| 110 | } else { |
| 111 | if (@query_fields) { |
| 112 | foreach (@query_fields) { |
| 113 | if (@query_fields > 1) { |
| 114 | print "$_: $cqc::fields{$_}\n"; |
| 115 | } else { |
| 116 | print "$cqc::fields{$_}\n"; |
| 117 | } # if |
| 118 | } # foreach |
| 119 | } else { |
| 120 | while (($key, $value) = each (%fields)) { |
| 121 | $value =~ s/\r/\r\n/g; |
| 122 | print "$key: $value\n"; |
| 123 | } # while |
| 124 | } # if |
| 125 | } # if |
| 126 | } else { |
| 127 | print "Enter bug ID:"; |
| 128 | |
| 129 | while ($command = ) { |
| 130 | chomp $command; |
| 131 | last if $command =~ m/exit|quit|shutdown/; |
| 132 | |
| 133 | $bugid = fix_bugid ($command); |
| 134 | $result = cqc::GetBugRecord ($bugid, %fields); |
| 135 | die "Unable to connect to server\n" if $result < 0; |
| 136 | if ($result) { |
| 137 | print "Bug ID $bugid was not found\n"; |
| 138 | } else { |
| 139 | while (($key, $value) = each (%fields)) { |
| 140 | $value =~ s/\r/\r\n/g; |
| 141 | print "$key: $value\n"; |
| 142 | } # while |
| 143 | } # if |
| 144 | |
| 145 | print "Enter bug ID:"; |
| 146 | } # while |
| 147 | } # if |