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

Comparing UserCode/OSUT3Analysis/DBTools/scripts/crabclean (file contents):
Revision 1.9 by ahart, Wed Aug 7 18:46:11 2013 UTC vs.
Revision 1.10 by ahart, Wed Aug 7 23:55:28 2013 UTC

# Line 12 | Line 12 | our $db = Mysql->connect ("cmshead.mps.o
12  
13   my %opt;
14   Getopt::Long::Configure ("bundling");
15 < GetOptions (\%opt, "dumb|d", "force|f", "destination|o=s", "dataset|s", "help|h");
15 > GetOptions (\%opt, "dumb|d", "force|f", "destination|o=s", "print|p", "dataset|s", "help|h");
16  
17 < printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$opt{"dataset"} && !$ARGV[1]);
17 > printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$opt{"dataset"} && !$opt{"print"} && !$ARGV[1]);
18   my $crabDir = $ARGV[0];
19   my $outputDir = $ARGV[0];
20   my $dataset = $ARGV[0];
# Line 65 | Line 65 | if ($opt{"dataset"})
65        }
66    }
67  
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);
68 > die "Output directory does not exist, stopped" if !$opt{"print"} && (!(-e $outputDir) || !(-d $outputDir));
69 > my @crabOutput;
70 > if (!$opt{"print"})
71 >  {
72 >    opendir (CRAB_OUTPUT, "$outputDir");
73 >    @crabOutput = readdir (CRAB_OUTPUT);
74 >    closedir (CRAB_OUTPUT);
75 >  }
76   my %filesToKeep;
77   if (!$opt{"dumb"})
78    {
# Line 100 | Line 104 | if ($opt{"destination"})
104      close (TEST_FILE);
105      unlink "$opt{'destination'}/.crabCleanTest";
106    }
107 < opendir (CRAB_OUTPUT, "$outputDir");
108 < my @crabOutput = readdir (CRAB_OUTPUT);
109 < closedir (CRAB_OUTPUT);
110 < my $nFiles = @crabOutput - 2;
111 < print "Before cleaning: $nFiles files\n";
107 > if (!$opt{"print"})
108 >  {
109 >    opendir (CRAB_OUTPUT, "$outputDir");
110 >    my @crabOutput = readdir (CRAB_OUTPUT);
111 >    closedir (CRAB_OUTPUT);
112 >    my $nFiles = @crabOutput - 2;
113 >    print "Before cleaning: $nFiles files\n";
114 >  }
115   foreach my $file (@crabOutput)
116    {
117      next if ($file eq "." || $file eq "..");
# Line 119 | Line 126 | foreach my $file (@crabOutput)
126        }
127      elsif ((($opt{"dumb"} && $filesToKeep{$jobNumber} != $submissionNumber)
128          || (!$opt{"dumb"} && $filesToKeep{$jobNumber} ne $file))
129 <        && !$opt{"destination"})
129 >        && !$opt{"destination"} && !$opt{"print"})
130        {
131          system ("rm -f $outputDir/$file") if $opt{"force"};
132          system ("rm -i $outputDir/$file") if !$opt{"force"};
133        }
134      elsif ((($opt{"dumb"} && $filesToKeep{$jobNumber} == $submissionNumber)
135          || (!$opt{"dumb"} && $filesToKeep{$jobNumber} eq $file))
136 <        && $opt{"destination"})
136 >        && $opt{"destination"} && !$opt{"print"})
137        {
138          system ("mv -f $outputDir/$file $opt{'destination'}/$file") if $opt{"force"};
139          system ("mv -i $outputDir/$file $opt{'destination'}/$file") if !$opt{"force"};
140        }
141    }
142 < opendir (CRAB_OUTPUT, "$outputDir");
143 < my @crabOutput = readdir (CRAB_OUTPUT);
144 < closedir (CRAB_OUTPUT);
145 < opendir (CRAB_OUTPUT, "$opt{'destination'}");
146 < my @crabOutputInDestination = readdir (CRAB_OUTPUT);
147 < closedir (CRAB_OUTPUT);
148 < my $nFiles = @crabOutput - 2;
149 < $nFiles = @crabOutputInDestination - 2 if $opt{"destination"};
150 < print "After cleaning:  $nFiles files\n";
142 > if (!$opt{"print"})
143 >  {
144 >    opendir (CRAB_OUTPUT, "$outputDir");
145 >    my @crabOutput = readdir (CRAB_OUTPUT);
146 >    closedir (CRAB_OUTPUT);
147 >    opendir (CRAB_OUTPUT, "$opt{'destination'}");
148 >    my @crabOutputInDestination = readdir (CRAB_OUTPUT);
149 >    closedir (CRAB_OUTPUT);
150 >    my $nFiles = @crabOutput - 2;
151 >    $nFiles = @crabOutputInDestination - 2 if $opt{"destination"};
152 >    print "After cleaning:  $nFiles files\n";
153 >  }
154 > else
155 >  {
156 >    foreach my $file (keys %filesToKeep)
157 >      {
158 >        print $filesToKeep{$file} . "\n";
159 >      }
160 >  }
161  
162   sub
163   printHelp
# Line 150 | Line 167 | printHelp
167  
168    print "Usage: $exeName [OPTION]... CRAB_DIR OUTPUT_DIR\n";
169    print "  or: $exeName -d [OPTION]... OUTPUT_DIR\n";
170 +  print "  or: $exeName -p [OPTION]... CRAB_DIR\n";
171    print "  or: $exeName -s [OPTION]... DATASET\n";
172    print "Deletes excess EDM output caused by multiple CRAB submissions using the results\n";
173    print "contained in the CRAB working directory provided.\n";
# Line 163 | Line 181 | printHelp
181    printf "%-29s%s\n", "  -h, --help", "print this help message";
182    printf "%-29s%s\n", "  -o, --destination DIR", "do not remove excess output and move the good files";
183    printf "%-29s%s\n", " ", "to DIR";
184 +  printf "%-29s%s\n", "  -p, --print", "do not remove any files, just print the names of";
185 +  printf "%-29s%s\n", " ", "the good files to the screen";
186    printf "%-29s%s\n", "  -s, --dataset", "tells the script to expect a dataset name instead";
187    printf "%-29s%s\n", "               ", "of a directory";
188  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines