From: Bill Erickson Date: Fri, 7 Dec 2012 17:18:50 +0000 (-0500) Subject: csv fetcher; remote account X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=cd46eb487513b8b9b1007136833068acb7903fe1;p=evergreen%2Fequinox.git csv fetcher; remote account Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/support-scripts/csv_notify_fetcher.pl b/Open-ILS/src/support-scripts/csv_notify_fetcher.pl index b033a26a9c..8fd0391803 100755 --- a/Open-ILS/src/support-scripts/csv_notify_fetcher.pl +++ b/Open-ILS/src/support-scripts/csv_notify_fetcher.pl @@ -7,12 +7,14 @@ use OpenILS::Utils::CStoreEditor; use OpenILS::Utils::Cronscript; use OpenILS::Utils::Fieldmapper; use OpenSRF::Utils::Logger qw/$logger/; -binmode(STDOUT, ":utf8"); my %defaults = ( - 'osrf-config=s' => '/openils/conf/opensrf_core.xml', - 'response-file=s' => '', - 'verbose' => 0 + 'osrf-config=s' => '/openils/conf/opensrf_core.xml', + 'response-file=s' => '', + 'remote-account=s' => 0, + 'remote-file=s' => '', + 'local-file=s' => '', # store fetched file locally + 'verbose' => 0 ); sub help { @@ -32,8 +34,52 @@ my $opts = $o->MyGetOptions(); $o->bootstrap; my $file = $opts->{'response-file'}; +my $remote_account = $opts->{'remote-account'}; +my $remote_file = $opts->{'remote-file'}; +my $local_file = $opts->{'local-file'}; +my $verbose = $opts->{'verbose'}; + +die "--response-file OR --remote-account and --remote-file required\n" + unless $file or ($remote_account and $remote_file); + +if (!$file and $remote_account) { + + my $racct = $o->editor->retrieve_config_remote_account($remote_account); + die "No such remote account $remote_account" unless $racct; + + my $type; + my $host = $racct->host; + ($host =~ s/^(S?FTP)://i and $type = uc($1)) or + ($host =~ s/^(SSH|SCP)://i and $type = 'SCP'); + + if ($local_file) { + $file = $local_file; + } else { + my $tmp_file = File::Temp->new(); + $file = $tmp_file->filename; + } + + my $acct = OpenILS::Utils::RemoteAccount->new( + type => $type, + account_object => $racct, + local_file => $file, + remote_file => $remote_file + ); + + my $res = $acct->put; + + die "Unable to push to remote server [$remote_account] : " . + $acct->error . "\n" unless $res; + + print "Pushed file to $res\n" if $verbose; +} + +# at this point, $file contains CSV, because it was already there or +# because we just fetched it from the remote account open(FILE, $file) or die "Unable to open response file: '$file' : $!\n"; + +binmode(FILE, ":utf8"); my $e = $o->editor(connect => 1);