| 227 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# CLASS ClearCase::IgnoreList
|
|
|
3 |
# Class holding files to ignore for CC, reads file from GBE_TOOLS, HOME & pwd
|
|
|
4 |
# This is a singleton class that stores data in an Eponymous hash and as the
|
|
|
5 |
# constructor does not bless self it always refers to the classname which is
|
|
|
6 |
# the same name as the hash ( which is why its an Eponymous Hash)
|
|
|
7 |
###############################################################################
|
|
|
8 |
|
|
|
9 |
package Clearcase::IgnoreList;
|
|
|
10 |
|
|
|
11 |
use strict;
|
|
|
12 |
use DeployUtils::Logger;
|
|
|
13 |
|
|
|
14 |
our %IgnoreList = ( );
|
|
|
15 |
|
|
|
16 |
#==============================================================================
|
|
|
17 |
# new
|
|
|
18 |
#==============================================================================
|
|
|
19 |
sub new
|
|
|
20 |
{
|
|
|
21 |
my $self = shift;
|
|
|
22 |
my $ignoreFile = ".ccignore";
|
|
|
23 |
|
|
|
24 |
#
|
|
|
25 |
# This routine assumes that there exists a file called .ccignore
|
|
|
26 |
# in the same directory as this package. The trick is to determine
|
|
|
27 |
# that directory. This can be discovered from __FILE__.
|
|
|
28 |
# __FILE__ should be an an absolute path, but it may not be.
|
|
|
29 |
# It depends on the PERL5LIB element used to locate the module
|
|
|
30 |
#
|
|
|
31 |
#
|
|
|
32 |
(my $this_dir = __FILE__ ) =~ s~/[^/]*$~~;
|
|
|
33 |
LogDebug("ClearCase::IgnoreList::new Use .ccignore in $this_dir");
|
|
|
34 |
unless ( -f "$this_dir/$ignoreFile" )
|
|
|
35 |
{
|
|
|
36 |
LogError('-x',"ClearCase::IgnoreList::new Local $ignoreFile not found");
|
|
|
37 |
LogError("ClearCase::IgnoreList::new FNF: $this_dir/$ignoreFile");
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
my @lookupDirs = ( $this_dir, $ENV{HOME}, "." );
|
|
|
41 |
my $classobj = $self->_classobj();
|
|
|
42 |
|
|
|
43 |
$classobj->{FILELIST} = [ ];
|
|
|
44 |
|
|
|
45 |
#always ignore .ccignore file if found
|
|
|
46 |
push(@{$classobj->{FILELIST}}, qr|/\.ccignore$|);
|
|
|
47 |
|
|
|
48 |
foreach my $dir ( @lookupDirs )
|
|
|
49 |
{
|
|
|
50 |
if ( -f "$dir/$ignoreFile" )
|
|
|
51 |
{
|
|
|
52 |
LogDebug("ClearCase::IgnoreList::new Processing $dir/$ignoreFile");
|
|
|
53 |
$self->_readFile("$dir/$ignoreFile");
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
} # new
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
#==============================================================================
|
|
|
60 |
# _classobj returns a hard reference to class object ( The Eponymous Hash )
|
|
|
61 |
#==============================================================================
|
|
|
62 |
sub _classobj
|
|
|
63 |
{
|
|
|
64 |
my $self = shift;
|
|
|
65 |
no strict "refs";
|
|
|
66 |
return \%$self;
|
|
|
67 |
} # _classobj
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
#==============================================================================
|
|
|
71 |
# _readFile
|
|
|
72 |
#==============================================================================
|
|
|
73 |
sub _readFile
|
|
|
74 |
{
|
|
|
75 |
my $self = shift;
|
|
|
76 |
my $file = shift;
|
|
|
77 |
my $classobj = $self->_classobj();
|
|
|
78 |
|
|
|
79 |
open(IGFILE, "<$file") || LogError("ClearCase::IgnoreList::_readFile Cannot open $file for reading");
|
|
|
80 |
|
|
|
81 |
while ( <IGFILE> )
|
|
|
82 |
{
|
|
|
83 |
chomp;
|
|
|
84 |
|
|
|
85 |
# skip empty lines or comments
|
|
|
86 |
next if ( /^ *$/ || /^#/ );
|
|
|
87 |
|
|
|
88 |
push( @{$classobj->{FILELIST}}, qr|$_| );
|
|
|
89 |
LogDebug("ClearCase::IgnoreList::_readFile Added item RE $classobj->{FILELIST}[$#{$classobj->{FILELIST}}] to ignore list");
|
|
|
90 |
}
|
|
|
91 |
} # _readFile
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
#==============================================================================
|
|
|
95 |
# ignoreFile returns 1(TRUE) if file is to be ignored
|
|
|
96 |
#==============================================================================
|
|
|
97 |
sub ignoreFile
|
|
|
98 |
{
|
|
|
99 |
my $self = shift;
|
|
|
100 |
my $fullPath = shift;
|
|
|
101 |
my $fixedPath = $fullPath;
|
|
|
102 |
my $classobj = $self->_classobj();
|
|
|
103 |
|
|
|
104 |
$fixedPath =~ s|\\|/|g;
|
|
|
105 |
|
|
|
106 |
for ( my $i = 0; $i <= $#{$classobj->{FILELIST}}; $i++ )
|
|
|
107 |
{
|
|
|
108 |
if ( $fixedPath =~ m|$classobj->{FILELIST}[$i]| )
|
|
|
109 |
{
|
|
|
110 |
LogDebug("ClearCase::IgnoreList::ignoreFile Ignoring $fixedPath");
|
|
|
111 |
return (1);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
return (0);
|
|
|
116 |
} # ignoreFile
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
#==============================================================================
|
|
|
120 |
# printIgnoreList prints the list of files to ignore, used for debugging
|
|
|
121 |
#==============================================================================
|
|
|
122 |
sub printIgnoreList
|
|
|
123 |
{
|
|
|
124 |
my $self = shift;
|
|
|
125 |
my $classobj = $self->_classobj();
|
|
|
126 |
|
|
|
127 |
# lets dump hash if logging is debug
|
|
|
128 |
if ( getLogLevel() == $LOG_LEVEL_DEBUG )
|
|
|
129 |
{
|
|
|
130 |
for my $file ( sort keys(%{$classobj->{FILELIST}}) )
|
|
|
131 |
{
|
|
|
132 |
LogDebug("ClearCase::IgnoreList::printIgnoreList contains $file");
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
} # printIgnoreList
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
# now we create the class singleton before we do anything else
|
|
|
139 |
__PACKAGE__->new();
|
|
|
140 |
|
|
|
141 |
1;
|