3 |
|
use strict; |
4 |
|
use Getopt::Long; |
5 |
|
use Mysql; |
6 |
+ |
use Term::ANSIColor; |
7 |
|
|
8 |
|
sub printHelp; |
9 |
|
sub parseCrabDir; |
22 |
|
|
23 |
|
if ($opt{"dataset"}) |
24 |
|
{ |
25 |
< |
my $query = "select workingDirectory,location,dataset,user,creationTime from ntuple where dataset like '$dataset' order by creationTime"; |
25 |
> |
my $queryDataset = $dataset; |
26 |
> |
$queryDataset =~ s/\*/%/g; |
27 |
> |
$queryDataset =~ s/(.*)/%$1%/g; |
28 |
> |
my $query = "select workingDirectory,location,dataset,user,creationTime,status from ntuple where dataset like '$queryDataset' order by creationTime"; |
29 |
|
$db->selectdb ("ntuple"); |
30 |
|
my $results = $db->query ($query); |
31 |
|
if ($results->numrows () == 1) |
39 |
|
print "Database entry does not exist.\n"; |
40 |
|
exit; |
41 |
|
} |
42 |
< |
my %workingDir; |
39 |
< |
my %location; |
40 |
< |
print "Found multiple database entries matching\n"; |
41 |
< |
print "\"$dataset\":\n"; |
42 |
< |
for (my $i = 1; $i <= $results->numrows (); $i++) |
42 |
> |
if ($results->numrows () > 1) |
43 |
|
{ |
44 |
< |
my @row = $results->fetchrow (); |
45 |
< |
$workingDir{"$i"} = $row[0]; |
46 |
< |
$location{"$i"} = $row[1]; |
47 |
< |
printf "(%2d) $row[2]\n", $i; |
48 |
< |
print " created by $row[3] on $row[4]\n"; |
49 |
< |
} |
50 |
< |
print "\nWhich entry would you like to use?: "; |
51 |
< |
my $response = <STDIN>; |
52 |
< |
$response =~ s/[ \t\n]//g; |
53 |
< |
if (!(exists $workingDir{$response})) |
54 |
< |
{ |
55 |
< |
print "Your selection \"$response\" was not a valid option! Quitting.\n"; |
56 |
< |
exit; |
44 |
> |
my %workingDir; |
45 |
> |
my %location; |
46 |
> |
print "Found multiple database entries matching\n"; |
47 |
> |
print "\"$dataset\":\n"; |
48 |
> |
for (my $i = 1; $i <= $results->numrows (); $i++) |
49 |
> |
{ |
50 |
> |
my @row = $results->fetchrow (); |
51 |
> |
$row[4] =~ s/([^ ]*) [^ ]*/$1/g; |
52 |
> |
$workingDir{"$i"} = $row[0]; |
53 |
> |
$location{"$i"} = $row[1]; |
54 |
> |
printf "(%2d) $row[2]\n", $i; |
55 |
> |
print " ("; |
56 |
> |
print color "green" if $row[5] eq "present"; |
57 |
> |
print color "bold yellow" if $row[5] eq "submitted"; |
58 |
> |
print color "bold red" if $row[5] eq "created" or $row[5] eq "cancelled" or $row[5] eq "deprecated"; |
59 |
> |
print $row[5]; |
60 |
> |
print color "reset"; |
61 |
> |
print ") created by $row[3] on $row[4]\n"; |
62 |
> |
} |
63 |
> |
print "\nWhich entry would you like to use?: "; |
64 |
> |
my $response = <STDIN>; |
65 |
> |
$response =~ s/[ \t\n]//g; |
66 |
> |
if (!(exists $workingDir{$response})) |
67 |
> |
{ |
68 |
> |
print "Your selection \"$response\" was not a valid option! Quitting.\n"; |
69 |
> |
exit; |
70 |
> |
} |
71 |
> |
$crabDir = "$workingDir{$response}/ntuple"; |
72 |
> |
$outputDir = $location{$response}; |
73 |
|
} |
58 |
– |
$crabDir = "$workingDir{$response}/ntuple"; |
59 |
– |
$outputDir = $location{$response}; |
74 |
|
} |
75 |
|
|
76 |
|
if (!(-e $outputDir) || !(-d $outputDir)) |
108 |
|
} |
109 |
|
} |
110 |
|
} |
111 |
+ |
opendir (CRAB_OUTPUT, "$outputDir"); |
112 |
+ |
my @crabOutput = readdir (CRAB_OUTPUT); |
113 |
+ |
closedir (CRAB_OUTPUT); |
114 |
+ |
my $nFiles = @crabOutput - 2; |
115 |
+ |
print "Before cleaning: $nFiles files\n"; |
116 |
|
foreach my $file (@crabOutput) |
117 |
|
{ |
118 |
|
next if ($file eq "." || $file eq ".."); |
132 |
|
system ("rm -i $outputDir/$file") if !$opt{"force"}; |
133 |
|
} |
134 |
|
} |
135 |
+ |
opendir (CRAB_OUTPUT, "$outputDir"); |
136 |
+ |
my @crabOutput = readdir (CRAB_OUTPUT); |
137 |
+ |
closedir (CRAB_OUTPUT); |
138 |
+ |
my $nFiles = @crabOutput - 2; |
139 |
+ |
print "After cleaning: $nFiles files\n"; |
140 |
|
|
141 |
|
sub |
142 |
|
printHelp |
186 |
|
print "Job $jobNumber failed (return value $wrapperStatus). Skipping.\n"; |
187 |
|
next; |
188 |
|
} |
189 |
< |
my @surlForGrid = `grep -A 1 '<SurlForGrid>' $crabDir/res/$file`; |
189 |
> |
my @surlForGrid = `grep -A 1 '<SurlForGrid' $crabDir/res/$file`; |
190 |
|
my $fileName = $surlForGrid[1]; |
191 |
< |
$fileName =~ s/^.*\/([^\/]*)\n/$1/; |
191 |
> |
my $fileName = $surlForGrid[0] if $surlForGrid[0] =~ m/Value=/; |
192 |
> |
$fileName =~ s/^.*\/([^\/]*)\n/$1/ if !($fileName =~ m/Value=/); |
193 |
> |
$fileName =~ s/^.*\/([^\/]*)"\/>\n/$1/; |
194 |
|
$filesToKeep->{$jobNumber} = $fileName; |
195 |
|
} |
196 |
|
} |