script/moses-generate-datatypes.pl untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 87 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 datatypes.
4 #
5 # $Id: moses-generate-datatypes.pl,v 1.4 2008/05/09 20:26:04 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_f $opt_R $opt_u $opt_d $opt_v $opt_s /;
12 getopts('hfudvsR:');
13  
14 # usage
15 if ($opt_h) {
16 print STDOUT <<'END_OF_USAGE';
17 Generate datatypes.
18 Usage: [-R registry-string] [-vds] [data-type-name] [data-type-name...]
19 [-R registry-string] [-uf]
20
21 It also needs to get a location of a local cache (and potentially
22 a BioMoby registry endpoint, and an output directory). It takes
23 it from the 'moby-service.cfg' configuration file.
24  
25 If no data type given it generates all of them.
26  
27 -R ... a registry string in the form:
28 registry-url[@registry-uri]
29 where registry-uri is optional.
30 For example:
31 http://localhost/cgi-bin/MOBY-Central.pl
32 or
33 http://localhost/cgi-bin/MOBY-Central.pl@http://localhost/MOBY/Central
34  
35 -s ... show generated code on STDOUT
36 (no file is created, disabled when no data type name given)
37 -f ... fill the cache
38 -u ... update the cache
39 -v ... verbose
40 -d ... debug
41 -h ... help
42 END_OF_USAGE
43 exit (0);
44 }
45 # -----------------------------------------------------------
46  
47 use strict;
48  
49 use MOSES::MOBY::Base;
50 use MOSES::MOBY::Generators::GenTypes;
51  
52 $LOG->level ('INFO') if $opt_v;
53 $LOG->level ('DEBUG') if $opt_d;
54  
55 sub say { print @_, "\n"; }
56  
57 if ($opt_R) {
58 my @r = split(/\@/, $opt_R);
59 $opt_R = $r[0];
60 }
61  
62 my $generator = new MOSES::MOBY::Generators::GenTypes;
63 $generator->registry($opt_R) if $opt_R;
64  
65 if ($opt_f) {
66 my $cache = MOSES::MOBY::Cache::Central->new (
67 cachedir => $generator->cachedir,
68 registry => $generator->registry
69 );
70 say "Creating the datatype cache ... may take a few minutes!";
71 eval {$cache->create_datatype_cache();};
72 say "There was a problem creating the cache!\n$@" if $@;
73 say 'Done.' unless $@;
74 exit(0);
75 } elsif ($opt_u) {
76 my $cache = MOSES::MOBY::Cache::Central->new (
77 cachedir => $generator->cachedir,
78 registry => $generator->registry
79 );
80 say "Updating the datatype cache ... may take a few minutes!";
81 eval {$cache->update_datatype_cache();};
82 say "There was a problem updating the cache. Did you create it first?\n$@" if $@;
83 say 'Done.' unless $@;
84 exit(0);
85 }
86  
87 if (@ARGV) {
88 say 'Generating ' . (@ARGV+0) . '+ data types.';
89 if ($opt_s) {
90 my $code = '';
91 $generator->generate (datatype_names => [@ARGV],
92 with_docs => 1,
93 outcode => \$code);
94 say $code;
95 } else {
96 $generator->generate (datatype_names => [@ARGV]);
97 }
98 } else {
99 say 'Generating all data types.';
100 $generator->generate;
101 }
102 say 'Done.';
103  
104  
105 __END__