annotate lib/utils.pm @ 2:be504ccbc41c draft default tip

master branch Updating with tag :CI_COMMIT_TAG - - Fxx
author fgiacomoni
date Wed, 30 Nov 2022 16:14:27 +0000
parents 7c9269bded0e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
1 package utils ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
2
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
3 use strict;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
4 use warnings ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
5 use Exporter ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
6 use Carp ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
7
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
8 use Data::Dumper ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
9 use LWP::UserAgent ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
10 use LWP::Simple ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
11 use HTTP::Status qw(:constants :is status_message);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
12 use Archive::Zip ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
13 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
14
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
15 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
16
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
17 our $VERSION = "1.0";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
18 our @ISA = qw(Exporter);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
19 our @EXPORT = qw( getHttpFileVersion getHttpFile unzipFile );
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
20 our %EXPORT_TAGS = ( ALL => [qw( getHttpFileVersion getHttpFile unzipFile )] );
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
21
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
22 =head1 NAME
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
23
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
24 My::Module - An example module
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
25
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
26 =head1 SYNOPSIS
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
27
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
28 use My::Module;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
29 my $object = My::Module->new();
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
30 print $object->as_string;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
31
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
32 =head1 DESCRIPTION
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
33
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
34 This module does not really exist, it
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
35 was made for the sole purpose of
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
36 demonstrating how POD works.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
37
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
38 =head1 METHODS
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
39
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
40 Methods are :
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
41
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
42 =head2 METHOD new
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
43
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
44 ## Description : new
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
45 ## Input : $self
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
46 ## Ouput : bless $self ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
47 ## Usage : new() ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
48
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
49 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
50
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
51 sub new {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
52 ## Variables
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
53 my $self={};
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
54 bless($self) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
55 return $self ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
56 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
57 ### END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
58
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
59 =head2 METHOD checkHttpUrl
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
60
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
61 ## Description : check if a http url exists or not and warn/die
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
62 ## Input : $url
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
63 ## Output : $warn
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
64 ## Usage : my ( $warn ) = checkHttpUrl ( $url ) ;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
65
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
66 =cut
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
67 ## START of SUB
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
68 sub checkHttpUrl {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
69 ## Retrieve Values
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
70 my $self = shift ;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
71 my ( $url ) = @_;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
72 my ( $warn ) = ( undef ) ;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
73
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
74 my $ua = new LWP::UserAgent;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
75
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
76 ## just make different not existing/time out
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
77 $ua->timeout(10);
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
78
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
79 if ($ua->head($url)) {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
80 print "\t$url DOES EXIST\n";
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
81 } else {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
82 croak "\t$url DOES not exist or timeout\n";;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
83 }
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
84
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
85
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
86 return ($warn) ;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
87 }
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
88 ### END of SUB
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
89
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
90 =head2 METHOD getHttpFileVersion
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
91
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
92 ## Description : fetch the version of a file from its http header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
93 ## Input : $url
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
94 ## Output : $version
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
95 ## Usage : $version= getHttpFileVersion($url) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
96
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
97 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
98 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
99 sub getHttpFileVersion {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
100 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
101 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
102 my ( $url ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
103
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
104 my ( $version ) = undef ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
105
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
106 # based on https://stackoverflow.com/questions/36903905/extract-headers-from-http-request-in-perl
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
107 my $ua = new LWP::UserAgent;
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
108 $ua->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:64.0) Gecko/20100101 Firefox/64.0");
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
109 $ua->from('franck.giacomoni@inrae.fr');
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
110 $ua->ssl_opts(timeout => 100, verify_hostname => 0);
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
111
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
112 my $result = $ua->head($url);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
113
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
114 for my $header_name ($result->header_field_names) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
115
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
116 if ( ($header_name eq 'Last-Modified') or ($header_name eq 'last-Modified') or ($header_name eq 'last-Modified') ) {
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
117 # print $result->header($header_name)."\n";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
118 if ($result->header($header_name) =~/[a-z|A-Z]+,\s(.*)\s[0-9]+:[0-9]+:[0-9]+\s[a-z|A-Z]+$/) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
119 $version = $1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
120
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
121 #version format is DD Month(3letters) YYYY (as "09 Jul 2018")
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
122 if ($version =~/([0-9]+)\s([a-z|A-Z]+)\s([0-9]+)/) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
123 $version = 'v'.$3.$2.$1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
124 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
125 else{
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
126 warn "the current version format - DD Month(3letters) YYYY - doesn't match with template" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
127 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
128 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
129 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
130 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
131 next ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
132 }
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
133 # print "\tVERSION IS: $version\n" ;
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
134 }
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
135
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
136 if (!$version) {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
137 croak "\t /!\\ the current version of the db is not findable !!"
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
138 }
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
139
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
140 return($version) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
141 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
142 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
143
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
144 =head2 METHOD getHttpFile
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
145
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
146 ## Description : fetch a file from http
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
147 ## Input : $url, $filename
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
148 ## Output : $file
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
149 ## Usage : $file= getHttpFile($url, $filename) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
150
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
151 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
152 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
153 sub getHttpFile {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
154 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
155 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
156 my ( $url, $fileNameToGet ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
157
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
158 my $hstatus = 404 ; # default
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
159
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
160 if ( (defined $url ) and (defined $fileNameToGet ) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
161 my $ua = LWP::UserAgent->new();
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
162 $ua->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:64.0) Gecko/20100101 Firefox/64.0");
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
163 $ua->from('franck.giacomoni@inrae.fr');
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
164 $ua->ssl_opts(timeout => 100, verify_hostname => 0);
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
165
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
166 # my $hstatus = getstore ($url, $fileNameToGet);
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
167
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
168 my $response = $ua->get($url);
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
169
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
170 if ($response->is_error) {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
171 $hstatus = $response->status_line ;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
172 print "\t\t$hstatus: ", status_message($hstatus), "\n";
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
173 carp $response->status_line, "\n";
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
174 }
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
175 else {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
176 $hstatus = $response->status_line ;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
177 }
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
178
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
179 open my $fh, '>', $fileNameToGet or die $!;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
180 binmode $fh;
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
181 print $fh $response->decoded_content;
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
182
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
183 # if($hstatus != HTTP_OK) {
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
184 # print "\t\t$hstatus: ", status_message($hstatus), "\n";
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
185 # }
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
186 #
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
187 if (!-e $fileNameToGet) {
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
188 carp "None file (should be $fileNameToGet) was download from the given url($url)\n" ;
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
189 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
190 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
191
2
be504ccbc41c master branch Updating with tag :CI_COMMIT_TAG - - Fxx
fgiacomoni
parents: 0
diff changeset
192 return($hstatus) ;
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
193 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
194 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
195
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
196 =head2 METHOD unzipFile
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
197
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
198 ## Description : unzip a wanted file from a zip archive
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
199 ## Input : $archive, $filePath, $fileName
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
200 ## Output : 1
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
201 ## Usage : unzipFile($archive, $filePath, $fileName) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
202
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
203 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
204 sub unzipFile {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
205 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
206 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
207 my ($archive, $filePath, $fileName) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
208
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
209 my $zip = Archive::Zip->new($archive);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
210
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
211 if ( (defined $fileName) and (defined $filePath) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
212
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
213 foreach my $file ($zip->members) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
214 next unless ($file->fileName eq $fileName);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
215 $file->extractToFileNamed($filePath);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
216 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
217
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
218 croak "There was a problem extracting $fileName from $archive" unless (-e $filePath);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
219 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
220 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
221 croak "the given filePath or the filename are undef\n" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
222 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
223
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
224 return 1;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
225 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
226 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
227
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
228 =head2 METHOD gunzipFile
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
229
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
230 ## Description : unzip a wanted file from a zip archive
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
231 ## Input : $archive, $filePath, $fileName
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
232 ## Output : 1
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
233 ## Usage : gunzipFile($archive, $filePath, $fileName) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
234
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
235 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
236 sub gunzipFile {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
237 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
238 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
239 my ($archive, $filePath, $fileName) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
240
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
241 if ( (defined $fileName) and (defined $filePath) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
242
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
243 gunzip $archive => $filePath
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
244 or die "gunzip failed: $GunzipError\n";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
245 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
246 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
247 croak "the given filePath or the filename are undef\n" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
248 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
249
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
250 return 1;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
251 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
252 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
253
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
254
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
255 =head2 METHOD cleanUnzip
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
256
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
257 ## Description : clean zip file if the unzip is successfully run
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
258 ## Input : $archive, $filePath
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
259 ## Output : 1
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
260 ## Usage : unzipFile($archive, $want, $dir) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
261
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
262 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
263 sub cleanUnzip {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
264 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
265 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
266 my ($archive, $filePath ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
267
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
268 if ( (defined $archive) and (defined $filePath) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
269
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
270 croak "There was a problem extracting $filePath from $archive" unless (-e $filePath);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
271 unlink $archive ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
272 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
273 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
274 croak "Given filePath or the archive are undef\n" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
275 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
276
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
277 return 1;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
278 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
279 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
280
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
281 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
282
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
283
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
284 __END__
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
285
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
286 =head1 SUPPORT
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
287
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
288 You can find documentation for this module with the perldoc command.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
289
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
290 perldoc XXX.pm
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
291
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
292 =head1 Exports
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
293
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
294 =over 4
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
295
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
296 =item :ALL is ...
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
297
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
298 =back
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
299
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
300 =head1 AUTHOR
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
301
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
302 Franck Giacomoni E<lt>franck.giacomoni@clermont.inra.frE<gt>
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
303
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
304 =head1 LICENSE
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
305
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
306 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
307
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
308 =head1 VERSION
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
309
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
310 version 1 : xx / xx / 201x
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
311
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
312 version 2 : ??
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
313
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
314 =cut