| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | # xxx list dir_types | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | # xxx convert all module version numbers | ||||||||||||||||||||||||||||||
| 6 | # use hg keywords (?) | ||||||||||||||||||||||||||||||
| 7 | # equivalent | ||||||||||||||||||||||||||||||
| 8 | # decimal zero-padded dotted-decimal | ||||||||||||||||||||||||||||||
| 9 | # ------- ----------- -------------- | ||||||||||||||||||||||||||||||
| 10 | # 1.2 1.200 v1.200.0 | ||||||||||||||||||||||||||||||
| 11 | # 1.02 1.020 v1.20.0 | ||||||||||||||||||||||||||||||
| 12 | # 1.002 1.002 v1.2.0 | ||||||||||||||||||||||||||||||
| 13 | # 1.0023 1.002300 v1.2.300 | ||||||||||||||||||||||||||||||
| 14 | # 1.00203 1.002030 v1.2.30 | ||||||||||||||||||||||||||||||
| 15 | # 1.002003 1.002003 v1.2.3 | ||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use 5.006; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 23 | my $VERSION = $File::Namaste::VERSION; | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 23 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | # this :config allows -h24w80 for '‐h 24 ‐w 80', -vax for --vax or --Vax | ||||||||||||||||||||||||||||||
| 25 | 23 | ▶ | use Getopt::Long qw(:config bundling_override); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | 23 | ▶ | use File::Namaste ':all'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 28 | 23 | ▶ | use File::OM; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | 23 | my %opt = ( | |||||||||||||||||||||||||||||
| 31 | portable => undef, # NOT 0 because Namaste.pm does | ||||||||||||||||||||||||||||||
| 32 | # if defined(...) to check if $portable_default applies | ||||||||||||||||||||||||||||||
| 33 | help => 0, | ||||||||||||||||||||||||||||||
| 34 | man => 0, | ||||||||||||||||||||||||||||||
| 35 | version => 0, | ||||||||||||||||||||||||||||||
| 36 | directory => 0, | ||||||||||||||||||||||||||||||
| 37 | format => 0, | ||||||||||||||||||||||||||||||
| 38 | verbose => 0, | ||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | # main | ||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||
| 43 | 23 | ▶ | GetOptions(\%opt, | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 44 | 'portable', | ||||||||||||||||||||||||||||||
| 45 | 'help|?', | ||||||||||||||||||||||||||||||
| 46 | 'man', | ||||||||||||||||||||||||||||||
| 47 | 'version', | ||||||||||||||||||||||||||||||
| 48 | 'format|m=s', | ||||||||||||||||||||||||||||||
| 49 | 'directory|d=s', | ||||||||||||||||||||||||||||||
| 50 | 'verbose|v', | ||||||||||||||||||||||||||||||
| 51 | ) or pod2usage(1); | ||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | help(), exit(0) | ||||||||||||||||||||||||||||||
| 54 | 23 | ▶ | if $opt{help}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 55 | pod2usage(-exitstatus => 0, -verbose => 2) | ||||||||||||||||||||||||||||||
| 56 | 23 | ▶ | if $opt{man}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | print "$VERSION\n" and exit(0) | ||||||||||||||||||||||||||||||
| 58 | 23 | ▶ | if $opt{version}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$opt{'version'} && (print("$VERSION\n") && exit 0)
print "$VERSION\n" and exit 0
MC/DC0%0/2
$opt{'version'} && (print("$VERSION\n") && exit 0)
$opt{'version'}
print "$VERSION\n"
Truth table33%1/3
A && B
A= $opt{'version'}B= print "$VERSION\n"
| |||||||||||||||||||||||||||||||
| 59 | 23 | ▶ | help(), exit(1) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 60 | unless @ARGV > 0; | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | $opt{listformats} and | ||||||||||||||||||||||||||||||
| 63 | 23 | ▶ | print(join("\n", File::OM::listformats()), "\n"), | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 64 | exit 0; | ||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | 23 | ▶ | my $format = $opt{format} || 'Plain'; # given format name | ||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{'format'} || 'Plain'
MC/DC100%1/1
$opt{'format'} || 'Plain'
$opt{'format'}
Truth table100%2/2
A
A= $opt{'format'}
| |||||||||||||||||||||||||||||||
| 67 | 23 | my %om_opt = ( | |||||||||||||||||||||||||||||
| 68 | outhandle => *STDOUT, | ||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||
| 70 | 23 | ▶ | my $om = File::OM->new($format, \%om_opt) or | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | pod2usage("$0: unknown format: $format"); | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 23 | ▶ | my $dir = $opt{directory} || ""; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'directory'} || ''
MC/DC0%0/1
$opt{'directory'} || ''
$opt{'directory'}
Truth table50%1/2
A
A= $opt{'directory'}
| |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | 23 | my $cmd = lc shift @ARGV; | |||||||||||||||||||||||||||||
| 76 | 23 | my ($num, $fname, $fvalue, $msg, @nnv); | |||||||||||||||||||||||||||||
| 77 | 23 | my $delete = 0; | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 23 | ▶ | if ($cmd eq "add") { # easiest, since don't need to check existence | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | @ARGV > 1 or | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 81 | pod2usage("$cmd: needs at least two arguments"); | ||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | ($msg = nam_add($dir, $opt{portable}, @ARGV)) and | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 83 | die $msg; | ||||||||||||||||||||||||||||||
| 84 | 2 | exit 0; | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | ▶ | elsif (($delete = $cmd eq "rm") || $cmd eq "set") { | |||||||||||||||||||||||||||||
|
Condition66%2/3
$delete = $cmd eq "rm" or $cmd eq "set"
MC/DC50%1/2
$delete = $cmd eq "rm" or $cmd eq "set"
$delete = $cmd eq "rm"
$cmd eq "set"
Truth table66%2/3
A or B
A= $delete = $cmd eq "rm"B= $cmd eq "set"
| |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | 7 | ▶ | pod2usage("$cmd what? (more arguments needed)") | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | if (@ARGV == 0); | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | # same args for command as for nam_get() | ||||||||||||||||||||||||||||||
| 92 | 7 | ▶ | @nnv = ($delete | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 93 | ? nam_get($dir, @ARGV) # delete all args or | ||||||||||||||||||||||||||||||
| 94 | : nam_get($dir, $ARGV[0])); # just 1st for "set" | ||||||||||||||||||||||||||||||
| 95 | # @nnv may contain multiple tags (even for "set") to delete | ||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | 7 | ▶ | while (defined($num = shift @nnv)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 98 | 4 | $fname = shift @nnv; | |||||||||||||||||||||||||||||
| 99 | 4 | $fvalue = shift @nnv; | |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | unlink($fname) or | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 101 | print STDERR "$fname: $!"; | ||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||
| 103 | 7 | ▶ | $delete and exit 0; # since we're done | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 104 | # "set" case | ||||||||||||||||||||||||||||||
| 105 | 7 | ▶ | ($msg = nam_add($dir, $opt{portable}, @ARGV)) and | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 106 | die $msg; | ||||||||||||||||||||||||||||||
| 107 | 7 | exit 0; | |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | ▶ | elsif (($delete = $cmd eq "rmall") || $cmd eq "get") { | |||||||||||||||||||||||||||||
|
Condition100%3/3
$delete = $cmd eq "rmall" or $cmd eq "get"
MC/DC100%2/2
$delete = $cmd eq "rmall" or $cmd eq "get"
$delete = $cmd eq "rmall"
$cmd eq "get"
Truth table100%3/3
A or B
A= $delete = $cmd eq "rmall"B= $cmd eq "get"
| |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | # same args for command as for nam_get() | ||||||||||||||||||||||||||||||
| 112 | 13 | @nnv = nam_get($dir, @ARGV); | |||||||||||||||||||||||||||||
| 113 | 13 | ▶ | while (defined($num = shift @nnv)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 114 | 16 | $fname = shift @nnv; | |||||||||||||||||||||||||||||
| 115 | 16 | $fvalue = shift @nnv; | |||||||||||||||||||||||||||||
| 116 | 16 | ▶ | if ($delete) { # we're doing a delete | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 117 | 4 | ▶ | unlink($fname) or | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 118 | print STDERR "$fname: $!"; | ||||||||||||||||||||||||||||||
| 119 | 4 | next; | |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||
| 121 | 12 | $om->elem(File::Namaste::num2label($num), $fvalue); | |||||||||||||||||||||||||||||
| 122 | $opt{verbose} and | ||||||||||||||||||||||||||||||
| 123 | 12 | ▶ | $om->elem("file", $fname, '#'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||
| 125 | 13 | exit 0; | |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||
| 127 | elsif ($cmd eq "elide") { | ||||||||||||||||||||||||||||||
| 128 | 1 | $om->elem('elide', nam_elide(@ARGV)); | |||||||||||||||||||||||||||||
| 129 | 1 | exit 0; | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | 0 | pod2usage("$cmd: unrecognized command"); | |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | # One of the main benefits of this help text is to make it easy to find | ||||||||||||||||||||||||||||||
| 135 | # out what the numeric assignments are. Absent a command for tracking | ||||||||||||||||||||||||||||||
| 136 | # the current assignments, it is a priority to track them here. | ||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub help { | ||||||||||||||||||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 138 | 0 | print << 'EOI'; | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | nam - manage Namaste (NAMe-AS-TExt) tag files for describing directories | ||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | Usage: | ||||||||||||||||||||||||||||||
| 143 | nam [options] set|add N string [[maxlen] ellipsis] | ||||||||||||||||||||||||||||||
| 144 | nam [options] get|rm [N ...] | ||||||||||||||||||||||||||||||
| 145 | nam [options] rmall | ||||||||||||||||||||||||||||||
| 146 | nam elide string [[maxlen] ellipsis] | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | A Namaste tag file holds a single metadata value and its filename is derived | ||||||||||||||||||||||||||||||
| 149 | from that value. N specifies Dublin Core Kernel metadata elements, roughly: | ||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | 0 dir_type directory type (e.g., bagit_0.97) | ||||||||||||||||||||||||||||||
| 152 | 1 who creator (or contributor or publisher) | ||||||||||||||||||||||||||||||
| 153 | 2 what title (human-oriented name or identifier) | ||||||||||||||||||||||||||||||
| 154 | 3 when date of creation or collection of content | ||||||||||||||||||||||||||||||
| 155 | 4 where machine-oriented identifier | ||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||
| 157 | Commands (set, add, get, rm) act as you would expect, but "rmall" removes | ||||||||||||||||||||||||||||||
| 158 | all tags and "elide" just returns an elided string, operating on no files. | ||||||||||||||||||||||||||||||
| 159 | Use the "-d directory" option for tag files not in the current directory. | ||||||||||||||||||||||||||||||
| 160 | See "nam --man" for full documentation. | ||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | EOI | ||||||||||||||||||||||||||||||
| 163 | 0 | return 1; | |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||||