#!/usr/bin/perl ################################################################################ # # File: cqc: Clearquest client # Description: This script is a test client for cqd. # Author: Andrew@DeFaria.com # Created: Fri May 31 15:34:50 2002 # Modified: # Language: Perl # # (c) Copyright 2002, Salira Optical Network Systems, all rights reserved. # ################################################################################ use strict; BEGIN { # Add the appropriate path to our modules to @INC array. We use ipconfig to # get the current host's IP address then determine whether we are in the US # or China. my @ipconfig = grep (/IP Address/, `ipconfig`); my ($ipaddr) = ($ipconfig[0] =~ /(\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/); # US is in the subnets of 192 and 172 while China is in the subnet of 10 if ($ipaddr =~ /^192|^172/) { unshift (@INC, "//sons-clearcase/Views/official/Tools/lib"); } elsif ($ipaddr =~ /^10/) { unshift (@INC, "//sons-cc/Views/official/Tools/lib"); } else { die "Internal Error: Unable to find our modules!\n" } # if } # BEGIN use cqc; %cqc::fields; $cqc::command; my $len; my $key; my $value; my $servername = $ENV {CQDSERVER}; my $bugid; my @query_fields; my $result; sub Usage { print "Usage: cqc [ -s servername ] bugid [ fieldname... ]\n"; exit 1; } # Usage $bugid = ""; @query_fields = (); sub GetParms { my $i = 0; if ($ARGV [0] && $ARGV [0] eq "-s") { shift (@ARGV); if (!$ARGV [0]) { Usage; } else { $servername = shift (@ARGV); } # if } # if if ($ARGV [0]) { $bugid = shift (@ARGV); } # if @query_fields = @ARGV; # Downshift any query_fields foreach (@query_fields) { $query_fields [$i++] = lc $_; } # foreach } # GetParms sub fix_bugid { my $bugid = shift; if ($bugid =~ /^\d+$/) { if (length ($bugid) < 13) { $len = 13 - length ($bugid); if ($len < 5) { # Can't even prepend "BUGS2"! print "Invalid bug id \"$bugid\" encountered!\n"; exit 1; } else { $bugid = "BUGS2" . "0" x ($len - 5) . $bugid; } # if } # if } # if return $bugid; } # fix_bugid # Main code GetParms; if (defined ($servername)) { die "Unable to connect to $servername\n" if cqc::Connect ($servername) < 0; } # if if ($bugid) { $result = cqc::GetBugRecord (fix_bugid ($bugid), %fields); die "Unable to connect to server\n" if $result < 0; if ($result) { print "Bug ID $bugid was not found\n"; } else { if (@query_fields) { foreach (@query_fields) { if (@query_fields > 1) { print "$_: $cqc::fields{$_}\n"; } else { print "$cqc::fields{$_}\n"; } # if } # foreach } else { while (($key, $value) = each (%fields)) { $value =~ s/\r/\r\n/g; print "$key: $value\n"; } # while } # if } # if } else { print "Enter bug ID:"; while ($command = ) { chomp $command; last if $command =~ m/exit|quit|shutdown/; $bugid = fix_bugid ($command); $result = cqc::GetBugRecord ($bugid, %fields); die "Unable to connect to server\n" if $result < 0; if ($result) { print "Bug ID $bugid was not found\n"; } else { while (($key, $value) = each (%fields)) { $value =~ s/\r/\r\n/g; print "$key: $value\n"; } # while } # if print "Enter bug ID:"; } # while } # if