| 1 | #!cqperl |
| 2 | ################################################################################ |
| 3 | # |
| 4 | # File: CheckCodePage.pl |
| 5 | # Description: With Clearquest 2003.06.15 there is more support for |
| 6 | # internationalization. This means that Clearquest now |
| 7 | # implements a Code Page which essentially defines the |
| 8 | # valid character set for data. If it encounters invalid |
| 9 | # characters the user must correct them. |
| 10 | # |
| 11 | # This script will check a Clearquest database to see if |
| 12 | # there are any invalid ASCII characters in string oriented |
| 13 | # fields. |
| 14 | # Author: Andrew@DeFaria.com |
| 15 | # Created: Fri Sep 23 17:27:58 PDT 2005 |
| 16 | # Language: Perl |
| 17 | # |
| 18 | # (c) Copyright 2005, Andrew@DeFaria.com, all rights reserved |
| 19 | # |
| 20 | ################################################################################ |
| 21 | use strict; |
| 22 | use warnings; |
| 23 | use CQPerlExt; |
| 24 | use File::Spec; |
| 25 | |
| 26 | our ($me, $separator); |
| 27 | |
| 28 | my ($abs_path, $lib_path); |
| 29 | |
| 30 | BEGIN { |
| 31 | # Extract relative path and basename from script name. |
| 32 | $0 =~ /(.*)[\/\\](.*)/; |
| 33 | |
| 34 | $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1); |
| 35 | $me = (!defined $2) ? $0 : $2; |
| 36 | $me =~ s/\.pl$//; |
| 37 | |
| 38 | # Remove .pl for Perl scripts that have that extension |
| 39 | $me =~ s/\.pl$//; |
| 40 | |
| 41 | # Define the path separator |
| 42 | $separator = ($^O =~ /MSWin/) ? "\\" : "/"; |
| 43 | |
| 44 | # Setup paths |
| 45 | $lib_path = "$abs_path" . $separator . ".." . $separator . "lib"; |
| 46 | |
| 47 | # Add the appropriate path to our modules to @INC array. |
| 48 | unshift (@INC, "$abs_path"); |
| 49 | unshift (@INC, "$lib_path"); |
| 50 | } # BEGIN |
| 51 | |
| 52 | use PQA; |
| 53 | use Display; |
| 54 | use Logger; |
| 55 | use TimeUtils; |
| 56 | |
| 57 | my $from_db_connection_name = "Controller"; |
| 58 | |
| 59 | sub Usage { |
| 60 | my $msg = shift; |
| 61 | |
| 62 | display "ERROR: $msg\n" if defined $msg; |
| 63 | |
| 64 | display "Usage: $me\t[-u] [-v] [-d] [-from ] |
| 65 | |
| 66 | Where: |
| 67 | |
| 68 | -u: Display usage |
| 69 | -v: Turn on verbose mode |
| 70 | -d: Turn on debug mode |
| 71 | -from : Specify the from connection name |
| 72 | (Default: $from_db_connection_name)"; |
| 73 | exit 1; |
| 74 | } # Usage |
| 75 | |
| 76 | while ($ARGV [0]) { |
| 77 | if ($ARGV [0] eq "-v") { |
| 78 | Display::set_verbose; |
| 79 | Logger::set_verbose; |
| 80 | } elsif ($ARGV [0] eq "-d") { |
| 81 | set_debug; |
| 82 | } elsif ($ARGV [0] eq "-from") { |
| 83 | shift; |
| 84 | if (!$ARGV [0]) { |
| 85 | Usage "Must specify after -from"; |
| 86 | } else { |
| 87 | $from_db_connection_name = $ARGV [0]; |
| 88 | } # if |
| 89 | } elsif ($ARGV [0] eq "-u") { |
| 90 | Usage; |
| 91 | } else { |
| 92 | Usage "Unknown argument found: " . $ARGV [0]; |
| 93 | } # if |
| 94 | |
| 95 | shift (@ARGV); |
| 96 | } # while |
| 97 | |
| 98 | my $log = Logger->new (path => "."); |
| 99 | |
| 100 | my $process_start_time = time; |
| 101 | my $start_time; |
| 102 | |
| 103 | $log->msg ("Starting Cont session"); |
| 104 | my $session = StartSession ("Cont", $from_db_connection_name); |
| 105 | |
| 106 | $start_time = time; |
| 107 | |
| 108 | #$log->msg ("Checking customer record..."); |
| 109 | #CheckRecord $log, $session, "dbid", "customer", undef, @customer_fields; |
| 110 | |
| 111 | #$log->msg ("Checking project record..."); |
| 112 | #CheckRecord $log, $session, "dbid", "project", undef, @project_fields; |
| 113 | |
| 114 | $log->msg ("Checking defect record..."); |
| 115 | #CheckRecord $log, $session, "id", "defect", undef, @new_Cont_defect_fields; |
| 116 | CheckRecord $log, $session, "id", "defect", "Cont00022003", @new_Cont_defect_fields; |
| 117 | |
| 118 | $log->msg ("Ending Cont session..."); |
| 119 | EndSession $session; |
| 120 | |
| 121 | display_duration $start_time, $log; |
| 122 | |
| 123 | |
| 124 | $log->msg ("\nInvalid character analysis\n"); |
| 125 | |
| 126 | my $i = 0; |
| 127 | |
| 128 | foreach (sort (keys (%bad_chars))) { |
| 129 | $log->msg (++$i . "\t$_\t$bad_chars{$_}\n"); |
| 130 | } # foreach |
| 131 | |
| 132 | display_duration $process_start_time, $log; |