script/checkm

filter: Statementstmt 83.1% 69 / 83 Branchbran 43.1% 19 / 44 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 10 / 12 Podpod n/a totaltotal 66.8% 101 / 151 CC 3 SCAR 6.6
CC
3
Cov
67%
do_help
6.0
do_over
2.0
help
2.0
CRAP 1.9
« lib/File/Checkm.pm ↑ Summary
1 #!/usr/local/bin/perl
2  
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 my $VERSION = $File::Checkm::VERSION;
8  
9 6 ▶use File::Checkm;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 #use File::OM;
13  
14 6 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 # this :config allows -h24w80 for '‐h 24 ‐w 80', -vax for --vax or --Vax
16 6 ▶use Getopt::Long qw(:config bundling_override);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 my $dir; # global defining our directory
19 6 my $M = $File::Checkm::manfilename;
20  
21 #my $om; # output multiplexer routine
22 6 my %o; # global to communicate options to module
23  
24 6 my %opt = (
25 algorithm => 0,
26 alg => 0, # non-command-line option
27 cols => 0,
28 digest => 0, # non-command-line option
29 digester => 0, # non-command-line option
30 directory => 0,
31 fieldscount => 0, # non-command-line option
32 force => 0,
33 format => 0,
34 help => 0,
35 man => 0,
36 mani_digester => 0, # non-command-line option
37 mtime => 0, # non-command-line option
38 om => 0, # non-command-line option
39 output => 0,
40 preventlinks => 0,
41 size => 0, # non-command-line option
42 temper => 0,
43 version => 0,
44 verbose => 0,
45 );
46 # We piggyback more than just command-line options in the %opt hash,
47 # so be careful not to collide with non-command-line options.
48  
49 # xxx for 'pt', add -P option and make lstree*s* similar to Checkm.pm
50 # xxx make 'snag' version recognize number to left of suffix, eg,
51 # "snag --mknext manifest1.txt"; also,
52 # "snag --mknext v1/manifest.txt" ?? (up the dir number?)
53 # "checkm over > `snag --mknext manifest1.txt`" should work
54 # also, convert? options to commands, eg,
55 # $ snag next manifest1.txt
56 # $ snag highest manifest1.txt
57 # $ snag lowest manifest1.txt
58  
59 # main
60 {
61 6 ▶ GetOptions(\%opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%opt, "algorithm|a=s", "cols|c=s", "directory|d=s", "force|f", "format|m=s", "help|h|?", "output|o=s", "man", "preventlinks|P", "temper", "version", "verbose|v") or pod2usage("-exitstatus", 2, "-verbose", 1) 6 0 6
62 'algorithm|a=s',
63 'cols|c=s',
64 'directory|d=s',
65 'force|f',
66 'format|m=s',
67 'help|h|?',
68 'output|o=s',
69 'man',
70 'preventlinks|P',
71 'temper',
72 'version',
73 'verbose|v',
74 )
75 or pod2usage(-exitstatus => 2, -verbose => 1);
76  
77 6 ▶ $opt{help} and help(), exit(0);
Branch: 1 branch
BranchTrueFalseTotal
$opt{"help"} and help(), exit 0 0 6 6
78 6 ▶ $opt{man} and pod2usage(-exitstatus => 0, -verbose => 2);
Branch: 1 branch
BranchTrueFalseTotal
$opt{"man"} and pod2usage("-exitstatus", 0, "-verbose", 2) 0 6 6
79 6 ▶ $opt{version} and print("$VERSION\n"), exit(0);
Branch: 1 branch
BranchTrueFalseTotal
$opt{"version"} and print("$VERSION\n"), exit 0 1 5 6
80  
81 5 ▶ my $format = $opt{format} || 'Plain'; # given format name
Condition50%1/2
$opt{'format'} || 'Plain'
l!l
05
MC/DC0%0/1
$opt{'format'} || 'Plain'
$opt{'format'}
Truth table50%1/2
A
A= $opt{'format'}
Aresult
11
00
82 5 my %om_opt = (
83 outhandle => *STDOUT,
84 );
85 #$om = File::OM->new($format, \%om_opt) or
86 # pod2usage("$0: unknown format: $format");
87 #$opt{om} = $om;
88  
89 5 ▶ my $cols = $opt{cols} ||= "fadsm";
Condition50%1/2
$opt{"cols"} ||= "fadsm"
l!l
05
MC/DC0%0/1
$opt{"cols"} ||= "fadsm"
$opt{"cols"}
Truth table50%1/2
A
A= $opt{"cols"}
Aresult
11
00
90 5 my $fields = 0; # number of fields to do
91 5 ▶ $cols =~ s/f// and $fields++, $opt{fname} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$cols =~ s/f// and ++$fields, $opt{"fname"} = 1 5 0 5
92 5 ▶ $cols =~ s/a// and $fields++, $opt{aname} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$cols =~ s/a// and ++$fields, $opt{"aname"} = 1 5 0 5
93 5 ▶ $cols =~ s/d// and $fields++, $opt{digest} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$cols =~ s/d// and ++$fields, $opt{"digest"} = 1 5 0 5
94 5 ▶ $cols =~ s/s// and $fields++, $opt{size} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$cols =~ s/s// and ++$fields, $opt{"size"} = 1 5 0 5
95 5 ▶ $cols =~ s/m// and $fields++, $opt{mtime} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$cols =~ s/m// and ++$fields, $opt{"mtime"} = 1 5 0 5
96 5 $opt{fieldscount} = $fields;
97 5 ▶ $cols =~ /[^-]/ and # warn if $cols isn't a "-"
Branch: 1 branch
BranchTrueFalseTotal
$cols =~ /[^-]/ and print STDERR "warning: extra characters ($cols) after --cols\n" 0 5 5
98 print STDERR "warning: extra characters ($cols) after --cols\n";
99  
100 5 my @algs_to_try = ("SHA-256", "MD5"); # default list
101 5 ▶ if ($opt{algorithm} eq "-") { # '-' means our current best idea of
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{'algorithm'} eq '-') { } 0 5 5
elsif ($opt{'algorithm'}) { } 0 5 5
102 0 @algs_to_try = ("MD5"); # most widely available single alg
103 0 $opt{algorithm} = 0; # triggers defaulting code below
104 }
105 elsif ($opt{algorithm}) { # if user specified something
106 # XXXX let user specify comma-separated list of algs?
107 0 @algs_to_try = split(',', $opt{algorithm});
108 }
109 5 my $digester;
110 5 for my $alg (@algs_to_try) {
111 5 $opt{algorithm} = uc $alg;
112 5 $digester = File::Checkm::make_digester($opt{algorithm});
113 5 ▶ $digester and last;
Branch: 1 branch
BranchTrueFalseTotal
$digester and last 5 0 5
114 }
115 5 ▶ unless ($digester) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($digester) 0 5 5
116 0 ▶ my $exitcode = $opt{algorithm} =~ /list|help/i ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'algorithm'} =~ /list|help/i ? : 0 0 0
117 0 ▶ my $FH = $exitcode ? *STDERR : *STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
$exitcode ? : 0 0 0
118 0 ▶ $exitcode and print $FH
Branch: 2 branches
BranchTrueFalseTotal
$exitcode and print $FH join(", ", @algs_to_try), ": digest algorithm", @algs_to_try == 1 ? "" : "s", " not found\n" 0 0 0
@algs_to_try == 1 ? : 0 0 0
119 join(", ", @algs_to_try), ": digest algorithm",
120 (@algs_to_try == 1 ? "" : "s"), " not found\n";
121 0 print $FH "Algorithms that seem to be installed:\n";
122 0 print $FH join("\n", File::Checkm::list_digesters()), "\n";
123 0 exit $exitcode;
124 }
125 5 $opt{digester} = $digester; # main content digester
126 $opt{mani_digester} = # manifest digester
127 5 ▶ File::Checkm::make_digester($opt{algorithm}) or
Branch: 1 branch
BranchTrueFalseTotal
$opt{"mani_digester"} = File::Checkm::make_digester($opt{"algorithm"}) or print STDERR "Couldn't create manifest digester: $!\n" 5 0 5
128 print STDERR "Couldn't create manifest digester: $!\n";
129 # XXX what if mani_digester can't be created? what if it's
130 # different from the regular digester?
131 5 $opt{alg} = lc $opt{algorithm};
132 5 $opt{alg} =~ tr/-//d;
133  
134 5 my $cmd = shift @ARGV;
135 5 ▶ defined($cmd) or help(), exit(1);
Branch: 1 branch
BranchTrueFalseTotal
defined $cmd or help(), exit 1 5 0 5
136 5 $cmd = "do_" . lc($cmd);
137 5 ▶ defined(&$cmd) or pod2usage("$0: unknown command: $cmd");
Branch: 1 branch
BranchTrueFalseTotal
defined &$cmd or pod2usage("$0: unknown command: $cmd") 5 0 5
138  
139 # Which directory or file?
140 #
141 5 ▶ $dir = $opt{directory} || ".";
Condition50%1/2
$opt{'directory'} || '.'
l!l
50
MC/DC0%0/1
$opt{'directory'} || '.'
$opt{'directory'}
Truth table50%1/2
A
A= $opt{'directory'}
Aresult
11
00
142  
143 6 ▶ no strict 'refs'; # permits the next call
Subroutine BEGIN: called CC=1 SCAR=0.0
144 #exit &$cmd(@ARGV);
145 5 my $ret = &$cmd(@ARGV);
146 #print "ret=$ret\n";
147 5 exit $ret;
148 }
149  
150 #######################
151 #
152 # Command functions.
153 #
154  
155 0 ▶sub do_help { my( $topic )=@_;
Subroutine do_help: not called CC=2 SCAR=17.9
156  
157 0 ▶ $topic ||= "";
Condition0%0/2
$topic ||= ""
l!l
00
MC/DC0%0/1
$topic ||= ""
$topic
Truth table0%0/2
A
A= $topic
Aresult
11
00
158 0 pod2usage(-exitstatus => 0, -verbose => 2)
159 #return print "XXX place holder for help on $topic\n";
160 }
161  
162 5 ▶sub do_over { my( @trees )=@_;
Subroutine do_over: called CC=2 SCAR=7.1
163  
164 5 ▶ scalar(@trees) == 0 and
Branch: 1 branch
BranchTrueFalseTotal
scalar @trees == 0 and push @trees, $dir 0 5 5
165 push(@trees, $dir); # default if no args
166  
167 #$o{om} = $om;
168 #$o{algorithm} = $opt{algorithm};
169 #$o{alg} = $opt{alg};
170 #$o{force} = $opt{force};
171 #$o{digest} = $opt{digest};
172 #$o{size} = $opt{size};
173 #$o{mtime} = $opt{mtime};
174 #$o{fieldscount} = $opt{fieldscount};
175  
176 # optional 3rd arg is &visit function to use instead
177  
178 #return File::Checkm::checkm_trees(\@trees, \%o);
179 5 return File::Checkm::checkm_trees(\@trees, \%opt);
180 }
181  
182 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
183 0 print << 'EOI';
184  
185 checkm - create a checkm manifest
186  
187 checkm [opts] over [name ...] # create manifest for named files/dirs
188  
189 The checkm command takes one subcommand (currently), "over", that writes
190 a Checkm file manifest to the standard output computed over all files and
191 directories (recursively) given as arguments, or the current directory by
192 default. On platforms that support them, symbolic links are followed unless
193 you use -P to prevent it. Normally each file produces five Checkm fields,
194  
195 filename | algorithm | digest | size | modtime
196  
197 Use -c (--cols) to select only desired fields, designated by first letter.
198 The default field set corresponds to "-c fadsm" and "-c -" asks checkm to
199 compute no per-file digests, the most useful output then being the final
200 octet/file count summary (oxum).
201  
202 Options examples:
203 -a <algorithm> use given digest algorithm (SHA-256 default, or MD5)
204 -a list list digest algorithms installed on your platform
205 -c fad produce only the first 3 fields
206 -c fs produce only fields 1 and 4
207 -v be verbose with errors
208 -h print this help text
209 EOI
210  
211 0 return 1;
212 #checkm - verify and transfer files with a checkm manifest
213 #
214 # checkm [opts] over [fdir ...] # compute manifest for named files/dirs
215 #
216 # checkm [opts] in [manifest ...] # verify one or more manifests
217 # checkm [opts] out [manifest [file ...] # write a manifest given files
218 # checkm [opts] to remote [manifest] # copy files to remote location
219 # checkm [opts] from remote [manifest] # copy files from remote location
220 }
221  
222 # XXX get consistent with return status
223  
224 __END__
« lib/File/Checkm.pm ↑ Summary