-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckBeamtimeFiles.pl
executable file
·76 lines (69 loc) · 1.98 KB
/
CheckBeamtimeFiles.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use Data::Dumper;
die "Please provide beamtime folders as arguments" if @ARGV == 0;
&main;
sub main {
foreach my $dir (@ARGV) {
unless(-d $dir) {
print "Skipping $dir, not a directory\n";
}
WorkOnDir($dir);
}
}
sub WorkOnDir {
my $dir = shift;
my $md5sum_file = "$dir/MD5SUM";
my %MD5SUM;
if (-f $md5sum_file) {
open(my $fh, "<$md5sum_file") or die "Can't open $md5sum_file: $!";
%MD5SUM = map {$_=~ s/^(.+?) (.+?)\n$/$2/; $_ => 1 } <$fh>;
close $fh;
}
my %rundata; # should have an xz/gz, and xml. and maybe dat
my @otherfiles;
while (glob("$dir/*")) {
my $file = (fileparse($_, '\..*'))[0]; # naked filename
my $ext = (fileparse($_, '\.[^.]*'))[2]; # very last extension
$ext =~ s/\.gz/\.xz/;
if ($ext =~ /^\.(dat|xz|xml)$/) {
$rundata{$file}->{$ext}++;
if ($ext eq '.xz' && exists $MD5SUM{basename($_)}) {
$rundata{$file}->{'md5sum'}++;
}
} elsif ($_ ne $md5sum_file) {
push(@otherfiles, "'$_'");
}
}
my %n = ();
foreach my $r (keys %rundata) {
if (exists $rundata{$r}->{'.xml'} &&
exists $rundata{$r}->{'.xz'} &&
exists $rundata{$r}->{'md5sum'}) {
$n{complete}++;
if (exists $rundata{$r}->{'.dat'}) {
$n{original}++;
}
} elsif (!exists $rundata{$r}->{'.xml'} &&
!exists $rundata{$r}->{'.xz'} &&
!exists $rundata{$r}->{'md5sum'} &&
exists $rundata{$r}->{'.dat'}) {
$n{uncompressed}++;
} elsif (!exists $rundata{$r}->{'.xml'} &&
exists $rundata{$r}->{'.xz'} &&
exists $rundata{$r}->{'md5sum'}) {
$n{nometadata}++;
}
else {
push(@otherfiles, "'$dir/".$r.".*'");
}
}
print "$dir\t ", join(', ', map {"$n{$_} $_"} sort keys %n),"\n";
if (@otherfiles>0) {
print 'Other files: ', join(' ',@otherfiles), "\n";
}
#print Dumper(\%rundata);
#print Dumper(\@otherfiles);
}