blib/script/removeConfigData.pl untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 92 CC 1 SCAR 6.9
CC
1
Cov
0%
minimalUsageNotes
2.0
showHelp
2.0
showVersion
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 removeConfigData.pl - This program removes the temporary table
6 and associated files that are created based on the configuration
7 file.
8  
9 =head1 SYNOPSIS
10  
11 This program removes the temporary table and associated files that
12 are created based on the configuration file.
13  
14 =head1 USAGE
15  
16 Usage: removeConfigData.pl [OPTIONS] CONFIGFILE
17  
18 =head1 INPUT
19  
20 =head2 CONFIGFILE
21  
22 This is the configuration file. The format of the configuration
23 file is as follows:
24  
25 SAB :: <include|exclude> <source1, source2, ... sourceN>
26  
27 REL :: <include|exclude> <relation1, relation2, ... relationN>
28  
29 For example, if we wanted to use the MSH vocabulary with only
30 the RB/RN relations, the configuration file would be:
31  
32 SAB :: include MSH
33 REL :: include RB, RN
34  
35 or
36  
37 SAB :: include MSH
38 REL :: exclude PAR, CHD
39  
40 If you go to the configuration file directory, there will
41 be example configuration files for the different runs that
42 you have performed.
43  
44 =head2 Optional Arguments:
45  
46 =head3 --debug
47  
48 Sets the debug flag for testing
49  
50 =head3 --username STRING
51  
52 Username is required to access the umls database on MySql
53 unless it was specified in the my.cnf file at installation
54  
55 =head3 --password STRING
56  
57 Password is required to access the umls database on MySql
58 unless it was specified in the my.cnf file at installation
59  
60 =head3 --hostname STRING
61  
62 Hostname where mysql is located. DEFAULT: localhost
63  
64 =head3 --socket STRING
65  
66 The socket your mysql is using. DEFAULT: /tmp/mysql.sock
67  
68 =head3 --database STRING
69  
70 Database contain UMLS DEFAULT: umls
71  
72 =head4 --help
73  
74 Displays the quick summary of program options.
75  
76 =head4 --version
77  
78 Displays the version information.
79  
80 =head1 OUTPUT
81  
82 List of CUIs that are associated with the input term
83  
84 =head1 SYSTEM REQUIREMENTS
85  
86 =over
87  
88 =item * Perl (version 5.8.5 or better) - http://www.perl.org
89  
90 =back
91  
92 =head1 AUTHOR
93  
94 Bridget T. McInnes, University of Minnesota
95  
96 =head1 COPYRIGHT
97  
98 Copyright (c) 2007-2009,
99  
100 Bridget T. McInnes, University of Minnesota
101 bthomson at cs.umn.edu
102
103 Ted Pedersen, University of Minnesota Duluth
104 tpederse at d.umn.edu
105  
106 Siddharth Patwardhan, University of Utah, Salt Lake City
107 sidd@cs.utah.edu
108
109 Serguei Pakhomov, University of Minnesota Twin Cities
110 pakh0002@umn.edu
111  
112 This program is free software; you can redistribute it and/or modify it under
113 the terms of the GNU General Public License as published by the Free Software
114 Foundation; either version 2 of the License, or (at your option) any later
115 version.
116  
117 This program is distributed in the hope that it will be useful, but WITHOUT
118 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
119 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
120  
121 You should have received a copy of the GNU General Public License along with
122 this program; if not, write to:
123  
124 The Free Software Foundation, Inc.,
125 59 Temple Place - Suite 330,
126 Boston, MA 02111-1307, USA.
127  
128 =cut
129  
130 ###############################################################################
131  
132 # THE CODE STARTS HERE
133 ###############################################################################
134  
135 # ================================
136 # COMMAND LINE OPTIONS AND USAGE
137 # ================================
138  
139  
140 use UMLS::Interface;
141 use Getopt::Long;
142  
143 eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s")) or die ("Please check the above mentioned option(s).\n");
144  
145  
146 # if help is defined, print out help
147 if( defined $opt_help ) {
148 $opt_help = 1;
149 &showHelp();
150 exit;
151 }
152  
153 # if version is requested, show version
154 if( defined $opt_version ) {
155 $opt_version = 1;
156 &showVersion();
157 exit;
158 }
159  
160 # At least 1 CUI should be given on the command line.
161 if(scalar(@ARGV) < 1) {
162 print STDERR "Configuration file was not specified on the command line\n";
163 &minimalUsageNotes();
164 exit;
165 }
166  
167 my $config = shift;
168  
169 my %option_hash = ();
170  
171 $option_hash{"config"} = $config;
172  
173 if(defined $opt_debug) {
174 $option_hash{"debug"} = $opt_debug;
175 }
176 if(defined $opt_username) {
177 $option_hash{"username"} = $opt_username;
178 }
179 if(defined $opt_driver) {
180 $option_hash{"driver"} = $opt_driver;
181 }
182 if(defined $opt_database) {
183 $option_hash{"database"} = $opt_database;
184 }
185 if(defined $opt_password) {
186 $option_hash{"password"} = $opt_password;
187 }
188 if(defined $opt_hostname) {
189 $option_hash{"hostname"} = $opt_hostname;
190 }
191 if(defined $opt_socket) {
192 $option_hash{"socket"} = $opt_socket;
193 }
194  
195 $umls = UMLS::Interface->new(\%option_hash);
196 die "Unable to create UMLS::Interface object.\n" if(!$umls);
197  
198 $umls->dropConfigTable();
199 $umls->removeConfigFiles();
200  
201 ##############################################################################
202 # function to output minimal usage notes
203 ##############################################################################
204 sub minimalUsageNotes {
205
206 print "Usage: removeConfigData.pl [OPTIONS] CONFIGFILE \n";
207 &askHelp();
208 exit;
209 }
210  
211 ##############################################################################
212 # function to output help messages for this program
213 ##############################################################################
214 sub showHelp() {
215  
216
217 print "This is a utility that removes the temporary database and \n";
218 print "files associated with the configuration file information.\n\n";
219
220 print "Usage: removeConfigData.pl [OPTIONS] CONFIGFILE\n\n";
221  
222 print "Options:\n\n";
223  
224 print "--debug Sets the debug flag for testing\n\n";
225  
226 print "--username STRING Username required to access mysql\n\n";
227  
228 print "--password STRING Password required to access mysql\n\n";
229  
230 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
231  
232 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
233
234 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
235  
236 print "--version Prints the version number\n\n";
237
238 print "--help Prints this help message.\n\n";
239 }
240  
241 ##############################################################################
242 # function to output the version number
243 ##############################################################################
244 sub showVersion {
245 print '$Id: removeConfigData.pl,v 1.6 2011/08/29 16:37:03 btmcinnes Exp $';
246 print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n";
247 }
248  
249 ##############################################################################
250 # function to output "ask for help" message when user's goofed
251 ##############################################################################
252 sub askHelp {
253 print STDERR "Type removeConfigData.pl --help for help.\n";
254 }
255