X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Finterface%2Fhttp_getter%2Fhttp_getter.pl;h=1d99e65ce03bf5b552adf1c8e1a5451b07f03172;hb=d66b34e7f8a6c6ceb330c4cfc8f6a3803eba262b;hp=9ea1641b7c7b2036ca3b71216267f3fa1a448b23;hpb=dae57ab510b31d1edd21031a3433c3c0d84631de;p=helm.git diff --git a/helm/interface/http_getter/http_getter.pl b/helm/interface/http_getter/http_getter.pl index 9ea1641b7..1d99e65ce 100755 --- a/helm/interface/http_getter/http_getter.pl +++ b/helm/interface/http_getter/http_getter.pl @@ -4,7 +4,7 @@ use Env; my $HELM_CONFIGURATION_PREFIX = $ENV{"HELM_CONFIGURATION_PREFIX"}; my $HELM_CONFIGURATION_PATH = - $HELM_CONFIGURATION_PREFIX."local/lib/helm/configuration.pl"; + $HELM_CONFIGURATION_PREFIX."/local/lib/helm/configuration.pl"; # next require defines: $helm_dir, $html_link require $HELM_CONFIGURATION_PATH; @@ -18,9 +18,10 @@ use DB_File; my $cont = ""; my $d = new HTTP::Daemon LocalPort => 8081; -tie(%map, 'DB_File', 'urls_of_uris.db', O_RDONLY, 0664); +tie(%map, 'DB_File', $uris_dbm.".db", O_RDONLY, 0664); print "Please contact me at: url, ">\n"; print "helm_dir: $helm_dir\n"; +print "urls_of_uris.db: $uris_dbm.db\n"; $SIG{CHLD} = "IGNORE"; # do not accumulate defunct processes while (my $c = $d->accept) { if (fork() == 0) { @@ -55,7 +56,8 @@ while (my $c = $d->accept) { $response = $ua->request($request, \&callback); print "Storing file\n"; - open(FD, $filename); + mkdirs($filename); + open(FD, ">".$filename); print FD $cont; close(FD); @@ -95,7 +97,8 @@ while (my $c = $d->accept) { $response = $ua->request($request, \&callback); print "Storing file for the annotation\n"; - open(FD, $filename); + mkdirs($filename); + open(FD, ">".$filename); print FD $cont; close(FD); } @@ -117,7 +120,8 @@ while (my $c = $d->accept) { $response = $ua->request($request, \&callback); print "Storing file for the file to annotate\n"; - open(FD, $filename_target); + mkdirs($filename_target); + open(FD, ">".$filename_target); print FD $cont; close(FD); } @@ -144,19 +148,38 @@ EOT $res->content($merged); $c->send_response($res); } elsif ($http_method eq 'GET' and $http_path eq "/getwithtypes") { - my $do_annotate = ($cicuri =~ /\.types$/); + my $mode; + my $do_annotate; + if ($cicuri =~ /\.types$/) { + $do_annotate = 1; + $mode = "types"; + } elsif ($cicuri =~ /\.ann$/) { + $do_annotate = 1; + $mode = "ann"; + } else { + $do_annotate = 0; + } my $target_to_annotate = $cicuri; - $target_to_annotate =~ s/(.*)\.types$/$1/ if $do_annotate; + if ($mode eq "types") { + $target_to_annotate =~ s/(.*)\.types$/$1/; + } elsif ($mode eq "ann") { + $target_to_annotate =~ s/(.*)\.ann$/$1/; + } my $filename = $cicuri; $filename =~ s/cic:(.*)/$1/; $filename =~ s/theory:(.*)/$1/; my $filename_target = $helm_dir.$filename if $do_annotate; $filename = $helm_dir.$filename.".xml"; - $filename_target =~ s/(.*)\.types$/$1.xml/ if $do_annotate; + if ($mode eq "types") { + $filename_target =~ s/(.*)\.types$/$1.xml/; + } elsif ($mode eq "ann") { + $filename_target =~ s/(.*)\.ann$/$1.xml/; + } my $resolved = $map{$cicuri}; my $resolved_target = $map{$target_to_annotate} if $do_annotate; if ($do_annotate) { - print "GETWITHTYPES!!\n"; + print "GETWITHTYPES!!\n" if ($mode eq "types"); + print "GETWITHANN!!\n" if ($mode eq "ann"); print "($cicuri, $target_to_annotate) ==> ($resolved + $resolved_target) ($filename)\n"; } else { print "$cicuri ==> $resolved ($filename)\n"; @@ -165,18 +188,22 @@ EOT # Retrieves the annotation if (stat($filename)) { - print "Using local copy for the types\n"; + print "Using local copy for the types\n" if ($mode eq "types"); + print "Using local copy for the ann\n" if ($mode eq "ann"); open(FD, $filename); while() { $cont .= $_; } close(FD); } else { - print "Downloading the types\n"; + print "Downloading the types\n" if ($mode eq "types"); + print "Downloading the ann\n" if ($mode eq "ann"); $ua = LWP::UserAgent->new; $request = HTTP::Request->new(GET => "$resolved"); $response = $ua->request($request, \&callback); - print "Storing file for the types\n"; - open(FD, $filename); + print "Storing file for the types\n" if ($mode eq "types"); + print "Storing file for the ann\n" if ($mode eq "ann"); + mkdirs($filename); + open(FD, ">".$filename); print FD $cont; close(FD); } @@ -199,7 +226,8 @@ EOT $response = $ua->request($request, \&callback); print "Storing file for the file to type\n"; - open(FD, $filename_target); + mkdirs($filename_target); + open(FD, ">".$filename_target); print FD $cont; close(FD); } @@ -215,13 +243,21 @@ EOT $target =~ s/]*>//sg; $annotation =~ s/<\?xml [^?]*\?>//sg; $annotation =~ s/]*>//sg; + my $element, $endelement; + if ($mode eq "types") { + $element = ""; + $endelement = ""; + } elsif ($mode eq "ann") { + $element = ""; + $endelement = ""; + } my $merged = < $target - +$element $annotation - +$endelement EOT @@ -276,3 +312,18 @@ sub callback my ($data) = @_; $cont .= $data; } + +# Does not raise errors if could not create dirs/files + +# Too much powerful: creates even /home, /home/users/, ... +sub mkdirs +{ + my ($pathname) = @_; + my @dirs = split /\//,$pathname; + my $tmp; + foreach $dir (@dirs) { + $tmp = ((defined($tmp)) ? $tmp = $tmp."\/".$dir : ""); + mkdir($tmp,0777); + } + rmdir($tmp); +}