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.3 by ahart, Thu Jun 14 17:42:30 2012 UTC vs.
Revision 1.8 by ahart, Thu Aug 9 06:40:08 2012 UTC

# Line 3 | Line 3
3   use strict;
4   use Mysql;
5   use Getopt::Long;
6 + 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 datasetExists;
16  
17 < our $db;
17 > our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped";
18  
19   my %opt;
20   Getopt::Long::Configure ("bundling");
21 < GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "remoteLocation|r=s", "lumiSummary|s=s", "location|l=s", "help|h");
21 > 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", "help|h");
22   my $argc = @ARGV;
23  
24 < printHelp () if $opt{"help"};
25 < printHelp () if $argc != 2;
26 < printHelp () if $ARGV[0] != "create" && $ARGV[0] != "update" && $ARGV[0] != "finish" && $ARGV[0] != "deprecate";
27 < my $id = -1;
28 < $id = getDataset ($ARGV[1]) if $ARGV[0] ne "create";
29 < $ARGV[0] = "create" if $id < 0;
30 < my $status = "present";
31 < $status = "" if $ARGV[0] eq "update";
32 < $status = "deprecated" if $ARGV[0] eq "deprecate";
33 < $opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"};
34 < dbUpdate ($id, $ARGV[1], $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"remoteLocation"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"});
24 > printHelp ($ARGV[0]) if $opt{"help"};
25 > printHelp () if $argc != 2 && $ARGV[0] ne "createOther";
26 > 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 "deleteEntry";
27 > if ($ARGV[0] eq "create" && datasetExists ($ARGV[1]))
28 >  {
29 >    print "Dataset name already exists in the database!\n";
30 >    exit;
31 >  }
32 > if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"})
33 >  {
34 >    print "The directory containing the ntuples must be given!\n";
35 >    exit;
36 >  }
37 > if ($ARGV[0] eq "uploadRelease" && !$opt{"pyConfig"} && !$opt{"release"})
38 >  {
39 >    print "Both the Python and the CMSSW release must be given!\n";
40 >    exit;
41 >  }
42 > if ($ARGV[0] eq "uploadRelease")
43 >  {
44 >    my $parentDir = "./$opt{'release'}";
45 >    $parentDir =~ s/CMSSW_[^\/]*//g;
46 >    $parentDir =~ s/\/\/*/\//g;
47 >    my $cmsswRelease = $opt{'release'};
48 >    $cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/;
49 >    `tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`;
50 >    $opt{"format"} = "BEAN" if !$opt{"format"};
51 >    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], $ENV{"USER"}, $opt{"comment"});
52 >  }
53 > elsif ($ARGV[0] eq "createOther")
54 >  {
55 >    my @listOfFiles = @ARGV;
56 >    @listOfFiles = reverse (@listOfFiles);
57 >    pop (@listOfFiles);
58 >    @listOfFiles = reverse (@listOfFiles);
59 >    dbOtherCreate ($ENV{"USER"}, \@listOfFiles, $opt{"comment"});
60 >  }
61 > else
62 >  {
63 >    my $id = -1;
64 >    my $fullDataset;
65 >    ($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create" && ($ARGV[0] ne "update" || !$opt{"other"}) && ($ARGV[0] ne "deleteEntry" || !$opt{"other"});
66 >    $id = $ARGV[1] if ($ARGV[0] eq "update" && $opt{"other"}) || ($ARGV[0] eq "deleteEntry" && $opt{"other"});
67 >    $fullDataset = $ARGV[1] if $id < 0;
68 >    $ARGV[0] = "create" if $id < 0;
69 >    my $status = "present";
70 >    $status = "" if $ARGV[0] eq "update";
71 >    $status = "deprecated" if $ARGV[0] eq "deprecate";
72 >    $opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"};
73 >    dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"};
74 >    dbUpdateOther ($id, $opt{"comment"}) if $opt{"other"};
75 >    dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"};
76 >    dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"};
77 >  }
78  
79   sub
80   addSlashes
# Line 43 | Line 92 | addSlashes
92   sub
93   getDataset
94   {
95 +  my $command = shift;
96    my $dataset = shift;
97  
98    my $results;
99    my $queryDataset = $dataset;
100    $queryDataset =~ s/\*/%/g;
101    $queryDataset =~ s/(.*)/%$1%/g;
102 <  $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User");
53 <  my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by lastUpdateTime";
102 >  my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime";
103    $db->selectdb ("ntuple");
104    $results = $db->query ($query);
105    if ($results->numrows () == 1)
106      {
107        my @row = $results->fetchrow ();
108 <      return $row[0];
108 >      return ($row[0], $row[1]);
109      }
110    if ($results->numrows () == 0)
111      {
112 <      print "Database entry does not exist. Create it? (Y/n): ";
113 <      my $response = <STDIN>;
114 <      $response =~ s/\n//g;
115 <      $response = "y" if !$response;
116 <      exit if substr (lc ($response), 0, 1) ne 'y';
117 <      return -1;
112 >      if ($command ne "deleteEntry" && $command ne "deprecate")
113 >        {
114 >          print "Database entry does not exist. Create it? (Y/n): ";
115 >          my $response = <STDIN>;
116 >          $response =~ s/\n//g;
117 >          $response = "y" if !$response;
118 >          exit if substr (lc ($response), 0, 1) ne 'y';
119 >          return (-1, "");
120 >        }
121 >      else
122 >        {
123 >          print "Database entry does not exist.\n";
124 >          exit;
125 >        }
126      }
127 <  my %map;
127 >  my %id;
128 >  my %fullDataset;
129    print "Found multiple database entries matching\n";
130    print "\"$dataset\":\n";
131 <  print "( 0) new\n";
131 >  print "( 0) new\n" if $command ne "deleteEntry" && $command ne "deprecate";
132    for (my $i = 1; $i <= $results->numrows (); $i++)
133      {
134        my @row = $results->fetchrow ();
135 <      $map{"$i"} = $row[0];
135 >      $id{"$i"} = $row[0];
136 >      $fullDataset{"$i"} = $row[1];
137        printf "(%2d) $row[1]\n", $i;
138        print "     created by $row[2] on $row[3]\n";
139      }
140 <  print "\nWhich entry would you like to update? (Select 0 to create a new entry): ";
140 >  print "\nWhich entry would you like to modify?";
141 >  if ($command ne "deleteEntry" && $command ne "deprecate")
142 >    {
143 >      print " (Select 0 to create a new entry): "
144 >    }
145 >  else
146 >    {
147 >      print ": ";
148 >    }
149    my $response = <STDIN>;
150    $response =~ s/[ \t\n]//g;
151 <  return -1 if $response == 0;
152 <  if (!(exists $map{$response}))
151 >  return (-1, "") if $response == 0 && $command ne "deleteEntry" && $command ne "deprecate";
152 >  if (!(exists $id{$response}))
153      {
154        print "Your selection \"$response\" was not a valid option! Quitting.\n";
155        exit;
156      }
157  
158 <  return $map{$response};
158 >  return ($id{$response}, $fullDataset{$response});
159   }
160  
161   sub
# Line 99 | Line 166 | dbUpdate
166    my $user = shift;
167    my $format = shift;
168    my $location = shift;
169 <  my $remoteLocation = shift;
169 >  my $fileListName = shift;
170    my $status = shift;
171    my $comment = shift;
172    my $psetName = shift;
173    my $crabCfgName = shift;
174    my $jsonFileName = shift;
175    my $lumiSummaryName = shift;
176 +  my $release = shift;
177  
178 +  my $fileList;
179    my $pset;
180    my $crabCfg;
181    my $jsonFile;
182    my $lumiSummary;
183    my $size = 0;
184    my $nFiles = 0;
185 +  if ($fileListName)
186 +    {
187 +      if (!(-e $fileListName))
188 +        {
189 +          print "$fileListName does not exist!\n";
190 +          exit;
191 +        }
192 +      open (FILE_LIST, "<$fileListName");
193 +      my @fileList = <FILE_LIST>;
194 +      close (FILE_LIST);
195 +      $fileList = join ("", @fileList);
196 +    }
197    if ($psetName)
198      {
199        if (!(-e $psetName))
# Line 161 | Line 242 | dbUpdate
242        close (LUMI_SUMMARY);
243        $lumiSummary = join ("", @lumiSummary);
244      }
245 <  if ($location)
246 <  {
247 <    if (!(-e $location))
248 <      {
249 <        print "$location does not exist!\n";
250 <        exit;
251 <      }
252 <     $nFiles = `ls $location | wc -l`;
253 <     $size = `du -s $location`;
254 <    $size =~ s/([^ ]*) .*/$1/;
255 <    $size /= 1024 * 1024;
256 <    $size = sprintf "%.2f", $size;
257 <  }
245 >  if ($release)
246 >    {
247 >      my $query = "select id from ntupleRelease where name='$release'";
248 >      $db->selectdb ("ntuple");
249 >      my $results = $db->query ($query);
250 >      if ($results->numrows () != 1)
251 >        {
252 >          print "Ntuple release \"$release\" not found!\n";
253 >          exit;
254 >        }
255 >    }
256 >  ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
257 >  my $fullLocation = $location;
258 >  $fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//);
259  
260    $dataset = addSlashes ($dataset);
261    $user = addSlashes ($user);
# Line 182 | Line 264 | dbUpdate
264    $crabCfg = addSlashes ($crabCfg);
265    $jsonFile = addSlashes ($jsonFile);
266    $lumiSummary = addSlashes ($lumiSummary);
267 <  $location = addSlashes ($location);
268 <  $remoteLocation = addSlashes ($remoteLocation);
267 >  $fullLocation = addSlashes ($fullLocation);
268 >  $fileList = addSlashes ($fileList);
269    $status = addSlashes ($status);
270    $comment = addSlashes ($comment);
271 +  $release = addSlashes ($release);
272  
273    my $results;
274    my $query;
275    if ($id < 0)
276      {
194      $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User");
277        $query = "select max(id) from ntuple";
278        $db->selectdb ("ntuple");
279        $results = $db->query ($query);
# Line 199 | Line 281 | dbUpdate
281        my $id = 1;
282        $id = $row[0] + 1 if $results->numrows ();
283  
284 <      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, remoteLocation, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary) values ($id, '$dataset', now(), now(), '$user', '$format', '$location', '$remoteLocation', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary')";
284 >      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version) values ($id, '$dataset', now(), now(), '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release')";
285      }
286    if ($id > 0)
287      {
# Line 209 | Line 291 | dbUpdate
291        $values .= ", dataset='$dataset'" if $dataset;
292        $values .= ", lastUpdateTime=now()";
293        $values .= ", format='$format'" if $format;
294 <      $values .= ", location='$location'" if $location;
295 <      $values .= ", remoteLocation='$remoteLocation'" if $remoteLocation;
296 <      $values .= ", nFiles=$nFiles" if $location;
297 <      $values .= ", sizeInGB=$size" if $location;
294 >      $values .= ", location='$fullLocation'" if $location;
295 >      $values .= ", fileList='$fileList'" if $fileList;
296 >      $values .= ", nFiles=$nFiles" if $nFiles;
297 >      $values .= ", sizeInGB=$size" if $size;
298        $values .= ", status='$status'" if $status;
299        $values .= ", comment='$comment'" if $comment;
300        $values .= ", pset='$pset'" if $pset;
301        $values .= ", crabCfg='$crabCfg'" if $crabCfg;
302        $values .= ", jsonFile='$jsonFile'" if $jsonFile;
303        $values .= ", lumiSummary='$lumiSummary'" if $lumiSummary;
304 +      $values .= ", version='$release'" if $release;
305  
306        $values =~ s/^, //;
307        $query = "update ntuple set $values where id=$id";
# Line 229 | Line 312 | dbUpdate
312   }
313  
314   sub
315 + dbUpdateOther
316 + {
317 +  my $id = shift;
318 +  my $comment = shift;
319 +
320 +  $comment = addSlashes ($comment);
321 +
322 +  my $query = "update other set lastUpdateTime=now(), comment='$comment'  where id=$id";
323 +  $db->selectdb ("ntuple");
324 +  my $results = $db->query ($query);
325 +
326 +  return $results;
327 + }
328 +
329 + sub
330 + dbDelete
331 + {
332 +  my $id = shift;
333 +
334 +  my $query = "delete from ntuple where id=$id";
335 +  $db->selectdb ("ntuple");
336 +  my $results = $db->query ($query);
337 + }
338 +
339 + sub
340 + dbDeleteOther
341 + {
342 +  my $id = shift;
343 +
344 +  my $query = "delete from other where id=$id";
345 +  $db->selectdb ("ntuple");
346 +  my $results = $db->query ($query);
347 + }
348 +
349 + sub
350   printHelp
351   {
352 +  my $command = shift;
353 +
354    my $exeName = $0;
355    $exeName =~ s/^.*\/([^\/]*)$/$1/;
356  
357 <  print "Usage: $exeName [OPTION]... COMMAND DATASET\n";
358 <  print "Manipulates entries in the OSU Tier 3 ntuple database.\n";
359 <  print "\n";
360 <  print "Mandatory arguments to long options are mandatory for short options too.\n";
361 <  printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config file used to submit the ntuple jobs";
362 <  printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for this database entry";
363 <  printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
364 <  printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used to ntuplize the dataset";
365 <  printf "%-29s%s\n", "  -h, --help", "print this help message";
366 <  printf "%-29s%s\n", "  -l, --location DIRECTORY", "location on the Tier 3";
367 <  printf "%-29s%s\n", "  -p, --pyConfig FILE", "python config used to ntuplize the dataset";
368 <  printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json returned by CRAB";
369 <  print "\n";
370 <  print "COMMAND may be one of the following:\n";
371 <  printf "%-29s%s\n", "  create", "creates the entry (assumes the dataset is present)";
372 <  printf "%-29s%s\n", "  update", "updates the entry";
373 <  printf "%-29s%s\n", "  finish", "finalizes the database entry";
374 <  printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
357 >  if ($command eq "create")
358 >    {
359 >      print "Usage: $exeName -l DIRECTORY [OPTION]... create NAME\n";
360 >      print "Creates an entry in the database for dataset NAME. The ntuples are assumed to\n";
361 >      print "be present on the Tier 3, with the status being set accordingly.\n";
362 >      print "\n";
363 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
364 >      printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
365 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
366 >      printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
367 >      printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
368 >      printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
369 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
370 >      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
371 >      printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
372 >    }
373 >  elsif ($command eq "createOther")
374 >    {
375 >      print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n";
376 >      print "Creates an entry in the database for non-ntuple data.\n";
377 >      print "\n";
378 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
379 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
380 >    }
381 >  elsif ($command eq "update")
382 >    {
383 >      print "Usage: $exeName [OPTION]... update NAME\n";
384 >      print "Updates an existing database entry for dataset NAME.\n";
385 >      print "\n";
386 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
387 >      printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
388 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
389 >      printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format";
390 >      printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
391 >      printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
392 >      printf "%-29s%s\n", "  -o, --other", "update an entry in the non-ntuple database";
393 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
394 >      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
395 >      printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
396 >    }
397 >  elsif ($command eq "finish")
398 >    {
399 >      print "Usage: $exeName -l DIRECTORY finish NAME\n";
400 >
401 >      print "Finalizes the database entry for dataset NAME, changing its status to\n";
402 >      print "\"present\".  This is intended to be the final step in command-line based ntuple\n";
403 >      print "production.\n";
404 >      print "\n";
405 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
406 >      printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
407 >    }
408 >  elsif ($command eq "deleteEntry")
409 >    {
410 >      print "Usage: $exeName [OPTION]... deleteEntry NAME\n";
411 >      print "Deletes the database entry for dataset NAME. This is intended primarily for\n";
412 >      print "mistaken database entries. If you wish to actually delete a set of ntuples,\n";
413 >      print "please use the \"deprecate\" command instead.\n";
414 >      print "\n";
415 >      printf "%-29s%s\n", "  -o, --other", "update an entry in the non-ntuple database";
416 >    }
417 >  elsif ($command eq "deprecate")
418 >    {
419 >      print "Usage: $exeName deprecate NAME\n";
420 >      print "Marks the dataset NAME for deletion. WARNING: The dataset will be deleted from\n";
421 >      print "the Tier 3 within one week of this action. If you wish to simply delete a\n";
422 >      print "mistaken database entry, use the \"deleteEntry\" command instead.\n";
423 >    }
424 >  elsif ($command eq "uploadRelease")
425 >    {
426 >      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
427 >      print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n";
428 >      print "database entry for it, with NAME being the name of the release. An ntuple\n";
429 >      print "release is a CMSSW release with all the necessary packages added for creating\n";
430 >      print "ntuples, along with a default Python config file.\n";
431 >      print "\n";
432 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
433 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
434 >      printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
435 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "default Python config for the release";
436 >      printf "%-29s%s\n", "  -r, --release DIRECTORY", "CMSSW release containing ntuple packages";
437 >    }
438 >  else
439 >    {
440 >      print "Usage: $exeName [OPTION]... COMMAND NAME\n";
441 >      print "Manipulates entry in the OSU Tier 3 ntuple database given by NAME.\n";
442 >      print "\n";
443 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
444 >      printf "%-29s%s\n", "  -h, --help", "print help. If COMMAND is present, print help";
445 >      printf "%-29s%s\n", " ", "specific to COMMAND.";
446 >      print "\n";
447 >      print "COMMAND may be one of the following:\n";
448 >      printf "%-29s%s\n", "  create", "creates the entry";
449 >      printf "%-29s%s\n", "  create", "creates an entry for non-ntuple data";
450 >      printf "%-29s%s\n", "  update", "updates the entry";
451 >      printf "%-29s%s\n", "  finish", "finalizes the database entry";
452 >      printf "%-29s%s\n", "  deleteEntry", "removes the database entry";
453 >      printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
454 >      printf "%-29s%s\n", "  uploadRelease", "upload an ntuple release";
455 >    }
456  
457    exit;
458   }
459 +
460 + sub
461 + sizeOfDataset
462 + {
463 +  my $dataset = shift;
464 +  my $location = shift;
465 +  my $fileList = shift;
466 +
467 +  my $size = 0.0;
468 +  my $nFiles = 0;
469 +  if ($location && !$fileList)
470 +    {
471 +      if (!(-e $location))
472 +        {
473 +          print "$location does not exist!\n";
474 +          exit;
475 +        }
476 +      $nFiles = `ls $location | wc -l`;
477 +      $size = `du -s $location`;
478 +      $size =~ s/([^ ]*) .*/$1/;
479 +      $size /= 1024 * 1024;
480 +      $size = sprintf "%.2f", $size;
481 +    }
482 +  elsif ($fileList)
483 +    {
484 +      foreach my $file (split (/\n/, $fileList))
485 +        {
486 +          $nFiles++;
487 +          my $fileSize = `du -s $file`;
488 +          $fileSize =~ s/([^ ]*) .*/$1/;
489 +          $size += $fileSize;
490 +        }
491 +      $size /= 1024 * 1024;
492 +      $size = sprintf "%.2f", $size;
493 +    }
494 +
495 +  return ($nFiles, $size);
496 + }
497 +
498 + sub
499 + uploadRelease
500 + {
501 +  my $format = shift;
502 +  my $cmsswRelease = shift;
503 +  my $release = shift;
504 +  my $psetName = shift;
505 +  my $name = shift;
506 +  my $user = shift;
507 +  my $comment = shift;
508 +
509 +  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
510 +  if (!(-e $psetName))
511 +    {
512 +      print "$psetName does not exist!\n";
513 +      exit;
514 +    }
515 +  open (PY_CONFIG, "<$psetName");
516 +  my @pset = <PY_CONFIG>;
517 +  close (PY_CONFIG);
518 +  my $pset = join ("", @pset);
519 +
520 +  my $query = "select max(id) from ntupleRelease";
521 +  $db->selectdb ("ntuple");
522 +  my $results = $db->query ($query);
523 +  my @row = $results->fetchrow ();
524 +  my $id = 1;
525 +  $id = $row[0] + 1 if $results->numrows ();
526 +
527 +  $name = addSlashes ($name);
528 +  $pset = addSlashes ($pset);
529 +  $user = addSlashes ($user);
530 +  $format = addSlashes ($format);
531 +  $cmsswRelease = addSlashes ($cmsswRelease);
532 +  $comment = addSlashes ($comment);
533 +
534 +  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')";
535 +  $db->selectdb ("ntuple");
536 +  my $results = $db->query ($query);
537 + }
538 +
539 + sub
540 + datasetExists
541 + {
542 +  my $dataset = shift;
543 +
544 +  my $query = "select id from ntuple where dataset='$dataset'";
545 +  $db->selectdb ("ntuple");
546 +  my $results = $db->query ($query);
547 +
548 +  return $results->numrows ();
549 + }
550 +
551 + sub
552 + dbOtherCreate
553 + {
554 +  my $user = shift;
555 +  my $listOfFiles = shift;
556 +  my $comment = shift;
557 +
558 +  my $size = 0.0;
559 +  my $nFiles = 0.0;
560 +  for (my $i = 0; $i < @$listOfFiles; $i++)
561 +    {
562 +      if (!(-e $$listOfFiles[$i]))
563 +        {
564 +          print "$$listOfFiles[$i] does not exist!\n";
565 +          exit;
566 +        }
567 +      $nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`;
568 +      my $fileSize = `du -s $$listOfFiles[$i]`;
569 +      $fileSize =~ s/([^ ]*) .*/$1/;
570 +      $fileSize /= 1024 * 1024;
571 +      $size += $fileSize;
572 +      $$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//);
573 +    }
574 +  $size = sprintf "%.2f", $size;
575 +  my $location = join ("<br />", @$listOfFiles);
576 +
577 +  my $query = "select max(id) from other";
578 +  $db->selectdb ("ntuple");
579 +  my $results = $db->query ($query);
580 +  my @row = $results->fetchrow ();
581 +  my $id = 1;
582 +  $id = $row[0] + 1 if $results->numrows ();
583 +
584 +  $user = addSlashes ($user);
585 +  $location = addSlashes ($location);
586 +  $comment = addSlashes ($comment);
587 +
588 +  my $query = "insert into other (id, creationTime, lastUpdateTime, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$location', $nFiles, $size, '$comment')";
589 +  $db->selectdb ("ntuple");
590 +  my $results = $db->query ($query);
591 +
592 +  print "ID $id\n";
593 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines