src/HOL/Tools/ATP/scripts/remote_atp
author blanchet
Wed, 28 Jul 2010 23:01:27 +0200
changeset 38307 685d1f0f75b3
parent 38292 6659c15e7421
child 38308 a7c9cc973ca1
permissions -rwxr-xr-x
handle Perl and "libwww-perl" failures more gracefully, giving the user some clues about what goes on
     1 #!/usr/bin/env perl
     2 #
     3 # Wrapper for custom remote provers on SystemOnTPTP
     4 # Author: Fabian Immler, TU Muenchen
     5 #
     6 
     7 use warnings;
     8 use strict;
     9 use Getopt::Std;
    10 use HTTP::Request::Common;
    11 use LWP;
    12 
    13 my $SystemOnTPTPFormReplyURL =
    14   "http://www.cs.miami.edu/~tptp/cgi-bin/SystemOnTPTPFormReply";
    15 
    16 # default parameters
    17 my %URLParameters = (
    18     "NoHTML" => 1,
    19     "QuietFlag" => "-q01",
    20     "SubmitButton" => "RunSelectedSystems",
    21     "ProblemSource" => "UPLOAD",
    22     "ForceSystem" => "-force",
    23     );
    24 
    25 #----Get format and transform options if specified
    26 my %Options;
    27 getopts("hws:t:c:",\%Options);
    28 
    29 #----Usage
    30 sub usage() {
    31   print("Usage: remote_atp [<options>] <File name>\n");
    32   print("    <options> are ...\n");
    33   print("    -h            - print this help\n");
    34   print("    -w            - list available ATP systems\n");
    35   print("    -s<system>    - specified system to use\n");
    36   print("    -t<timelimit> - CPU time limit for system\n");
    37   print("    -c<command>   - custom command for system\n");
    38   print("    <File name>   - TPTP problem file\n");
    39   exit(0);
    40 }
    41 if (exists($Options{'h'})) {
    42   usage();
    43 }
    44 
    45 #----What systems flag
    46 if (exists($Options{'w'})) {
    47     $URLParameters{"SubmitButton"} = "ListSystems";
    48     delete($URLParameters{"ProblemSource"});
    49 }
    50 
    51 #----X2TPTP
    52 if (exists($Options{'x'})) {
    53     $URLParameters{"X2TPTP"} = "-S";
    54 }
    55 
    56 #----Selected system
    57 my $System;
    58 if (exists($Options{'s'})) {
    59     $System = $Options{'s'};
    60 } else {
    61     # use Vampire as default
    62     $System = "Vampire---9.0";
    63 }
    64 $URLParameters{"System___$System"} = $System;
    65 
    66 #----Time limit
    67 if (exists($Options{'t'})) {
    68     $URLParameters{"TimeLimit___$System"} = $Options{'t'};
    69 }
    70 #----Custom command
    71 if (exists($Options{'c'})) {
    72     $URLParameters{"Command___$System"} = $Options{'c'};
    73 }
    74 
    75 #----Get single file name
    76 if (exists($URLParameters{"ProblemSource"})) {
    77     if (scalar(@ARGV) >= 1) {
    78         $URLParameters{"UPLOADProblem"} = [shift(@ARGV)];
    79     } else {
    80       print("Missing problem file\n");
    81       usage();
    82       die;
    83     }
    84 }
    85 
    86 # Query Server
    87 my $Agent = LWP::UserAgent->new;
    88 if (exists($Options{'t'})) {
    89   # give server more time to respond
    90   $Agent->timeout($Options{'t'} + 10);
    91 }
    92 my $Request = POST($SystemOnTPTPFormReplyURL,
    93 	Content_Type => 'form-data',Content => \%URLParameters);
    94 my $Response = $Agent->request($Request);
    95 
    96 #catch errors / failure
    97 if(!$Response->is_success) {
    98   print "HTTP-Error: " . $Response->message . "\n";
    99   exit(-1);
   100 } elsif (exists($Options{'w'})) {
   101   print $Response->content;
   102   exit (0);
   103 } elsif ($Response->content =~ /WARNING: (\S*) does not exist/) {
   104   print "Specified system $1 does not exist\n";
   105   exit(-1);
   106 } else {
   107   print $Response->content;
   108   exit(0);
   109 }