Removed /usr/local from CDPATH
[clearscm.git] / cq / check_attachments
1 #!cqperl
2 use strict;
3 use warnings;
4 use CQPerlExt;
5 use File::Spec;
6
7 our ($me, $SEPARATOR);
8
9 my ($abs_path, $lib_path);
10
11 BEGIN {
12   # Extract relative path and basename from script name.
13   $0 =~ /(.*)[\/\\](.*)/;
14
15   $abs_path   = (!defined $1) ? "." : File::Spec->rel2abs ($1);
16   $me         = (!defined $2) ? $0  : $2;
17   $me         =~ s/\.pl$//;
18
19   # Define the path SEPARATOR
20   $SEPARATOR  = ($^O =~ /MSWin/) ? "\\" : "/";
21
22   # Setup paths
23   $lib_path   = "$abs_path" . $SEPARATOR . ".." . $SEPARATOR . "lib";
24
25   # Add the appropriate path to our modules to @INC array.
26   unshift (@INC, "$abs_path");
27   unshift (@INC, "$lib_path");
28 } # BEGIN
29
30 use PQA;
31 use Display;
32
33 sub TotalAttachment {
34   my $log       = shift;
35   my $id        = shift;
36   my $from      = shift;
37
38   my $attachments_size = 0;
39
40   my $from_attachment_fields    = $from->GetAttachmentFields;
41
42   for (my $i = 0; $i < $from_attachment_fields->Count; $i++) {
43     my $from_attachment_field   = $from_attachment_fields->Item ($i);
44     my $field_name              = $from_attachment_field->GetFieldName;
45
46     # Process attachments in this attachment field
47     my $from_attachments        = $from_attachment_field->GetAttachments;
48
49     for (my $j = 0; $j < $from_attachments->Count; $j++) {
50       my $from_attachment       = $from_attachments->Item ($j);
51       my $description           = $from_attachment->GetDescription;
52       my $filename              = $from_attachment->GetFileName;
53       my $size                  = $from_attachment->GetFileSize;
54
55       next if $filename eq "history.txt";
56       $log->msg ("$id,$filename,$size");
57       $attachments_size += $size;
58     } # for
59   } # for
60
61   $log->msg ("$id,Total attachment size,$attachments_size") if $attachments_size ne 0;
62
63   return $attachments_size;
64 } # TotalAttachment
65
66 my $log         = Logger->new (path => ".");
67
68 # Open databases
69 my $record_name = "defect";
70
71 my $connection  = "2005.02.00";
72 my $cont        = StartSession "Cont", $connection;
73
74 $connection     = "2003.06.00";
75 my $teton       = StartSession "TO", $connection;
76 my $prod        = StartSession "Prod", $connection;
77
78 my $result = GetAllDefectRecords $log, $cont, $record_name;
79
80 my $grand_total_old = 0;
81 my $grand_total_new = 0;
82
83 while ($result->MoveNext == $CQPerlExt::CQ_SUCCESS) {
84   # GetEntity by using $id
85   my $id        = $result->GetColumnValue (1);
86   my $from      = $cont->GetEntity ($record_name, $id);
87
88   my $new_size  = TotalAttachment $log, $id, $from;
89
90   my $old_id    = $from->GetFieldValue ("old_id")->GetValue;
91
92   my $to;
93
94   if ($old_id =~ /^TO/) {
95     $to = $teton->GetEntity ($record_name, $old_id);
96   } elsif ($old_id =~ /^Prod/) {
97     $to = $prod->GetEntity ($record_name, $old_id);
98   } else {
99     error "Old_id is not set! $old_id";
100   } # if
101
102   my $old_size  = TotalAttachment $log, $id, $to;
103
104   $grand_total_old += $old_size;
105   $grand_total_new += $new_size;
106
107   if ($new_size gt $old_size) {
108     display "$id:$new_size > $old_id:$old_size";
109   } elsif ($new_size lt $old_size) {
110     display "$id:$new_size < $old_id:$old_size";
111 #  } else {
112 #    display "$id:$new_size = $old_id:$old_size";
113   } # if
114
115 } # while
116
117 display "Grand total (old): $grand_total_old";
118 display "Grand total (new): $grand_total_new";
119
120 EndSession $cont;
121 EndSession $teton;
122 EndSession $prod;