script/moses-generate-services.pl untested

filter: Statementstmt 0.0% 0 / 111 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 193 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 # Generate services.
4 #
5 # $Id: moses-generate-services.pl,v 1.7 2009/03/30 13:16:38 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_A $opt_d $opt_R $opt_v $opt_a $opt_s $opt_b $opt_f $opt_u $opt_F $opt_S $opt_t $opt_c $opt_C /;
12 getopts('hdvasbfuFStcCAR:');
13 # usage
14 if (not($opt_u or $opt_f)) {
15 if ($opt_h or (not $opt_a and @ARGV == 0)) {
16 print STDOUT <<'END_OF_USAGE';
17 Generate Services.
18 Usage: [-vds] [-R registry-string] [-b|S|t|c|A] authority [service-name] [service-name...]
19 [-vds] [-R registry-string] [-b|S|t|c|A] authority
20 [-vd] [-R registry-string] [-b|S|t|c|A] -a
21 [-R registry-string] [-fu]
22  
23 It also needs to get a location of a local cache (and potentially
24 a BioMoby registry endpoint, and an output directory). It takes
25 it from the 'moby-service.cfg' configuration file.
26  
27 -f ... fill the cache
28 -u ... update the cache
29
30 -R ... a registry string in the form:
31 registry-url[@registry-uri]
32 where registry-uri is optional.
33 For example:
34 http://localhost/cgi-bin/MOBY-Central.pl
35 or
36 http://localhost/cgi-bin/MOBY-Central.pl@http://localhost/MOBY/Central
37
38 -b ... generate base[s] of given service[s]
39 -S ... generate implementation and the base of service[s], the
40 implementation module has enabled option to read the base
41 statically (that is why it is also generated here)
42
43 -i ... generate an implementation of the given service
44
45 -c ... generate a cgi based implementation of the given service
46 -C ... generate an asynchronous cgi based implementation of the given service
47
48 -A ... generate an asynchronous based implementation of the given service
49 -t ... update dispatch table of services (a table used by the
50 cgi-bin script and SOAP::Lite to dispatch requests);
51 this table is also updated automatically when options
52 -i or -S are given
53 If none of -b, -S, -t, -c is given, it generates/show implementation
54 (not a base) of service[s].
55  
56 -s ... show generated code on STDOUT
57 (no file is created, disabled when -a given)
58 -a ... generate all services (good only for generator testing)
59  
60 -v ... verbose
61 -d ... debug
62 -h ... help
63 END_OF_USAGE
64 exit (0);
65 }
66 }
67 # Undocumented options
68 # (because it is dangerous, you can loose your code):
69 # -F ... force to overwrite existing implementtaion
70 # -----------------------------------------------------------
71  
72 use strict;
73  
74 use MOSES::MOBY::Base;
75 use MOSES::MOBY::Generators::GenServices;
76  
77 $LOG->level ('INFO') if $opt_v;
78 $LOG->level ('DEBUG') if $opt_d;
79  
80 sub say { print @_, "\n"; }
81  
82 if ($opt_R) {
83 my @r = split(/\@/, $opt_R);
84 $opt_R = $r[0];
85 }
86  
87 my $generator = new MOSES::MOBY::Generators::GenServices;
88 $generator->registry($opt_R) if $opt_R;
89  
90 if ($opt_f) {
91 my $cache = MOSES::MOBY::Cache::Central->new (
92 cachedir => $generator->cachedir,
93 registry => $generator->registry
94 );
95
96 say "Creating the services cache ... may take a few minutes!";
97 say("Using the registry: " . $cache->registry);
98 eval{$cache->create_service_cache();};
99 say "There was a problem creating the cache:\n$@" if $@;
100 say 'Done.' unless $@;
101 exit(0);
102 } elsif ($opt_u) {
103 my $cache = MOSES::MOBY::Cache::Central->new (
104 cachedir => $generator->cachedir,
105 registry => $generator->registry
106 );
107 say "Updating the services cache ... may take a few minutes!";
108 eval{$cache->update_service_cache();};
109 say "There was a problem updating the cache. Did you create it first?\n$@" if $@;
110 say 'Done.' unless $@;
111 exit(0);
112 }
113  
114 if ($opt_a) {
115 say 'Generating all services.';
116 if ($opt_b) {
117 $generator->generate_base;
118 } elsif ($opt_S) {
119 $generator->generate_impl (static_impl => 1);
120 $generator->generate_base;
121 $generator->update_table;
122 } elsif ($opt_c) {
123 $generator->generate_impl;
124 $generator->generate_cgi;
125 } elsif ($opt_C) {
126 $generator->generate_impl;
127 $generator->generate_async_cgi;
128 } elsif ($opt_t) {
129 $generator->update_table;
130 } elsif ($opt_A) {
131 $generator->generate_impl;
132 $generator->generate_async;
133 $generator->update_async_table;
134 } else {
135 $generator->generate_impl;
136 $generator->update_table;
137 }
138 } else {
139 my $authority = shift;
140 say "Generating services from $authority:";
141 if ($opt_s) {
142 my $code = '';
143 if ($opt_b) {
144 $generator->generate_base (service_names => [@ARGV],
145 authority => $authority,
146 outcode => \$code);
147 } elsif ($opt_c) {
148 $generator->generate_impl(service_names => [@ARGV],
149 authority => $authority,
150 outcode => \$code);
151 $generator->generate_cgi(service_names => [@ARGV],
152 authority => $authority,
153 outcode => \$code);
154 } elsif ($opt_C) {
155 $generator->generate_impl(service_names => [@ARGV],
156 authority => $authority,
157 outcode => \$code);
158 $generator->generate_async_cgi(service_names => [@ARGV],
159 authority => $authority,
160 outcode => \$code);
161 } elsif ($opt_A) {
162 $generator->generate_async(service_names => [@ARGV],
163 authority => $authority,
164 outcode => \$code);
165 #$generator->update_async_table;
166 } else {
167 $generator->generate_impl (service_names => [@ARGV],
168 authority => $authority,
169 outcode => \$code);
170 }
171 say $code;
172 } else {
173 if ($opt_b) {
174 $generator->generate_base (service_names => [@ARGV],
175 authority => $authority);
176 } elsif ($opt_S) {
177 $generator->generate_impl (service_names => [@ARGV],
178 authority => $authority,
179 force_over => $opt_F,
180 static_impl => 1);
181 $generator->generate_base (service_names => [@ARGV],
182 authority => $authority);
183 $generator->update_table (service_names => [@ARGV],
184 authority => $authority);
185 } elsif ($opt_A) {
186 $generator->generate_impl(
187 service_names => [@ARGV],
188 authority => $authority,
189 force_over => $opt_F);
190 $generator->generate_async (service_names => [@ARGV],
191 authority => $authority,
192 force_over => $opt_F,
193 static_impl => 1);
194 $generator->update_async_table (service_names => [@ARGV],
195 authority => $authority);
196 } elsif ($opt_c) {
197 $generator->generate_impl(
198 service_names => [@ARGV],
199 authority => $authority,
200 force_over => $opt_F);
201 $generator->generate_cgi(service_names => [@ARGV],
202 authority => $authority);
203 } elsif ($opt_C) {
204 $generator->generate_impl(
205 service_names => [@ARGV],
206 authority => $authority,
207 force_over => $opt_F);
208 $generator->generate_async_cgi(service_names => [@ARGV],
209 authority => $authority);
210 } elsif ($opt_t) {
211 $generator->update_table (service_names => [@ARGV],
212 authority => $authority);
213 } else {
214 $generator->generate_impl (service_names => [@ARGV],
215 authority => $authority,
216 force_over => $opt_F);
217 $generator->update_table (service_names => [@ARGV],
218 authority => $authority);
219 }
220 }
221 }
222 say 'Done.';
223  
224  
225 __END__