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