ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/crabclean
Revision: 1.1
Committed: Mon Aug 27 18:02:03 2012 UTC (12 years, 8 months ago) by ahart
Branch: MAIN
CVS Tags: V00-00-04
Log Message:
First commit of crabclean.

File Contents

# Content
1 #!/usr/bin/env perl
2
3 use strict;
4 use Getopt::Long;
5
6 my %opt;
7 Getopt::Long::Configure ("bundling");
8 GetOptions (\%opt, "force|f", "help|h");
9
10 printHelp () if $opt{"help"} || !$ARGV[0];
11 opendir (CRAB_OUTPUT, "$ARGV[0]");
12 my @crabOutput = readdir (CRAB_OUTPUT);
13 closedir (CRAB_OUTPUT);
14 my %filesToKeep;
15 foreach my $file (@crabOutput)
16 {
17 next if ($file eq "." || $file eq "..");
18 next if !($file =~ m/^.*_[^_]*_[^_]*_[^_]*\.root$/);
19 my $jobNumber = $file;
20 my $submissionNumber = $file;
21 $jobNumber =~ s/^.*_([^_]*)_[^_]*_[^_]*\.root$/$1/;
22 $submissionNumber =~ s/^.*_[^_]*_([^_]*)_[^_]*\.root$/$1/;
23 if (!(defined $filesToKeep{$jobNumber})
24 || $filesToKeep{$jobNumber} < $submissionNumber)
25 {
26 $filesToKeep{$jobNumber} = $submissionNumber;
27 }
28 }
29 foreach my $file (@crabOutput)
30 {
31 next if ($file eq "." || $file eq "..");
32 next if !($file =~ m/^.*_[^_]*_[^_]*_[^_]*\.root$/);
33 my $jobNumber = $file;
34 my $submissionNumber = $file;
35 $jobNumber =~ s/^.*_([^_]*)_[^_]*_[^_]*\.root$/$1/;
36 $submissionNumber =~ s/^.*_[^_]*_([^_]*)_[^_]*\.root$/$1/;
37 if ($filesToKeep{$jobNumber} != $submissionNumber)
38 {
39 system ("rm -f $ARGV[0]/$file") if $opt{"force"};
40 system ("rm -i $ARGV[0]/$file") if !$opt{"force"};
41 }
42 }
43
44 sub
45 printHelp
46 {
47 my $exeName = $0;
48 $exeName =~ s/^.*\/([^\/]*)$/$1/;
49
50 print "Usage: $exeName [OPTION]... DIRECTORIES\n";
51 print "Deletes excess EDM output caused by multiple CRAB submissions.\n";
52 print "\n";
53 print "Mandatory arguments to long options are mandatory for short options too.\n";
54 printf "%-29s%s\n", " -f, --force", "never prompt (default is to prompt before any";
55 printf "%-29s%s\n", " ", "removal)";
56 printf "%-29s%s\n", " -h, --help", "print this help message";
57
58 exit;
59 }