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

Last change on this file since 12406 was 12406, checked in by shaoqun, 18 years ago

uses the cache_dir par rather than ${ENV{'HOME'} to get the cache dir

  • 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 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 'deft' => "\"$ENV{'HOME'}/.gli/cache\"",
69 'reqd' => "no" },
70 { 'name' => "gli",
71 'desc' => "",
72 'type' => "flag",
73 'reqd' => "no",
74 'hiddengli' => "yes" },
75 { 'name' => "info", ,
76 'desc' => "{downloadfrom.info}",
77 'type' => "flag",
78 'reqd' => "no"}
79 ];
80
81my $options = { 'name' => "downloadfrom.pl",
82 'desc' => "{downloadfrom.desc}",
83 'args' => $arguments };
84
85
86# This function return the coresponding mode with a given mode string.
87sub findMode
88{
89 my ($strInput) = @_;
90
91 foreach my $hashMode (@$download_mode_list)
92 {
93 if($strInput eq $hashMode->{'name'})
94 {
95 return $hashMode->{'downloadname'};
96 }
97 }
98 return "";
99}
100
101# main program
102sub main
103{
104
105 my $hashOptions = {};
106 my ($strMode,$objMode,$pntArg);
107 $pntArg = \@ARGV;
108
109 # Parsing the General options for downloadfrom.pl,
110 # this parsing operation will allow extra options,
111 # since there might be some arguments for Download.
112 # extra arguments will be detected by the Downloads
113 parse2::parse(\@ARGV,$arguments,$hashOptions,"allow_extra_options");
114 # hashOptions: This is a hash map which maps to
115 # downloadfrom's arguments
116 # $hashOptions->{'cache_dir'}
117 # $hashOptions->{'download_mode'}
118 # $hashOptions->{'gli'}
119 # $hashOptions->{'info'}
120
121 $strMode = &findMode($hashOptions->{'download_mode'});
122
123 if ($strMode eq "") {
124 &gsprintf(STDERR, "{downloadfrom.incorrect_mode}\n");
125 &PrintUsage::print_txt_usage($options, "{downloadfrom.params}");
126 die "\n";
127
128 }
129 $objMode = &download::load_download($strMode, $pntArg);
130
131 if($hashOptions->{'info'})
132 {
133
134 my $blnResult = &download::get_information($objMode);
135 }
136 else
137 {
138 print "downloadfrom.pl start gathering data by using $strMode...\n\n";
139
140 my $blnResult = &download::process($objMode,$hashOptions);
141
142 ($blnResult eq "true")?
143 print "\ndownloadfrom.pl has completed data gathering\n":
144 print "\ndownloadfrom.pl has failed to gather data\n";
145 }
146
147
148}
149
150
151&main();
152
153
Note: See TracBrowser for help on using the repository browser.