12 |
|
|
13 |
|
my %opt; |
14 |
|
Getopt::Long::Configure ("bundling"); |
15 |
< |
GetOptions (\%opt, "dumb|d", "force|f", "dataset|s", "help|h"); |
15 |
> |
GetOptions (\%opt, "dumb|d", "force|f", "destination|o=s", "dataset|s", "help|h"); |
16 |
|
|
17 |
|
printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$opt{"dataset"} && !$ARGV[1]); |
18 |
|
my $crabDir = $ARGV[0]; |
34 |
|
$crabDir = "$row[0]/ntuple"; |
35 |
|
$outputDir = $row[1]; |
36 |
|
} |
37 |
< |
if ($results->numrows () == 0) |
38 |
< |
{ |
39 |
< |
print "Database entry does not exist.\n"; |
40 |
< |
exit; |
41 |
< |
} |
37 |
> |
die "Database entry does not exist, stopped" if $results->numrows () == 0; |
38 |
|
if ($results->numrows () > 1) |
39 |
|
{ |
40 |
|
my %workingDir; |
59 |
|
print "\nWhich entry would you like to use?: "; |
60 |
|
my $response = <STDIN>; |
61 |
|
$response =~ s/[ \t\n]//g; |
62 |
< |
if (!(exists $workingDir{$response})) |
67 |
< |
{ |
68 |
< |
print "Your selection \"$response\" was not a valid option! Quitting.\n"; |
69 |
< |
exit; |
70 |
< |
} |
62 |
> |
die "Your selection was not a valid option, stopped" if !(exists $workingDir{$response}); |
63 |
|
$crabDir = "$workingDir{$response}/ntuple"; |
64 |
|
$outputDir = $location{$response}; |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
< |
if (!(-e $outputDir) || !(-d $outputDir)) |
77 |
< |
{ |
78 |
< |
print "Output directory $outputDir does not exist!\n"; |
79 |
< |
exit; |
80 |
< |
} |
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); |
72 |
|
my %filesToKeep; |
73 |
|
if (!$opt{"dumb"}) |
74 |
|
{ |
75 |
< |
if (!(-e $crabDir) || !(-d $crabDir)) |
88 |
< |
{ |
89 |
< |
print "CRAB directory $crabDir does not exist!\n"; |
90 |
< |
exit; |
91 |
< |
} |
75 |
> |
die "CRAB directory does not exist, stopped" if !(-e $crabDir) || !(-d $crabDir); |
76 |
|
parseCrabDir ($crabDir, \%filesToKeep); |
77 |
|
} |
78 |
|
else |
92 |
|
} |
93 |
|
} |
94 |
|
} |
95 |
+ |
if ($opt{"destination"}) |
96 |
+ |
{ |
97 |
+ |
mkdir $opt{"destination"} or die "Failed to create destination directory, stopped" if !(-e $opt{"destination"}); |
98 |
+ |
die "Destination is not a directory, stopped" if !(-d $opt{"destination"}); |
99 |
+ |
open (TEST_FILE, ">$opt{'destination'}/.crabCleanTest") or die "Unable to write to destination directory, stopped"; |
100 |
+ |
close (TEST_FILE); |
101 |
+ |
unlink "$opt{'destination'}/.crabCleanTest"; |
102 |
+ |
} |
103 |
|
opendir (CRAB_OUTPUT, "$outputDir"); |
104 |
|
my @crabOutput = readdir (CRAB_OUTPUT); |
105 |
|
closedir (CRAB_OUTPUT); |
117 |
|
{ |
118 |
|
print "No information found for job $jobNumber!\n"; |
119 |
|
} |
120 |
< |
elsif (($opt{"dumb"} && $filesToKeep{$jobNumber} != $submissionNumber) |
120 |
> |
elsif ((($opt{"dumb"} && $filesToKeep{$jobNumber} != $submissionNumber) |
121 |
|
|| (!$opt{"dumb"} && $filesToKeep{$jobNumber} ne $file)) |
122 |
+ |
&& !$opt{"destination"}) |
123 |
|
{ |
124 |
|
system ("rm -f $outputDir/$file") if $opt{"force"}; |
125 |
|
system ("rm -i $outputDir/$file") if !$opt{"force"}; |
126 |
|
} |
127 |
+ |
elsif ((($opt{"dumb"} && $filesToKeep{$jobNumber} == $submissionNumber) |
128 |
+ |
|| (!$opt{"dumb"} && $filesToKeep{$jobNumber} eq $file)) |
129 |
+ |
&& $opt{"destination"}) |
130 |
+ |
{ |
131 |
+ |
system ("mv -f $outputDir/$file $opt{'destination'}/$file") if $opt{"force"}; |
132 |
+ |
system ("mv -i $outputDir/$file $opt{'destination'}/$file") if !$opt{"force"}; |
133 |
+ |
} |
134 |
|
} |
135 |
|
opendir (CRAB_OUTPUT, "$outputDir"); |
136 |
|
my @crabOutput = readdir (CRAB_OUTPUT); |
137 |
|
closedir (CRAB_OUTPUT); |
138 |
+ |
opendir (CRAB_OUTPUT, "$opt{'destination'}"); |
139 |
+ |
my @crabOutputInDestination = readdir (CRAB_OUTPUT); |
140 |
+ |
closedir (CRAB_OUTPUT); |
141 |
|
my $nFiles = @crabOutput - 2; |
142 |
+ |
$nFiles = @crabOutputInDestination - 2 if $opt{"destination"}; |
143 |
|
print "After cleaning: $nFiles files\n"; |
144 |
|
|
145 |
|
sub |
161 |
|
printf "%-29s%s\n", " -f, --force", "never prompt (default is to prompt before any"; |
162 |
|
printf "%-29s%s\n", " ", "removal)"; |
163 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
164 |
+ |
printf "%-29s%s\n", " -o, --destination DIR", "do not remove excess output and move the good files"; |
165 |
+ |
printf "%-29s%s\n", " ", "to DIR"; |
166 |
|
printf "%-29s%s\n", " -s, --dataset", "tells the script to expect a dataset name instead"; |
167 |
|
printf "%-29s%s\n", " ", "of a directory"; |
168 |
|
|
194 |
|
} |
195 |
|
my @surlForGrid = `grep -A 1 '<SurlForGrid' $crabDir/res/$file`; |
196 |
|
my $fileName = $surlForGrid[1]; |
197 |
< |
my $fileName = $surlForGrid[0] if $surlForGrid[0] =~ m/Value=/; |
197 |
> |
$fileName = $surlForGrid[0] if $surlForGrid[0] =~ m/Value=/; |
198 |
|
$fileName =~ s/^.*\/([^\/]*)\n/$1/ if !($fileName =~ m/Value=/); |
199 |
< |
$fileName =~ s/^.*\/([^\/]*)"\/>\n/$1/; |
199 |
> |
$fileName =~ s/^.*\/([^\/]*)"\/>\n/$1/ if $fileName =~ m/Value=/; |
200 |
|
$filesToKeep->{$jobNumber} = $fileName; |
201 |
|
} |
202 |
|
} |