script/moses-local-cache.pl untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 137 CC 1 SCAR 6.9
CC
1
Cov
0%
say
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2 #
3 # Accessing local cache of BioMoby registries.
4 #
5 # $Id: moses-local-cache.pl,v 1.3 2008/02/21 00:12:55 kawas Exp $
6 # Contact: Martin Senger <martin.senger@gmail.com>
7 # -----------------------------------------------------------
8  
9 # some command-line options
10 use Getopt::Std;
11 use vars qw/ $opt_h $opt_d $opt_v $opt_x $opt_s $opt_t $opt_a $opt_l $opt_r $opt_c $opt_i /;
12 getopt;
13  
14 # usage
15 if ($opt_h) {
16 print STDOUT <<'END_OF_USAGE';
17 Accessing local cache of BioMoby registries.
18 Usage: # for data types
19 [-vd] -lt
20 [-vd] -[x]t data-type-name
21 [-vd] -r data-type-name [data-type-name...]
22 [-vd] -c data-type-name
23  
24 # for services
25 [-vd] -a
26 [-vd] -ls [authority]
27 [-vd] -[x]s authority [service-name...]
28  
29 # for info
30 [-vd] -i
31  
32 It also needs to get a location of a local cache (and potentially
33 a BioMoby registry endpoint). It takes it from the
34 'moby-service.cfg' configuration file.
35  
36 -t ... show given data type definition
37 -r ... list names of all related data types
38 -c ... list all children of a given data type
39 -s ... show given service definitions, or all services from
40 given authority
41 -a ... list service authority names
42  
43 -l ... list names of all entities (must be accompanied by
44 -t or -s, depending on what you want to print)
45  
46 -x ... print an XML representation of the obtained object
47 (data type or service) - the output is equivalent to
48 the XML used to register this object
49  
50 -i ... information about cached registries
51  
52 -v ... verbose
53 -d ... debug
54 -h ... help
55 END_OF_USAGE
56 exit (0);
57 }
58 # -----------------------------------------------------------
59  
60 use strict;
61  
62 use File::HomeDir;
63 use MOSES::MOBY::Base;
64 use MOSES::MOBY::Cache::Central;
65 use MOSES::MOBY::Cache::Registries;
66  
67 $LOG->level ('INFO') if $opt_v;
68 $LOG->level ('DEBUG') if $opt_d;
69  
70 sub say { print @_, "\n"; }
71  
72 my $cache = new MOSES::MOBY::Cache::Central;
73  
74 # --- get info
75 if ($opt_i) {
76 say 'Currently used registry: ' . $cache->registry;
77 say "(it can be changed in $MOSES::MOBY::Config::DEFAULT_CONFIG_FILE)\n";
78 my $details =
79 MOSES::MOBY::Cache::Registries->get ($cache->registry) ||
80 MOSES::MOBY::Cache::Registries->get ('default');
81 foreach my $key (sort keys %{ $details }) {
82 printf " %-12s: %-s\n", $key, $details->{$key};
83 }
84 say;
85  
86 say "Statictics for all locally cached registries:\n";
87 printf
88 "%-13s %+13s %+13s %+10s\n",
89 'Registry', 'Data types', 'Authorities', 'Services';
90 foreach my $reg (MOSES::MOBY::Cache::Registries->list) {
91 next unless $cache->cache_exists ($reg);
92 my $new_cache = new MOSES::MOBY::Cache::Central ( registry => $reg );
93 my $datatypes_count = $new_cache->get_datatype_names;
94 my %authorities = $new_cache->get_service_names;
95 my $services_count = 0;
96 foreach my $service_chunk (values %authorities) {
97 $services_count += @{$service_chunk};
98 }
99 printf
100 "%-13s %+13u %+13u %+10u\n",
101 $reg, $datatypes_count, (0 + keys %authorities), $services_count;
102 }
103 }
104  
105 # --- get data types
106 if ($opt_t) {
107 if ($opt_l) {
108 # getting a list of names
109 say join ("\n", sort $cache->get_datatype_names);
110 } else {
111 # getting data type[s]
112 my $result = $cache->get_datatype (@ARGV);
113 # ...and printing them
114 if ($opt_x) {
115 say $result->toXML->toString(1);
116 } else {
117 say $result;
118 }
119 }
120 }
121  
122 # --- get related data types
123 if ($opt_r and @ARGV) {
124 my @wanted_objs = map { $cache->get_datatype ($_) } @ARGV;
125 say join ("\n",
126 sort map { $_->name } @{ $cache->get_related_types (@wanted_objs) });
127 }
128  
129 # --- get children
130 if ($opt_c and @ARGV) {
131 say "All children of '$ARGV[0]':";
132 print $_ foreach $cache->get_all_children ($ARGV[0]);
133 }
134  
135 # --- get authorities
136 if ($opt_a) {
137 say join ("\n", sort keys %{ { $cache->get_service_names } } );
138 }
139  
140 # --- get services
141 if ($opt_s) {
142 if ($opt_l) {
143 # getting a list of services
144 my %by_authorities = $cache->get_service_names;
145 if (@ARGV) {
146 say join ("\n", @{ $by_authorities{$ARGV[0]} });
147 } else {
148 foreach my $authority (sort keys (%by_authorities)) {
149 say "\nAuthority: $authority";
150 say join ("\n", @{ $by_authorities{$authority} });
151 }
152 }
153 } else {
154 # getting service[s]
155 my @result = $cache->get_services (@ARGV);
156 # ...and printing them
157 if ($opt_x) {
158 say $_->toXML->toString(1) foreach @result;
159 } else {
160 say $_ foreach @result;
161 }
162 }
163 }
164  
165 __END__