| 7323 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
|
|
|
3 |
#
|
|
|
4 |
# Module name : jats_ignore.pl
|
|
|
5 |
# Module type : JATS Utility
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Utility to:
|
|
|
10 |
# 1) Parse the .jatsignore file
|
|
|
11 |
# Sanity test it
|
|
|
12 |
# 2) Display those files and folder ignored by it
|
|
|
13 |
# 3) Zero the ignored files
|
|
|
14 |
# For use by LXR
|
|
|
15 |
# 4) Generate sutable information for the 'cloc' utility used by
|
|
|
16 |
# jats metrics
|
|
|
17 |
#
|
|
|
18 |
# This is simply a wrapper around a Perl Module
|
|
|
19 |
# Implement the body in a perl module so that we can use it from
|
|
|
20 |
# within jats_metrics
|
|
|
21 |
#
|
|
|
22 |
# Usage : See POD at the end of this file
|
|
|
23 |
#
|
|
|
24 |
#......................................................................#
|
|
|
25 |
|
|
|
26 |
require 5.008_002;
|
|
|
27 |
use strict;
|
|
|
28 |
use warnings;
|
|
|
29 |
|
|
|
30 |
use Pod::Usage;
|
|
|
31 |
use Getopt::Long;
|
|
|
32 |
|
|
|
33 |
use JatsError;
|
|
|
34 |
use JatsIgnore;
|
|
|
35 |
|
|
|
36 |
################################################################################
|
|
|
37 |
# Option variables
|
|
|
38 |
#
|
|
|
39 |
my $VERSION = "1.0.0"; # Update this
|
|
|
40 |
my $opt_verbose = 0;
|
|
|
41 |
my $opt_debug = 0;
|
|
|
42 |
my $opt_help = 0;
|
|
|
43 |
my $opt_test;
|
|
|
44 |
my $opt_file;
|
|
|
45 |
my $opt_text;
|
|
|
46 |
my $opt_examine;
|
|
|
47 |
|
|
|
48 |
#
|
|
|
49 |
# Option parsing
|
|
|
50 |
#
|
|
|
51 |
my $result = GetOptions (
|
|
|
52 |
"help|h:+" => \$opt_help,
|
|
|
53 |
"manual:3" => \$opt_help,
|
|
|
54 |
"verbose|v:+" => \$opt_verbose,
|
|
|
55 |
"debug:+" => \$opt_debug,
|
|
|
56 |
"examine:s" => \$opt_examine,
|
|
|
57 |
"test" => \$opt_test,
|
|
|
58 |
"file:s" => \$opt_file,
|
|
|
59 |
"text:s" => \$opt_text,
|
|
|
60 |
);
|
|
|
61 |
|
|
|
62 |
#
|
|
|
63 |
# Process help and manual options
|
|
|
64 |
#
|
|
|
65 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
66 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
67 |
pod2usage(-verbose => 2) if ($opt_help > 2);
|
|
|
68 |
|
|
|
69 |
#
|
|
|
70 |
# Configure the error reporting process now that we have the user options
|
|
|
71 |
#
|
|
|
72 |
ErrorConfig( 'name' =>'IGNORE_BASE',
|
|
|
73 |
'verbose' => $opt_verbose,
|
|
|
74 |
'debug' => $opt_debug
|
|
|
75 |
);
|
|
|
76 |
|
|
|
77 |
#
|
|
|
78 |
# Sanity test the user arguemnts
|
|
|
79 |
#
|
|
|
80 |
Error ("Too many command line arguments: @ARGV" )
|
|
|
81 |
if ( $#ARGV >= 0 );
|
|
|
82 |
#Error ("No file specified") unless defined $opt_file;
|
|
|
83 |
#Error ("File not found: $opt_file") unless -f $opt_file;
|
|
|
84 |
|
|
|
85 |
#
|
|
|
86 |
# Invoke required operations
|
|
|
87 |
#
|
|
|
88 |
if ($opt_test)
|
|
|
89 |
{
|
|
|
90 |
JatsIgnore::Test();
|
|
|
91 |
# JatsIgnore::ReadFilters($opt_file);
|
|
|
92 |
JatsIgnore::TestFile($opt_text) if defined $opt_text && -f $opt_text;
|
|
|
93 |
Message("All done");
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
#
|
|
|
97 |
# Examine a path and report results
|
|
|
98 |
#
|
|
|
99 |
if ($opt_examine)
|
|
|
100 |
{
|
|
|
101 |
Error ("No file specified") unless defined $opt_file;
|
|
|
102 |
Error ("Path is not a directory") unless -d $opt_examine;
|
|
|
103 |
|
|
|
104 |
JatsIgnore::ReadFilters($opt_file);
|
|
|
105 |
JatsIgnore::AddFilter('*.zip', 'deskpkg', '*.pdf', '.git/**', '.svn/**');
|
|
|
106 |
JatsIgnore::ScanDir($opt_examine, \&ShowScanData);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
sub ShowScanData
|
|
|
110 |
{
|
|
|
111 |
my ($rv, $absPath) = @_;
|
|
|
112 |
print("$rv : $absPath\n");
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
#-------------------------------------------------------------------------------
|
|
|
118 |
# Documentation
|
|
|
119 |
#
|
|
|
120 |
|
|
|
121 |
=pod
|
|
|
122 |
|
|
|
123 |
=for htmltoc SYSUTIL::
|
|
|
124 |
|
|
|
125 |
=head1 NAME
|
|
|
126 |
|
|
|
127 |
jats_ignore - Test and use the .jatsignore file
|
|
|
128 |
|
|
|
129 |
=head1 SYNOPSIS
|
|
|
130 |
|
|
|
131 |
jats etool jats_ignore [options]
|
|
|
132 |
|
|
|
133 |
Options:
|
|
|
134 |
-help - brief help message
|
|
|
135 |
-help -help - Detailed help message
|
|
|
136 |
-man - Full documentation
|
|
|
137 |
-verbose[=n] - Verbose operation
|
|
|
138 |
|
|
|
139 |
=head1 OPTIONS
|
|
|
140 |
|
|
|
141 |
=over 8
|
|
|
142 |
|
|
|
143 |
=item B<-help>
|
|
|
144 |
|
|
|
145 |
Print a brief help message and exits.
|
|
|
146 |
|
|
|
147 |
=item B<-help -help>
|
|
|
148 |
|
|
|
149 |
Print a detailed help message with an explanation for each option.
|
|
|
150 |
|
|
|
151 |
=item B<-man>
|
|
|
152 |
|
|
|
153 |
Prints the manual page and exits.
|
|
|
154 |
|
|
|
155 |
=item B<-verbose[=n]>
|
|
|
156 |
|
|
|
157 |
This option will increase the level of verbosity of the command.
|
|
|
158 |
|
|
|
159 |
If an argument is provided, then it will be used to set the level, otherwise the
|
|
|
160 |
existing level will be incremented. This option may be specified multiple times.
|
|
|
161 |
|
|
|
162 |
=back
|
|
|
163 |
|
|
|
164 |
=head1 DESCRIPTION
|
|
|
165 |
|
|
|
166 |
This program will use and check a ".jatsignore" file.
|
|
|
167 |
|
|
|
168 |
The file is used to:
|
|
|
169 |
|
|
|
170 |
=over 4
|
|
|
171 |
|
|
|
172 |
1 Ignore files and folders for the purposes of Code Metrics generation
|
|
|
173 |
|
|
|
174 |
2 Ignore files and folders for the purposes of LXR processing
|
|
|
175 |
|
|
|
176 |
=back
|
|
|
177 |
|
|
|
178 |
=head1 FILE FORMAT
|
|
|
179 |
|
|
|
180 |
The .jatsignore file has the following format:
|
|
|
181 |
|
|
|
182 |
=over 4
|
|
|
183 |
|
|
|
184 |
=item *
|
|
|
185 |
|
|
|
186 |
Lines starting with a '#' are treated as comments and will be ignored.
|
|
|
187 |
|
|
|
188 |
=item *
|
|
|
189 |
|
|
|
190 |
Blank lines will be ignored
|
|
|
191 |
|
|
|
192 |
=item *
|
|
|
193 |
|
|
|
194 |
Leading and trailing white space will be ignored
|
|
|
195 |
|
|
|
196 |
=item *
|
|
|
197 |
|
|
|
198 |
All other lines will be treated as a single 'ignore' specifications.
|
|
|
199 |
|
|
|
200 |
=item *
|
|
|
201 |
|
|
|
202 |
The '/' character is used a directory separator.
|
|
|
203 |
|
|
|
204 |
=back
|
|
|
205 |
|
|
|
206 |
An ignore' specifications can take one of the following forms:
|
|
|
207 |
|
|
|
208 |
=over 4
|
|
|
209 |
|
|
|
210 |
=item *
|
|
|
211 |
|
|
|
212 |
A line starting with a '+' is taken to be a regular expression (regexp), with the '+' removed, all others are simple exclusion patterns.
|
|
|
213 |
|
|
|
214 |
=item *
|
|
|
215 |
|
|
|
216 |
A simple exclusion may use '*' and '?' as wildcard characters.
|
|
|
217 |
|
|
|
218 |
Examples:
|
|
|
219 |
|
|
|
220 |
*.pdf
|
|
|
221 |
Test???.ini
|
|
|
222 |
Test/*.ini
|
|
|
223 |
|
|
|
224 |
=item *
|
|
|
225 |
|
|
|
226 |
A simple exclusion ending in a / is taken to be a directory to be ignore. Only that directory will be ignored.
|
|
|
227 |
|
|
|
228 |
Examples:
|
|
|
229 |
|
|
|
230 |
Test/
|
|
|
231 |
Test/Data
|
|
|
232 |
|
|
|
233 |
=item *
|
|
|
234 |
|
|
|
235 |
A simple exclusion ending in a /* is taken to be a directory to be ignore. The directory and all subdirectories will be ignored.
|
|
|
236 |
|
|
|
237 |
Examples:
|
|
|
238 |
|
|
|
239 |
Test/*
|
|
|
240 |
|
|
|
241 |
=item *
|
|
|
242 |
|
|
|
243 |
A regexp ending in a / will have the '/' removed and it will be applied to directories. If the regexp matches then
|
|
|
244 |
the entry will be removed. This can be used to remove individial directories as well as directory trees.
|
|
|
245 |
|
|
|
246 |
Examples:
|
|
|
247 |
|
|
|
248 |
+/Test/ - Will ignore a directory called Test and all subdirs
|
|
|
249 |
+/Test$/ - Will ignore a directory called Test but not its subdirs
|
|
|
250 |
|
|
|
251 |
=item *
|
|
|
252 |
|
|
|
253 |
A regexp not ending in a / is used to ignore files. All files match the regexp will be ignored.
|
|
|
254 |
|
|
|
255 |
Examples:
|
|
|
256 |
|
|
|
257 |
+/.*pdf$
|
|
|
258 |
+/Test...\.ini$
|
|
|
259 |
+/Test/.*ini$
|
|
|
260 |
|
|
|
261 |
=back
|
|
|
262 |
|
|
|
263 |
=head1 EXAMPLE
|
|
|
264 |
|
|
|
265 |
=head2 Testing
|
|
|
266 |
|
|
|
267 |
jats etool jats_ignore -test
|
|
|
268 |
|
|
|
269 |
This command will locate the .jatsignore file, examine each line for correctness.
|
|
|
270 |
|
|
|
271 |
=head2 Display
|
|
|
272 |
|
|
|
273 |
jats etool jats_ignore -display
|
|
|
274 |
|
|
|
275 |
This command will locate the .jatsignore file, examine each line for correctness
|
|
|
276 |
and then display the files and folders ignored by the files specifications.
|
|
|
277 |
|
|
|
278 |
=cut
|
|
|
279 |
|
|
|
280 |
|