15 |
|
sub downloadRelease; |
16 |
|
sub datasetExists; |
17 |
|
sub uploadConfig; |
18 |
+ |
sub locationExists; |
19 |
|
|
20 |
|
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
21 |
|
|
22 |
|
my %opt; |
23 |
|
Getopt::Long::Configure ("bundling"); |
24 |
< |
GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "fileList|t=s", "release|r=s", "other|o", "recipe|e=s", "help|h"); |
24 |
> |
GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "name|n=s", "fileList|t=s", "release|r=s", "other|o", "recipe|e=s", "help|h"); |
25 |
|
my $argc = @ARGV; |
26 |
|
|
27 |
|
printHelp ($ARGV[0]) if $opt{"help"}; |
81 |
|
$status = "" if $ARGV[0] eq "update"; |
82 |
|
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
83 |
|
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
84 |
< |
dbUpdate ($id, $fullDataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"}; |
84 |
> |
if ($opt{"location"} && locationExists ($id, $opt{"location"})) |
85 |
> |
{ |
86 |
> |
print "This location is already registered in the database!\n"; |
87 |
> |
exit; |
88 |
> |
} |
89 |
> |
dbUpdate ($id, $fullDataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"format"}, $opt{"location"}, $opt{"name"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"}; |
90 |
|
dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"}; |
91 |
|
dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"}; |
92 |
|
dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"}; |
182 |
|
my $userAndHost = shift; |
183 |
|
my $format = shift; |
184 |
|
my $location = shift; |
185 |
+ |
my $name = shift; |
186 |
|
my $fileListName = shift; |
187 |
|
my $status = shift; |
188 |
|
my $comment = shift; |
285 |
|
$jsonFile = addSlashes ($jsonFile); |
286 |
|
$lumiSummary = addSlashes ($lumiSummary); |
287 |
|
$fullLocation = addSlashes ($fullLocation); |
288 |
+ |
$name = addSlashes ($name); |
289 |
|
$fileList = addSlashes ($fileList); |
290 |
|
$status = addSlashes ($status); |
291 |
|
$comment = addSlashes ($comment); |
295 |
|
my $query; |
296 |
|
if ($id < 0) |
297 |
|
{ |
298 |
+ |
$query = "select id from ntuple where dataset='$dataset'"; |
299 |
+ |
$db->selectdb ("ntuple"); |
300 |
+ |
$results = $db->query ($query); |
301 |
+ |
if ($results->numrows ()) |
302 |
+ |
{ |
303 |
+ |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
304 |
+ |
my $response = <STDIN>; |
305 |
+ |
$response =~ s/\n//g; |
306 |
+ |
$response = "n" if !$response; |
307 |
+ |
exit if substr (lc ($response), 0, 1) ne 'y'; |
308 |
+ |
} |
309 |
+ |
|
310 |
|
$query = "select max(id) from ntuple"; |
311 |
|
$db->selectdb ("ntuple"); |
312 |
|
$results = $db->query ($query); |
321 |
|
my $fields; |
322 |
|
my $values; |
323 |
|
|
324 |
< |
$values .= ", dataset='$dataset'" if $dataset; |
324 |
> |
if ($name) |
325 |
> |
{ |
326 |
> |
$query = "select id from ntuple where dataset='$name'"; |
327 |
> |
$db->selectdb ("ntuple"); |
328 |
> |
$results = $db->query ($query); |
329 |
> |
if ($results->numrows ()) |
330 |
> |
{ |
331 |
> |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
332 |
> |
my $response = <STDIN>; |
333 |
> |
$response =~ s/\n//g; |
334 |
> |
$response = "n" if !$response; |
335 |
> |
exit if substr (lc ($response), 0, 1) ne 'y'; |
336 |
> |
} |
337 |
> |
$values .= ", dataset='$name'"; |
338 |
> |
} |
339 |
> |
|
340 |
|
$values .= ", lastUpdateTime=now()"; |
341 |
|
$values .= ", lastUpdateUser='$user'"; |
342 |
|
$values .= ", format='$format'" if $format; |
439 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
440 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
441 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
442 |
+ |
printf "%-29s%s\n", " -n, --name NAME", "rename the entry"; |
443 |
|
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
444 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
445 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
497 |
|
} |
498 |
|
elsif ($command eq "uploadConfig") |
499 |
|
{ |
500 |
< |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n"; |
500 |
> |
print "Usage: $exeName -p FILE -r RELEASE [OPTION]... uploadConfig NAME\n"; |
501 |
|
print "Creates an entry in the database for a customized Python configuration file.\n"; |
502 |
|
print "\n"; |
503 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
589 |
|
print "$recipeName does not exist!\n"; |
590 |
|
exit; |
591 |
|
} |
592 |
< |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
592 |
> |
move ($release, "/home/osucms/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
593 |
|
open (PY_CONFIG, "<$psetName"); |
594 |
|
my @pset = <PY_CONFIG>; |
595 |
|
close (PY_CONFIG); |
633 |
|
print "Ntuple release \"$release\" not found!\n"; |
634 |
|
exit; |
635 |
|
} |
636 |
< |
if (!(-e "/home/hart/public_html/releases/$release.tar.gz")) |
636 |
> |
if (!(-e "/home/osucms/public_html/releases/$release.tar.gz")) |
637 |
|
{ |
638 |
|
print "Release is in the database but no package exists!\n"; |
639 |
|
exit; |
645 |
|
print PY_CONFIG $row[1]; |
646 |
|
close (PY_CONFIG); |
647 |
|
} |
648 |
< |
copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz"); |
648 |
> |
copy ("/home/osucms/public_html/releases/$release.tar.gz", "$release.tar.gz"); |
649 |
|
} |
650 |
|
|
651 |
|
sub |
742 |
|
$db->selectdb ("ntuple"); |
743 |
|
$results = $db->query ($query); |
744 |
|
} |
745 |
+ |
|
746 |
+ |
sub |
747 |
+ |
locationExists |
748 |
+ |
{ |
749 |
+ |
my $id = shift; |
750 |
+ |
my $location = shift; |
751 |
+ |
|
752 |
+ |
$location =~ s/^(.*)\/+$/$1/; |
753 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
754 |
+ |
$db->selectdb ("ntuple"); |
755 |
+ |
my $results = $db->query ($query); |
756 |
+ |
return 1 if $results->numrows (); |
757 |
+ |
|
758 |
+ |
if ($location =~ m/^\/store\/.*$/) |
759 |
+ |
{ |
760 |
+ |
$location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/; |
761 |
+ |
} |
762 |
+ |
elsif ($location =~ m/^\/data\/se\/store\/.*$/) |
763 |
+ |
{ |
764 |
+ |
$location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/; |
765 |
+ |
} |
766 |
+ |
|
767 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
768 |
+ |
$db->selectdb ("ntuple"); |
769 |
+ |
my $results = $db->query ($query); |
770 |
+ |
return 1 if $results->numrows (); |
771 |
+ |
|
772 |
+ |
return 0; |
773 |
+ |
} |