ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osudb
(Generate patch)

Comparing UserCode/OSUT3Analysis/DBTools/scripts/osudb (file contents):
Revision 1.4 by ahart, Tue Jul 31 14:12:19 2012 UTC vs.
Revision 1.17 by ahart, Sat Jan 19 07:16:03 2013 UTC

# Line 7 | Line 7 | use File::Copy;
7  
8   sub getDataset;
9   sub dbUpdate;
10 + sub dbUpdateOther;
11   sub dbDelete;
12 + sub dbDeleteOther;
13   sub addSlashes;
14   sub uploadRelease;
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", "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"};
28 < printHelp () if $argc != 2;
29 < printHelp () if $ARGV[0] ne "create" && $ARGV[0] ne "update" && $ARGV[0] ne "finish" && $ARGV[0] ne "deprecate" && $ARGV[0] ne "uploadRelease" && $ARGV[0] ne "deleteEntry";
28 > printHelp () if $argc != 2 && $ARGV[0] ne "createOther";
29 > printHelp () if $ARGV[0] ne "create" && $ARGV[0] ne "createOther" && $ARGV[0] ne "update" && $ARGV[0] ne "finish" && $ARGV[0] ne "deprecate" && $ARGV[0] ne "uploadRelease" && $ARGV[0] ne "downloadRelease" && $ARGV[0] ne "deleteEntry" && $ARGV[0] ne "uploadConfig";
30   if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"})
31    {
32      print "The directory containing the ntuples must be given!\n";
33      exit;
34    }
35 < if ($ARGV[0] eq "uploadRelease" && !$opt{"pyConfig"} && !$opt{"release"})
35 > if ($ARGV[0] eq "uploadRelease" && (!$opt{"pyConfig"} || !$opt{"release"} || !$opt{"recipe"}))
36    {
37 <    print "Both the Python and the CMSSW release must be given!\n";
37 >    print "The Python config, CMSSW release directory, and recipe file must be given!\n";
38      exit;
39    }
40 < if ($ARGV[0] ne "uploadRelease")
40 > if ($ARGV[0] eq "uploadConfig" && (!$opt{"pyConfig"} || !$opt{"release"}))
41    {
42 <    my $id = -1;
43 <    $id = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create";
38 <    $ARGV[0] = "create" if $id < 0;
39 <    my $status = "present";
40 <    $status = "" if $ARGV[0] eq "update";
41 <    $status = "deprecated" if $ARGV[0] eq "deprecate";
42 <    $opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"};
43 <    $opt{"location"} = "$ENV{'PWD'}/$opt{'location'}" if !($opt{"location"} =~ m/^\//);
44 <    dbUpdate ($id, $ARGV[1], $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"});
45 <    dbDelete ($id) if $ARGV[0] eq "deleteEntry";
42 >    print "The Python config and ntuple release must be given!\n";
43 >    exit;
44    }
45 < else
45 > if ($opt{"location"} && locationExists ($opt{"location"}))
46 >  {
47 >    print "This location is already registered in the database!\n";
48 >    exit;
49 >  }
50 > if ($ARGV[0] eq "uploadRelease")
51    {
52      my $parentDir = "./$opt{'release'}";
53      $parentDir =~ s/CMSSW_[^\/]*//g;
# Line 53 | Line 56 | else
56      $cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/;
57      `tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`;
58      $opt{"format"} = "BEAN" if !$opt{"format"};
59 <    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], $ENV{"USER"}, $opt{"comment"});
59 >    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}, $opt{"recipe"});
60 >  }
61 > elsif ($ARGV[0] eq "downloadRelease")
62 >  {
63 >    downloadRelease ($ARGV[1], $opt{"pyConfig"});
64 >  }
65 > elsif ($ARGV[0] eq "uploadConfig")
66 >  {
67 >    uploadConfig ($ARGV[1], $ENV{"USER"}, $opt{"pyConfig"}, $opt{"release"}, $opt{"comment"});
68 >  }
69 > elsif ($ARGV[0] eq "createOther")
70 >  {
71 >    my @listOfFiles = @ARGV;
72 >    @listOfFiles = reverse (@listOfFiles);
73 >    pop (@listOfFiles);
74 >    @listOfFiles = reverse (@listOfFiles);
75 >    dbOtherCreate ("$ENV{'USER'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"});
76 >  }
77 > else
78 >  {
79 >    my $id = -1;
80 >    my $fullDataset;
81 >    ($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create" && ($ARGV[0] ne "update" || !$opt{"other"}) && ($ARGV[0] ne "deleteEntry" || !$opt{"other"});
82 >    $id = $ARGV[1] if ($ARGV[0] eq "update" && $opt{"other"}) || ($ARGV[0] eq "deleteEntry" && $opt{"other"});
83 >    $fullDataset = $ARGV[1] if $id < 0;
84 >    $ARGV[0] = "create" if $id < 0;
85 >    my $status = "present";
86 >    $status = "" if $ARGV[0] eq "update";
87 >    $status = "deprecated" if $ARGV[0] eq "deprecate";
88 >    $opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"};
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"};
93    }
94  
95   sub
# Line 79 | Line 115 | getDataset
115    my $queryDataset = $dataset;
116    $queryDataset =~ s/\*/%/g;
117    $queryDataset =~ s/(.*)/%$1%/g;
118 <  my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by lastUpdateTime";
118 >  my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime";
119    $db->selectdb ("ntuple");
120    $results = $db->query ($query);
121    if ($results->numrows () == 1)
122      {
123        my @row = $results->fetchrow ();
124 <      return $row[0];
124 >      return ($row[0], $row[1]);
125      }
126    if ($results->numrows () == 0)
127      {
# Line 96 | Line 132 | getDataset
132            $response =~ s/\n//g;
133            $response = "y" if !$response;
134            exit if substr (lc ($response), 0, 1) ne 'y';
135 <          return -1;
135 >          return (-1, "");
136          }
137        else
138          {
# Line 104 | Line 140 | getDataset
140            exit;
141          }
142      }
143 <  my %map;
143 >  my %id;
144 >  my %fullDataset;
145    print "Found multiple database entries matching\n";
146    print "\"$dataset\":\n";
147    print "( 0) new\n" if $command ne "deleteEntry" && $command ne "deprecate";
148    for (my $i = 1; $i <= $results->numrows (); $i++)
149      {
150        my @row = $results->fetchrow ();
151 <      $map{"$i"} = $row[0];
151 >      $id{"$i"} = $row[0];
152 >      $fullDataset{"$i"} = $row[1];
153        printf "(%2d) $row[1]\n", $i;
154        print "     created by $row[2] on $row[3]\n";
155      }
# Line 126 | Line 164 | getDataset
164      }
165    my $response = <STDIN>;
166    $response =~ s/[ \t\n]//g;
167 <  return -1 if $response == 0 && $command ne "deleteEntry" && $command ne "deprecate";
168 <  if (!(exists $map{$response}))
167 >  return (-1, "") if $response == 0 && $command ne "deleteEntry" && $command ne "deprecate";
168 >  if (!(exists $id{$response}))
169      {
170        print "Your selection \"$response\" was not a valid option! Quitting.\n";
171        exit;
172      }
173  
174 <  return $map{$response};
174 >  return ($id{$response}, $fullDataset{$response});
175   }
176  
177   sub
# Line 141 | Line 179 | dbUpdate
179   {
180    my $id = shift;
181    my $dataset = shift;
182 <  my $user = shift;
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;
# Line 151 | Line 190 | dbUpdate
190    my $crabCfgName = shift;
191    my $jsonFileName = shift;
192    my $lumiSummaryName = shift;
193 +  my $release = shift;
194 +
195 +  my $user = $userAndHost;
196 +  $user =~ s/@.*$//g;
197  
198    my $fileList;
199    my $pset;
# Line 219 | Line 262 | dbUpdate
262        close (LUMI_SUMMARY);
263        $lumiSummary = join ("", @lumiSummary);
264      }
265 +  if ($release)
266 +    {
267 +      my $query = "select id from ntupleRelease where name='$release'";
268 +      $db->selectdb ("ntuple");
269 +      my $results = $db->query ($query);
270 +      if ($results->numrows () != 1)
271 +        {
272 +          print "Ntuple release \"$release\" not found!\n";
273 +          exit;
274 +        }
275 +    }
276    ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
277 +  my $fullLocation = $location;
278 +  $fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//);
279  
280    $dataset = addSlashes ($dataset);
281    $user = addSlashes ($user);
# Line 228 | Line 284 | dbUpdate
284    $crabCfg = addSlashes ($crabCfg);
285    $jsonFile = addSlashes ($jsonFile);
286    $lumiSummary = addSlashes ($lumiSummary);
287 <  $location = addSlashes ($location);
287 >  $fullLocation = addSlashes ($fullLocation);
288 >  $name = addSlashes ($name);
289    $fileList = addSlashes ($fileList);
290    $status = addSlashes ($status);
291    $comment = addSlashes ($comment);
292 +  $release = addSlashes ($release);
293  
294    my $results;
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);
# Line 244 | Line 314 | dbUpdate
314        my $id = 1;
315        $id = $row[0] + 1 if $results->numrows ();
316  
317 <      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary) values ($id, '$dataset', now(), now(), '$user', '$format', '$location', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary')";
317 >      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version) values ($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release')";
318      }
319    if ($id > 0)
320      {
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;
343 <      $values .= ", location='$location'" if $location;
343 >      $values .= ", location='$fullLocation'" if $location;
344        $values .= ", fileList='$fileList'" if $fileList;
345        $values .= ", nFiles=$nFiles" if $nFiles;
346        $values .= ", sizeInGB=$size" if $size;
# Line 264 | Line 350 | dbUpdate
350        $values .= ", crabCfg='$crabCfg'" if $crabCfg;
351        $values .= ", jsonFile='$jsonFile'" if $jsonFile;
352        $values .= ", lumiSummary='$lumiSummary'" if $lumiSummary;
353 +      $values .= ", version='$release'" if $release;
354  
355        $values =~ s/^, //;
356        $query = "update ntuple set $values where id=$id";
# Line 274 | Line 361 | dbUpdate
361   }
362  
363   sub
364 + dbUpdateOther
365 + {
366 +  my $id = shift;
367 +  my $comment = shift;
368 +  my $user = shift;
369 +
370 +  $comment = addSlashes ($comment);
371 +
372 +  my $query = "update other set lastUpdateTime=now(), lastUpdateUser='$user', comment='$comment'  where id=$id";
373 +  $db->selectdb ("ntuple");
374 +  my $results = $db->query ($query);
375 +
376 +  return $results;
377 + }
378 +
379 + sub
380   dbDelete
381   {
382    my $id = shift;
383  
281  return if $id < 0;
384    my $query = "delete from ntuple where id=$id";
385    $db->selectdb ("ntuple");
386    my $results = $db->query ($query);
387   }
388  
389   sub
390 + dbDeleteOther
391 + {
392 +  my $id = shift;
393 +
394 +  my $query = "delete from other where id=$id";
395 +  $db->selectdb ("ntuple");
396 +  my $results = $db->query ($query);
397 + }
398 +
399 + sub
400   printHelp
401   {
402    my $command = shift;
# Line 305 | Line 417 | printHelp
417        printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
418        printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
419        printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
420 +      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
421        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
422      }
423 +  elsif ($command eq "createOther")
424 +    {
425 +      print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n";
426 +      print "Creates an entry in the database for non-ntuple data.\n";
427 +      print "\n";
428 +      print "Mandatory arguments to long options are mandatory for short options too.\n";
429 +      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
430 +    }
431    elsif ($command eq "update")
432      {
433        print "Usage: $exeName [OPTION]... update NAME\n";
# Line 318 | Line 439 | printHelp
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";
446        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
447      }
448    elsif ($command eq "finish")
449      {
450        print "Usage: $exeName -l DIRECTORY finish NAME\n";
327
451        print "Finalizes the database entry for dataset NAME, changing its status to\n";
452        print "\"present\".  This is intended to be the final step in command-line based ntuple\n";
453        print "production.\n";
# Line 334 | Line 457 | printHelp
457      }
458    elsif ($command eq "deleteEntry")
459      {
460 <      print "Usage: $exeName deleteEntry NAME\n";
460 >      print "Usage: $exeName [OPTION]... deleteEntry NAME\n";
461        print "Deletes the database entry for dataset NAME. This is intended primarily for\n";
462        print "mistaken database entries. If you wish to actually delete a set of ntuples,\n";
463        print "please use the \"deprecate\" command instead.\n";
464 +      print "\n";
465 +      printf "%-29s%s\n", "  -o, --other", "update an entry in the non-ntuple database";
466      }
467    elsif ($command eq "deprecate")
468      {
# Line 348 | Line 473 | printHelp
473      }
474    elsif ($command eq "uploadRelease")
475      {
476 <      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
476 >      print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
477        print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n";
478        print "database entry for it, with NAME being the name of the release. An ntuple\n";
479        print "release is a CMSSW release with all the necessary packages added for creating\n";
# Line 356 | Line 481 | printHelp
481        print "\n";
482        print "Mandatory arguments to long options are mandatory for short options too.\n";
483        printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
484 +      printf "%-29s%s\n", "  -e, --recipe FILE", "file containing the recipe for the release";
485        printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
486        printf "%-29s%s\n", "  -p, --pyConfig FILE", "default Python config for the release";
487        printf "%-29s%s\n", "  -r, --release DIRECTORY", "CMSSW release containing ntuple packages";
488      }
489 +  elsif ($command eq "downloadRelease")
490 +    {
491 +      print "Usage: $exeName [OPTION]... downloadRelease NAME\n";
492 +      print "Copies an ntuple release to the current directory on the Tier 3. Optionally\n";
493 +      print "copies the corresponding Python configuration file registered in the database.\n";
494 +      print "\n";
495 +      print "Mandatory arguments to long options are mandatory for short options too.\n";
496 +      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python configuration file name";
497 +    }
498 +  elsif ($command eq "uploadConfig")
499 +    {
500 +      print "Usage: $exeName -p FILE -r DIRECTORY [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";
504 +      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
505 +      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config file";
506 +      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release with which to use this config";
507 +    }
508    else
509      {
510        print "Usage: $exeName [OPTION]... COMMAND NAME\n";
# Line 371 | Line 516 | printHelp
516        print "\n";
517        print "COMMAND may be one of the following:\n";
518        printf "%-29s%s\n", "  create", "creates the entry";
519 +      printf "%-29s%s\n", "  createOther", "creates an entry for non-ntuple data";
520        printf "%-29s%s\n", "  update", "updates the entry";
521        printf "%-29s%s\n", "  finish", "finalizes the database entry";
522        printf "%-29s%s\n", "  deleteEntry", "removes the database entry";
523        printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
524        printf "%-29s%s\n", "  uploadRelease", "upload an ntuple release";
525 +      printf "%-29s%s\n", "  downloadRelease", "download an ntuple release";
526 +      printf "%-29s%s\n", "  uploadConfig", "upload an ntuple config";
527      }
528  
529    exit;
# Line 388 | Line 536 | sizeOfDataset
536    my $location = shift;
537    my $fileList = shift;
538  
391  my $query = "select nFiles from ntuple where dataset='$dataset'";
392  $db->selectdb ("ntuple");
393  my $results = $db->query ($query);
394  my @row = $results->fetchrow ();
395  my $previousNFiles = 0;
396  $previousNFiles = $row[0] if $results->numrows ();
397
539    my $size = 0.0;
540    my $nFiles = 0;
541 <  if ($location && !$fileList && $previousNFiles < 1)
541 >  if ($location && !$fileList)
542      {
543        if (!(-e $location))
544          {
# Line 436 | Line 577 | uploadRelease
577    my $name = shift;
578    my $user = shift;
579    my $comment = shift;
580 +  my $recipeName = shift;
581  
440  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
582    if (!(-e $psetName))
583      {
584        print "$psetName does not exist!\n";
585        exit;
586      }
587 +  if (!(-e $recipeName))
588 +    {
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";
593    open (PY_CONFIG, "<$psetName");
594    my @pset = <PY_CONFIG>;
595    close (PY_CONFIG);
596    my $pset = join ("", @pset);
597 +  open (RECIPE, "<$recipeName");
598 +  my @recipe = <RECIPE>;
599 +  close (RECIPE);
600 +  my $recipe = join ("\n", @recipe);
601  
602    my $query = "select max(id) from ntupleRelease";
603    $db->selectdb ("ntuple");
# Line 461 | Line 612 | uploadRelease
612    $format = addSlashes ($format);
613    $cmsswRelease = addSlashes ($cmsswRelease);
614    $comment = addSlashes ($comment);
615 +  $recipe = addSlashes ($recipe);
616 +
617 +  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')";
618 +  $db->selectdb ("ntuple");
619 +  my $results = $db->query ($query);
620 + }
621 +
622 + sub
623 + downloadRelease
624 + {
625 +  my $release = shift;
626 +  my $pyConfigName = shift;
627 +
628 +  my $query = "select id,pset from ntupleRelease where name='$release'";
629 +  $db->selectdb ("ntuple");
630 +  my $results = $db->query ($query);
631 +  if ($results->numrows () != 1)
632 +    {
633 +      print "Ntuple release \"$release\" not found!\n";
634 +      exit;
635 +    }
636 +  if (!(-e "/home/hart/public_html/releases/$release.tar.gz"))
637 +    {
638 +      print "Release is in the database but no package exists!\n";
639 +      exit;
640 +    }
641 +  if ($pyConfigName)
642 +    {
643 +      my @row = $results->fetchrow ();
644 +      open (PY_CONFIG, ">$pyConfigName");
645 +      print PY_CONFIG $row[1];
646 +      close (PY_CONFIG);
647 +    }
648 +  copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz");
649 + }
650 +
651 + sub
652 + dbOtherCreate
653 + {
654 +  my $userAndHost = shift;
655 +  my $listOfFiles = shift;
656 +  my $comment = shift;
657 +
658 +  my $user = $userAndHost;
659 +  $user =~ s/@.*$//g;
660 +
661 +  my $size = 0.0;
662 +  my $nFiles = 0.0;
663 +  for (my $i = 0; $i < @$listOfFiles; $i++)
664 +    {
665 +      if (!(-e $$listOfFiles[$i]))
666 +        {
667 +          print "$$listOfFiles[$i] does not exist!\n";
668 +          exit;
669 +        }
670 +      $nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`;
671 +      my $fileSize = `du -s $$listOfFiles[$i]`;
672 +      $fileSize =~ s/([^ ]*) .*/$1/;
673 +      $fileSize /= 1024 * 1024;
674 +      $size += $fileSize;
675 +      $$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//);
676 +    }
677 +  $size = sprintf "%.2f", $size;
678 +  my $location = join ("<br />", @$listOfFiles);
679 +
680 +  my $query = "select max(id) from other";
681 +  $db->selectdb ("ntuple");
682 +  my $results = $db->query ($query);
683 +  my @row = $results->fetchrow ();
684 +  my $id = 1;
685 +  $id = $row[0] + 1 if $results->numrows ();
686 +
687 +  $user = addSlashes ($user);
688 +  $location = addSlashes ($location);
689 +  $comment = addSlashes ($comment);
690  
691 <  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')";
691 >  $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$userAndHost', '$user', '$location', $nFiles, $size, '$comment')";
692 >  $db->selectdb ("ntuple");
693 >  $results = $db->query ($query);
694 >
695 >  print "ID $id\n";
696 > }
697 >
698 > sub
699 > uploadConfig
700 > {
701 >  my $name = shift;
702 >  my $user = shift;
703 >  my $psetName = shift;
704 >  my $release = shift;
705 >  my $comment = shift;
706 >
707 >  if (!(-e $psetName))
708 >    {
709 >      print "$psetName does not exist!\n";
710 >      exit;
711 >    }
712 >  if ($release)
713 >    {
714 >      my $query = "select id from ntupleRelease where name='$release'";
715 >      $db->selectdb ("ntuple");
716 >      my $results = $db->query ($query);
717 >      if ($results->numrows () != 1)
718 >        {
719 >          print "Ntuple release \"$release\" not found!\n";
720 >          exit;
721 >        }
722 >    }
723 >  open (PSET, "<$psetName");
724 >  my @pset = <PSET>;
725 >  close (PSET);
726 >  my $pset = join ("", @pset);
727 >
728 >  my $query = "select max(id) from ntupleConfig";
729 >  $db->selectdb ("ntuple");
730 >  my $results = $db->query ($query);
731 >  my @row = $results->fetchrow ();
732 >  my $id = 1;
733 >  $id = $row[0] + 1 if $results->numrows ();
734 >
735 >  $name = addSlashes ($name);
736 >  $user = addSlashes ($user);
737 >  $pset = addSlashes ($pset);
738 >  $release = addSlashes ($release);
739 >  $comment = addSlashes ($comment);
740 >
741 >  my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')";
742 >  $db->selectdb ("ntuple");
743 >  $results = $db->query ($query);
744 > }
745 >
746 > sub
747 > locationExists
748 > {
749 >  my $location = shift;
750 >
751 >  $location =~ s/^(.*)\/+$/$1/;
752 >  my $query = "select id from ntuple where location like '$location%'";
753 >  $db->selectdb ("ntuple");
754 >  my $results = $db->query ($query);
755 >  return 1 if $results->numrows ();
756 >
757 >  if ($location =~ m/^\/store\/.*$/)
758 >    {
759 >      $location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/;
760 >    }
761 >  elsif ($location =~ m/^\/data\/se\/store\/.*$/)
762 >    {
763 >      $location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/;
764 >    }
765 >
766 >  my $query = "select id from ntuple where location like '$location%'";
767    $db->selectdb ("ntuple");
768    my $results = $db->query ($query);
769 +  return 1 if $results->numrows ();
770 +
771 +  return 0;
772   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines