[system] / tags / rel-2-2-pre2 / webwork2 / clients / webwork_soap_client.pl Repository:
ViewVC logotype

View of /tags/rel-2-2-pre2/webwork2/clients/webwork_soap_client.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3947 - (download) (as text) (annotate)
Sun Jan 22 03:50:43 2006 UTC (7 years, 4 months ago)
File size: 7053 byte(s)
This commit was manufactured by cvs2svn to create tag 'rel-2-2-pre2'.

    1 #!/usr/local/bin/perl -w
    2 
    3 use SOAP::Lite;
    4 
    5 #  configuration section
    6 use constant  HOSTURL  =>  'devel.webwork.rochester.edu';
    7 use constant  HOSTPORT =>  8002;
    8 use constant  TRANSPORT_METHOD => 'SOAP::Lite';
    9 use constant  REQUEST_CLASS =>'WebworkXMLRPC';  # WebworkXMLRPC is used for soap also!!
   10 use constant  REQUEST_URI   =>'mod_soap';
   11 
   12 my @COMMANDS = qw( listLibraries    renderProblem  ); #listLib  readFile tex2pdf
   13 
   14 # $pg{displayModes} = [
   15 #   "plainText",     # display raw TeX for math expressions
   16 #   "formattedText", # format math expressions using TtH
   17 #   "images",        # display math expressions as images generated by dvipng
   18 #   "jsMath",        # render TeX math expressions on the client side using jsMath
   19 #   "asciimath",     # render TeX math expressions on the client side using ASCIIMathML
   20 # ];
   21 use constant DISPLAYMODE   => 'images';
   22 
   23 # end configuration section
   24 use MIME::Base64 qw( encode_base64 decode_base64);
   25 
   26 
   27 print STDERR "inputs are ", join (" | ", @ARGV), "\n";
   28 our $source;
   29 
   30 if (@ARGV) {
   31     my $command = $ARGV[0];
   32 
   33     warn "executing WebworkXMLRPC.$command";
   34     $source = (defined $ARGV[1]) ? `cat $ARGV[1]` : '' ;
   35   xmlrpcCall($command);
   36 
   37 
   38 } else {
   39 
   40   print STDERR "Useage: ./webwork_soap_client.pl command   inputs\n";
   41   print STDERR "For example: ./webwork_soap_client renderProblem   input.txt\n";
   42   print STDERR "For example: ./webwork_soap_client listLibraries   \n";
   43   print STDERR "Commands are: ", join(" ", @COMMANDS), "\n";
   44 
   45 }
   46 
   47 
   48 
   49 sub xmlrpcCall {
   50   my $command = shift;
   51   $command   = 'listLibraries' unless $command;
   52 
   53     my $requestResult = TRANSPORT_METHOD
   54           ->uri('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_CLASS)
   55       -> proxy('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_URI);
   56 
   57     my $test = [3,4,5,6];
   58     my $input = setInputTable();
   59     print "displayMode=",$input->{envir}->{displayMode},"\n";
   60     local( $result);
   61     # use eval to catch errors
   62     eval { $result = $requestResult->call("$command",$input) };
   63     print STDERR "There were a lot of errors\n" if $@;
   64     print "Errors: \n $@\n End Errors\n" if $@;
   65 
   66     print "result is|", ref($result),"|";
   67 
   68     unless (ref($result) and $result->fault) {
   69 
   70       if (ref($result->result())=~/HASH/ and defined($result->result()->{text}) ) {
   71         $result->result()->{text} = decode_base64($result->result()->{text});
   72       }
   73     print  pretty_print_rh($result->result()),"\n";  #$result->result()
   74     } else {
   75     print 'oops ', join ', ',
   76       $result->faultcode,
   77       $result->faultstring;
   78     }
   79 }
   80 
   81 sub source {
   82   encode_base64($source);
   83 }
   84 sub pretty_print_rh {
   85     shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
   86   my $rh = shift;
   87   my $indent = shift || 0;
   88   my $out = "";
   89   my $type = ref($rh);
   90 
   91   if (defined($type) and $type) {
   92     $out .= " type = $type; ";
   93   } elsif (! defined($rh )) {
   94     $out .= " type = UNDEFINED; ";
   95   }
   96   return $out." " unless defined($rh);
   97 
   98   if ( ref($rh) =~/HASH/ or "$rh" =~/HASH/ ) {
   99       $out .= "{\n";
  100       $indent++;
  101     foreach my $key (sort keys %{$rh})  {
  102       $out .= "  "x$indent."$key => " . pretty_print_rh( $rh->{$key}, $indent ) . "\n";
  103     }
  104     $indent--;
  105     $out .= "\n"."  "x$indent."}\n";
  106 
  107   } elsif (ref($rh)  =~  /ARRAY/ or "$rh" =~/ARRAY/) {
  108       $out .= " ( ";
  109     foreach my $elem ( @{$rh} )  {
  110       $out .= pretty_print_rh($elem, $indent);
  111 
  112     }
  113     $out .=  " ) \n";
  114   } elsif ( ref($rh) =~ /SCALAR/ ) {
  115     $out .= "scalar reference ". ${$rh};
  116   } elsif ( ref($rh) =~/Base64/ ) {
  117     $out .= "base64 reference " .$$rh;
  118   } else {
  119     $out .=  $rh;
  120   }
  121 
  122   return $out." ";
  123 }
  124 
  125 sub setInputTable_for_listLib {
  126   $out = {
  127     #password    =>  'geometry',
  128     pw          =>   'geometry',
  129     set         =>   'set0',
  130     library_name =>  'rochesterLibrary',
  131     command      =>  'all',
  132   };
  133 
  134   $out;
  135 }
  136 sub setInputTable {
  137   $out = {
  138     #password    =>  'geometry',
  139     pw          =>   'geometry',
  140     set         =>   'set0',
  141     library_name =>  'rochesterLibrary',
  142     command      =>  'all',
  143     answer_form_submitted   => 1,
  144     course                  => 'daemon_course',
  145     extra_packages_to_load  => [qw( AlgParserWithImplicitExpand Expr
  146                                     ExprWithImplicitExpand AnswerEvaluator
  147                                     AnswerEvaluatorMaker
  148     )],
  149     mode                    => 'HTML_dpng',
  150     modules_to_evaluate     => [ qw(
  151 Exporter
  152 
  153 DynaLoader
  154 
  155 
  156 GD
  157 WWPlot
  158 Fun
  159 Circle
  160 Label
  161 
  162 
  163 PGrandom
  164 Units
  165 Hermite
  166 
  167 List
  168 
  169 
  170 Match
  171 Multiple
  172 Select
  173 
  174 
  175 AlgParser
  176 
  177 AnswerHash
  178 
  179 
  180 Fraction
  181 VectorField
  182 
  183 
  184 Complex1
  185 Complex
  186 
  187 
  188 MatrixReal1 Matrix
  189 
  190 
  191 Distributions
  192 
  193 Regression
  194 
  195     )],
  196     envir                   => environment(),
  197     problem_state           => {
  198 
  199       num_of_correct_ans  => 2,
  200       num_of_incorrect_ans => 4,
  201       recorded_score       => 1.0,
  202     },
  203     source                   => source(),  #base64 encoded
  204 
  205 
  206 
  207   };
  208 
  209   $out;
  210 }
  211 
  212 sub environment {
  213   my $envir = {
  214     answerDate  => '4014438528',
  215     CAPA_Graphics_URL=>'http://webwork-db.math.rochester.edu/capa_graphics/',
  216     CAPA_GraphicsDirectory =>'/ww/webwork/CAPA/CAPA_Graphics/',
  217     CAPA_MCTools=>'/ww/webwork/CAPA/CAPA_MCTools/',
  218     CAPA_Tools=>'/ww/webwork/CAPA/CAPA_Tools/',
  219     cgiDirectory=>'Not defined',
  220     cgiURL => 'Not defined',
  221     classDirectory=> 'Not defined',
  222     courseName=>'Not defined',
  223     courseScriptsDirectory=>'/ww/webwork/system/courseScripts/',
  224     displayMode=>DISPLAYMODE,
  225     dueDate=> '4014438528',
  226     externalGif2EpsPath=>'not defined',
  227     externalPng2EpsPath=>'not defined',
  228     externalTTHPath=>'/usr/local/bin/tth',
  229     fileName=>'set0/prob1a.pg',
  230     formattedAnswerDate=>'6/19/00',
  231     formattedDueDate=>'6/19/00',
  232     formattedOpenDate=>'6/19/00',
  233     functAbsTolDefault=> 0.0000001,
  234     functLLimitDefault=>0,
  235     functMaxConstantOfIntegration=> 1000000000000.0,
  236     functNumOfPoints=> 5,
  237     functRelPercentTolDefault=> 0.000001,
  238     functULimitDefault=>1,
  239     functVarDefault=> 'x',
  240     functZeroLevelDefault=> 0.000001,
  241     functZeroLevelTolDefault=>0.000001,
  242     htmlDirectory =>'/ww/webwork/courses/gage_course/html/',
  243     htmlURL =>'http://webwork-db.math.rochester.edu/gage_course/',
  244     inputs_ref => {
  245          AnSwEr1 => '',
  246          AnSwEr2 => '',
  247          AnSwEr3 => '',
  248     },
  249     macroDirectory=>'/ww/webwork/courses/gage_course/templates/macros/',
  250     numAbsTolDefault=>0.0000001,
  251     numFormatDefault=>'%0.13g',
  252     numOfAttempts=> 0,
  253     numRelPercentTolDefault => 0.0001,
  254     numZeroLevelDefault =>0.000001,
  255     numZeroLevelTolDefault =>0.000001,
  256     openDate=> '3014438528',
  257     PRINT_FILE_NAMES_FOR => [ 'gage'],
  258     probFileName => 'set0/prob1a.pg',
  259     problemSeed  => 1234,
  260     problemValue =>1,
  261     probNum => 13,
  262     psvn => 54321,
  263     psvnNumber=> 54321,
  264     questionNumber => 1,
  265     scriptDirectory => 'Not defined',
  266     sectionName => 'Gage',
  267     sectionNumber => 1,
  268     sessionKey=> 'Not defined',
  269     setNumber =>'MAAtutorial',
  270     studentLogin =>'gage',
  271     studentName => 'Mike Gage',
  272     tempDirectory => '/ww/htdocs/tmp/gage_course/',
  273     templateDirectory=>'/ww/webwork/courses/gage_course/templates/',
  274     tempURL=>'http://webwork-db.math.rochester.edu/tmp/gage_course/',
  275     webworkDocsURL => 'http://webwork.math.rochester.edu/webwork_gage_system_html',
  276   };
  277   $envir;
  278 };

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9