12 |
|
|
13 |
|
my %opt; |
14 |
|
Getopt::Long::Configure ("bundling"); |
15 |
< |
GetOptions (\%opt, "dumb|d", "force|f", "destination|o=s", "dataset|s", "help|h"); |
15 |
> |
GetOptions (\%opt, "dumb|d", "force|f", "destination|o=s", "print|p", "dataset|s", "help|h"); |
16 |
|
|
17 |
< |
printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$opt{"dataset"} && !$ARGV[1]); |
17 |
> |
printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$opt{"dataset"} && !$opt{"print"} && !$ARGV[1]); |
18 |
|
my $crabDir = $ARGV[0]; |
19 |
|
my $outputDir = $ARGV[0]; |
20 |
|
my $dataset = $ARGV[0]; |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
< |
die "Output directory does not exist, stopped" if !(-e $outputDir) || !(-d $outputDir); |
69 |
< |
opendir (CRAB_OUTPUT, "$outputDir"); |
70 |
< |
my @crabOutput = readdir (CRAB_OUTPUT); |
71 |
< |
closedir (CRAB_OUTPUT); |
68 |
> |
die "Output directory does not exist, stopped" if !$opt{"print"} && (!(-e $outputDir) || !(-d $outputDir)); |
69 |
> |
my @crabOutput; |
70 |
> |
if (!$opt{"print"}) |
71 |
> |
{ |
72 |
> |
opendir (CRAB_OUTPUT, "$outputDir"); |
73 |
> |
@crabOutput = readdir (CRAB_OUTPUT); |
74 |
> |
closedir (CRAB_OUTPUT); |
75 |
> |
} |
76 |
|
my %filesToKeep; |
77 |
|
if (!$opt{"dumb"}) |
78 |
|
{ |
104 |
|
close (TEST_FILE); |
105 |
|
unlink "$opt{'destination'}/.crabCleanTest"; |
106 |
|
} |
107 |
< |
opendir (CRAB_OUTPUT, "$outputDir"); |
108 |
< |
my @crabOutput = readdir (CRAB_OUTPUT); |
109 |
< |
closedir (CRAB_OUTPUT); |
110 |
< |
my $nFiles = @crabOutput - 2; |
111 |
< |
print "Before cleaning: $nFiles files\n"; |
107 |
> |
if (!$opt{"print"}) |
108 |
> |
{ |
109 |
> |
opendir (CRAB_OUTPUT, "$outputDir"); |
110 |
> |
my @crabOutput = readdir (CRAB_OUTPUT); |
111 |
> |
closedir (CRAB_OUTPUT); |
112 |
> |
my $nFiles = @crabOutput - 2; |
113 |
> |
print "Before cleaning: $nFiles files\n"; |
114 |
> |
} |
115 |
|
foreach my $file (@crabOutput) |
116 |
|
{ |
117 |
|
next if ($file eq "." || $file eq ".."); |
126 |
|
} |
127 |
|
elsif ((($opt{"dumb"} && $filesToKeep{$jobNumber} != $submissionNumber) |
128 |
|
|| (!$opt{"dumb"} && $filesToKeep{$jobNumber} ne $file)) |
129 |
< |
&& !$opt{"destination"}) |
129 |
> |
&& !$opt{"destination"} && !$opt{"print"}) |
130 |
|
{ |
131 |
|
system ("rm -f $outputDir/$file") if $opt{"force"}; |
132 |
|
system ("rm -i $outputDir/$file") if !$opt{"force"}; |
133 |
|
} |
134 |
|
elsif ((($opt{"dumb"} && $filesToKeep{$jobNumber} == $submissionNumber) |
135 |
|
|| (!$opt{"dumb"} && $filesToKeep{$jobNumber} eq $file)) |
136 |
< |
&& $opt{"destination"}) |
136 |
> |
&& $opt{"destination"} && !$opt{"print"}) |
137 |
|
{ |
138 |
|
system ("mv -f $outputDir/$file $opt{'destination'}/$file") if $opt{"force"}; |
139 |
|
system ("mv -i $outputDir/$file $opt{'destination'}/$file") if !$opt{"force"}; |
140 |
|
} |
141 |
|
} |
142 |
< |
opendir (CRAB_OUTPUT, "$outputDir"); |
143 |
< |
my @crabOutput = readdir (CRAB_OUTPUT); |
144 |
< |
closedir (CRAB_OUTPUT); |
145 |
< |
opendir (CRAB_OUTPUT, "$opt{'destination'}"); |
146 |
< |
my @crabOutputInDestination = readdir (CRAB_OUTPUT); |
147 |
< |
closedir (CRAB_OUTPUT); |
148 |
< |
my $nFiles = @crabOutput - 2; |
149 |
< |
$nFiles = @crabOutputInDestination - 2 if $opt{"destination"}; |
150 |
< |
print "After cleaning: $nFiles files\n"; |
142 |
> |
if (!$opt{"print"}) |
143 |
> |
{ |
144 |
> |
opendir (CRAB_OUTPUT, "$outputDir"); |
145 |
> |
my @crabOutput = readdir (CRAB_OUTPUT); |
146 |
> |
closedir (CRAB_OUTPUT); |
147 |
> |
opendir (CRAB_OUTPUT, "$opt{'destination'}"); |
148 |
> |
my @crabOutputInDestination = readdir (CRAB_OUTPUT); |
149 |
> |
closedir (CRAB_OUTPUT); |
150 |
> |
my $nFiles = @crabOutput - 2; |
151 |
> |
$nFiles = @crabOutputInDestination - 2 if $opt{"destination"}; |
152 |
> |
print "After cleaning: $nFiles files\n"; |
153 |
> |
} |
154 |
> |
else |
155 |
> |
{ |
156 |
> |
foreach my $file (keys %filesToKeep) |
157 |
> |
{ |
158 |
> |
print $filesToKeep{$file} . "\n"; |
159 |
> |
} |
160 |
> |
} |
161 |
|
|
162 |
|
sub |
163 |
|
printHelp |
167 |
|
|
168 |
|
print "Usage: $exeName [OPTION]... CRAB_DIR OUTPUT_DIR\n"; |
169 |
|
print " or: $exeName -d [OPTION]... OUTPUT_DIR\n"; |
170 |
+ |
print " or: $exeName -p [OPTION]... CRAB_DIR\n"; |
171 |
|
print " or: $exeName -s [OPTION]... DATASET\n"; |
172 |
|
print "Deletes excess EDM output caused by multiple CRAB submissions using the results\n"; |
173 |
|
print "contained in the CRAB working directory provided.\n"; |
181 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
182 |
|
printf "%-29s%s\n", " -o, --destination DIR", "do not remove excess output and move the good files"; |
183 |
|
printf "%-29s%s\n", " ", "to DIR"; |
184 |
+ |
printf "%-29s%s\n", " -p, --print", "do not remove any files, just print the names of"; |
185 |
+ |
printf "%-29s%s\n", " ", "the good files to the screen"; |
186 |
|
printf "%-29s%s\n", " -s, --dataset", "tells the script to expect a dataset name instead"; |
187 |
|
printf "%-29s%s\n", " ", "of a directory"; |
188 |
|
|