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

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

jefferey's script from downloading from an external server. uses download modules to provide specific functionality for types of servers

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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 die "HOME not set\n" unless defined $ENV{'HOME'};
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/downloaders");
37}
38
39use strict;
40no strict 'subs';
41use parse2;
42use download;
43use gsprintf 'gsprintf';
44use printusage;
45
46my $download_mode_list =
47 [ { 'name' => "Web",
48 'desc' => "{downloadfrom.download_mode.Web}",
49 'downloadname' => "WebDownload" },
50 { 'name' => "OAI",
51 'desc' => "{downloadfrom.download_mode.OAI}",
52 'downloadname' => "OAIDownload" },
53 { 'name' => "Z39.50",
54 'desc' => "{downloadfrom.download_mode.Z3950}",
55 'downloadname' => "Z3950Download" },
56 { 'name' => "SRW",
57 'desc' => "{downloadfrom.download_mode.SRW}",
58 'downloadname' => "SRWDownload" } ];
59
60my $arguments =
61 [ { 'name' => "download_mode",
62 'desc' => "{downloadfrom.download_mode}",
63 'type' => "enum",
64 'list' => $download_mode_list,
65 'reqd' => "yes" },
66 { 'name' => "cache_dir",
67 'desc' => "{downloadfrom.cache_dir}",
68 'type' => "string",
69 'deft' => "$ENV{'HOME'}/.gli/cache",
70 'reqd' => "no" },
71 { 'name' => "gli",
72 'desc' => "",
73 'type' => "flag",
74 'reqd' => "no",
75 'hiddengli' => "yes" },
76 { 'name' => "info", ,
77 'desc' => "{downloadfrom.info}",
78 'type' => "flag",
79 'reqd' => "no"}
80 ];
81
82my $options = { 'name' => "downloadfrom.pl",
83 'desc' => "{downloadfrom.desc}",
84 'args' => $arguments };
85
86
87# This function return the coresponding mode with a given mode string.
88sub findMode
89{
90 my ($strInput) = @_;
91
92 foreach my $hashMode (@$download_mode_list)
93 {
94 if($strInput eq $hashMode->{'name'})
95 {
96 return $hashMode->{'downloadname'};
97 }
98 }
99 return "";
100}
101
102# main program
103sub main
104{
105
106 my $hashOptions = {};
107 my ($strMode,$objMode,$pntArg);
108 $pntArg = \@ARGV;
109
110 # Parsing the General options for downloadfrom.pl,
111 # this parsing operation will allow extra options,
112 # since there might be some arguments for Download.
113 # extra arguments will be detected by the Downloads
114 parse2::parse(\@ARGV,$arguments,$hashOptions,"allow_extra_options");
115 # hashOptions: This is a hash map which maps to
116 # downloadfrom's arguments
117 # $hashOptions->{'cache_dir'}
118 # $hashOptions->{'download_mode'}
119 # $hashOptions->{'gli'}
120 # $hashOptions->{'info'}
121
122 $strMode = &findMode($hashOptions->{'download_mode'});
123
124 if ($strMode eq "") {
125 &gsprintf(STDERR, "{downloadfrom.incorrect_mode}\n");
126 &PrintUsage::print_txt_usage($options, "{downloadfrom.params}");
127 die "\n";
128
129 }
130 $objMode = &download::load_download($strMode, $pntArg);
131
132 if($hashOptions->{'info'})
133 {
134
135 my $blnResult = &download::get_information($objMode);
136 }
137 else
138 {
139 print "downloadfrom.pl start gathering data by using $strMode...\n\n";
140
141 my $blnResult = &download::process($objMode,$hashOptions);
142
143 ($blnResult eq "true")?
144 print "\ndownloadfrom.pl has completed data gathering\n":
145 print "\ndownloadfrom.pl has failed to gather data\n";
146 }
147}
148
149
150&main();
Note: See TracBrowser for help on using the repository browser.