source: trunk/gsdl/bin/script/downloadfrom.pl@ 12903

Last change on this file since 12903 was 12903, checked in by kjdon, 18 years ago

remove the trailing slash from cache_dir -on windows this stuff things up

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# downloadfrom.pl -- program to download files from an external server
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2006 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28package downloadfrom;
29
30BEGIN {
31 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
32 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
33 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/downloaders");
36}
37
38use strict;
39no strict 'subs';
40use parse2;
41use download;
42use gsprintf 'gsprintf';
43use printusage;
44
45my $download_mode_list =
46 [ { 'name' => "Web",
47 'desc' => "{downloadfrom.download_mode.Web}",
48 'downloadname' => "WebDownload" },
49 { 'name' => "OAI",
50 'desc' => "{downloadfrom.download_mode.OAI}",
51 'downloadname' => "OAIDownload" },
52 { 'name' => "Z3950",
53 'desc' => "{downloadfrom.download_mode.Z3950}",
54 'downloadname' => "Z3950Download" },
55 { 'name' => "SRW",
56 'desc' => "{downloadfrom.download_mode.SRW}",
57 'downloadname' => "SRWDownload" } ];
58
59my $arguments =
60 [ { 'name' => "download_mode",
61 'desc' => "{downloadfrom.download_mode}",
62 'type' => "enum",
63 'list' => $download_mode_list,
64 'reqd' => "yes" },
65 { 'name' => "cache_dir",
66 'desc' => "{downloadfrom.cache_dir}",
67 'type' => "string",
68 'reqd' => "no" },
69 { 'name' => "gli",
70 'desc' => "",
71 'type' => "flag",
72 'reqd' => "no",
73 'hiddengli' => "yes" },
74 { 'name' => "info", ,
75 'desc' => "{downloadfrom.info}",
76 'type' => "flag",
77 'reqd' => "no"}
78 ];
79
80my $options = { 'name' => "downloadfrom.pl",
81 'desc' => "{downloadfrom.desc}",
82 'args' => $arguments };
83
84
85# This function return the coresponding mode with a given mode string.
86sub findMode
87{
88 my ($strInput) = @_;
89
90 foreach my $hashMode (@$download_mode_list)
91 {
92 if($strInput eq $hashMode->{'name'})
93 {
94 return $hashMode->{'downloadname'};
95 }
96 }
97 return "";
98}
99
100# main program
101sub main
102{
103
104 my $hashOptions = {};
105 my ($strMode,$objMode,$pntArg);
106 $pntArg = \@ARGV;
107
108 # Parsing the General options for downloadfrom.pl,
109 # this parsing operation will allow extra options,
110 # since there might be some arguments for Download.
111 # extra arguments will be detected by the Downloads
112 parse2::parse(\@ARGV,$arguments,$hashOptions,"allow_extra_options");
113 # hashOptions: This is a hash map which maps to
114 # downloadfrom's arguments
115 # $hashOptions->{'cache_dir'}
116 # $hashOptions->{'download_mode'}
117 # $hashOptions->{'gli'}
118 # $hashOptions->{'info'}
119
120 $strMode = &findMode($hashOptions->{'download_mode'});
121
122 if ($strMode eq "") {
123 &gsprintf(STDERR, "{downloadfrom.incorrect_mode}\n");
124 &PrintUsage::print_txt_usage($options, "{downloadfrom.params}");
125 die "\n";
126
127 }
128 $objMode = &download::load_download($strMode, $pntArg);
129
130 if($hashOptions->{'info'})
131 {
132
133 my $blnResult = &download::get_information($objMode);
134 }
135 else
136 {
137 print "downloadfrom.pl start gathering data by using $strMode...\n\n";
138
139 # need to remove trailing slash from cache dir
140 if (defined $hashOptions->{'cache_dir'}) {
141 $hashOptions->{'cache_dir'} =~ s/[\/\\]$//;
142 }
143 my $blnResult = &download::process($objMode,$hashOptions);
144
145 ($blnResult eq "true")?
146 print "\ndownloadfrom.pl has completed data gathering\n":
147 print "\ndownloadfrom.pl has failed to gather data\n";
148 }
149
150
151}
152
153
154&main();
155
156
Note: See TracBrowser for help on using the repository browser.