Parent Directory
|
Revision Log
Revision 5243 -
(view)
(download)
(as text)
Original Path: branches/rel-2-4-dev/webwork2/clients/webwork_xmlrpc_inc.pl
| 1 : | gage | 4731 | #!/usr/bin/perl -w |
| 2 : | |||
| 3 : | =pod | ||
| 4 : | |||
| 5 : | This script will take a command and an input | ||
| 6 : | file. | ||
| 7 : | |||
| 8 : | It will list available libraries, list the contents of libraries | ||
| 9 : | or render the input file. | ||
| 10 : | |||
| 11 : | All of this is done by contacting the webservice. | ||
| 12 : | |||
| 13 : | |||
| 14 : | |||
| 15 : | =cut | ||
| 16 : | |||
| 17 : | use XMLRPC::Lite; | ||
| 18 : | use MIME::Base64 qw( encode_base64 decode_base64); | ||
| 19 : | |||
| 20 : | # configuration section | ||
| 21 : | use constant PROTOCOL => 'https'; # or 'http'; | ||
| 22 : | gage | 4733 | use constant HOSTURL => 'webwork.rochester.edu'; |
| 23 : | use constant HOSTPORT => 443; | ||
| 24 : | gage | 4731 | use constant TRANSPORT_METHOD => 'XMLRPC::Lite'; |
| 25 : | gage | 4733 | use constant REQUEST_CLASS => 'WebworkXMLRPC'; # WebworkXMLRPC is used for soap also!! |
| 26 : | use constant REQUEST_URI => 'mod_xmlrpc'; | ||
| 27 : | gage | 4731 | use constant TEMPOUTPUTFILE => '/Users/gage/Desktop/renderProblemOutput.html'; |
| 28 : | use constant COURSE => 'daemon2_course'; | ||
| 29 : | |||
| 30 : | |||
| 31 : | |||
| 32 : | # $pg{displayModes} = [ | ||
| 33 : | # "plainText", # display raw TeX for math expressions | ||
| 34 : | # "formattedText", # format math expressions using TtH | ||
| 35 : | # "images", # display math expressions as images generated by dvipng | ||
| 36 : | # "jsMath", # render TeX math expressions on the client side using jsMath | ||
| 37 : | # "asciimath", # render TeX math expressions on the client side using ASCIIMathML | ||
| 38 : | # ]; | ||
| 39 : | gage | 4733 | use constant DISPLAYMODE => 'images'; # tex and jsMath are other possibilities. |
| 40 : | gage | 4731 | |
| 41 : | |||
| 42 : | my @COMMANDS = qw( listLibraries renderProblem ); #listLib readFile tex2pdf | ||
| 43 : | |||
| 44 : | # end configuration section | ||
| 45 : | |||
| 46 : | |||
| 47 : | |||
| 48 : | |||
| 49 : | |||
| 50 : | |||
| 51 : | sub xmlrpcCall { | ||
| 52 : | my $command = shift; | ||
| 53 : | my $source = shift; | ||
| 54 : | $command = 'listLibraries' unless $command; | ||
| 55 : | |||
| 56 : | my $requestResult = TRANSPORT_METHOD | ||
| 57 : | #->uri('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_CLASS) | ||
| 58 : | -> proxy(PROTOCOL.'://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_URI); | ||
| 59 : | |||
| 60 : | my $test = [3,4,5,6]; | ||
| 61 : | my $input = setInputTable($source); | ||
| 62 : | #print "displayMode=",$input->{envir}->{displayMode},"\n"; | ||
| 63 : | local( $result); | ||
| 64 : | # use eval to catch errors | ||
| 65 : | eval { $result = $requestResult->call(REQUEST_CLASS.'.'.$command,$input) }; | ||
| 66 : | print STDERR "There were a lot of errors\n" if $@; | ||
| 67 : | print "Errors: \n $@\n End Errors\n" if $@; | ||
| 68 : | |||
| 69 : | #print "result is|", ref($result),"|"; | ||
| 70 : | |||
| 71 : | unless (ref($result) and $result->fault) { | ||
| 72 : | return $result->result(); # returns result hash | ||
| 73 : | } else { | ||
| 74 : | print 'oops ', join ', ', | ||
| 75 : | $result->faultcode, | ||
| 76 : | $result->faultstring; | ||
| 77 : | return 0; | ||
| 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 : | my $source = shift; | ||
| 138 : | $out = { | ||
| 139 : | #password => 'geometry', | ||
| 140 : | pw => 'geometry', | ||
| 141 : | set => 'set0', | ||
| 142 : | library_name => 'rochesterLibrary', | ||
| 143 : | command => 'all', | ||
| 144 : | answer_form_submitted => 1, | ||
| 145 : | course => COURSE(), | ||
| 146 : | extra_packages_to_load => [qw( AlgParserWithImplicitExpand Expr | ||
| 147 : | ExprWithImplicitExpand AnswerEvaluator | ||
| 148 : | AnswerEvaluatorMaker | ||
| 149 : | )], | ||
| 150 : | gage | 4733 | mode => DISPLAYMODE(), |
| 151 : | gage | 4731 | modules_to_evaluate => [ qw( |
| 152 : | Exporter | ||
| 153 : | DynaLoader | ||
| 154 : | GD | ||
| 155 : | WWPlot | ||
| 156 : | Fun | ||
| 157 : | Circle | ||
| 158 : | Label | ||
| 159 : | PGrandom | ||
| 160 : | Units | ||
| 161 : | Hermite | ||
| 162 : | List | ||
| 163 : | Match | ||
| 164 : | Multiple | ||
| 165 : | Select | ||
| 166 : | AlgParser | ||
| 167 : | AnswerHash | ||
| 168 : | Fraction | ||
| 169 : | VectorField | ||
| 170 : | Complex1 | ||
| 171 : | Complex | ||
| 172 : | MatrixReal1 Matrix | ||
| 173 : | Distributions | ||
| 174 : | Regression | ||
| 175 : | |||
| 176 : | )], | ||
| 177 : | envir => environment(), | ||
| 178 : | problem_state => { | ||
| 179 : | |||
| 180 : | num_of_correct_ans => 2, | ||
| 181 : | num_of_incorrect_ans => 4, | ||
| 182 : | recorded_score => 1.0, | ||
| 183 : | }, | ||
| 184 : | source => source($source), #base64 encoded | ||
| 185 : | |||
| 186 : | |||
| 187 : | |||
| 188 : | }; | ||
| 189 : | |||
| 190 : | $out; | ||
| 191 : | } | ||
| 192 : | |||
| 193 : | sub environment { | ||
| 194 : | my $envir = { | ||
| 195 : | answerDate => '4014438528', | ||
| 196 : | CAPA_Graphics_URL=>'http://webwork-db.math.rochester.edu/capa_graphics/', | ||
| 197 : | CAPA_GraphicsDirectory =>'/ww/webwork/CAPA/CAPA_Graphics/', | ||
| 198 : | CAPA_MCTools=>'/ww/webwork/CAPA/CAPA_MCTools/', | ||
| 199 : | CAPA_Tools=>'/ww/webwork/CAPA/CAPA_Tools/', | ||
| 200 : | cgiDirectory=>'Not defined', | ||
| 201 : | cgiURL => 'Not defined', | ||
| 202 : | classDirectory=> 'Not defined', | ||
| 203 : | courseName=>'Not defined', | ||
| 204 : | courseScriptsDirectory=>'/ww/webwork/system/courseScripts/', | ||
| 205 : | displayMode=>DISPLAYMODE, | ||
| 206 : | dueDate=> '4014438528', | ||
| 207 : | externalGif2EpsPath=>'not defined', | ||
| 208 : | externalPng2EpsPath=>'not defined', | ||
| 209 : | externalTTHPath=>'/usr/local/bin/tth', | ||
| 210 : | fileName=>'set0/prob1a.pg', | ||
| 211 : | formattedAnswerDate=>'6/19/00', | ||
| 212 : | formattedDueDate=>'6/19/00', | ||
| 213 : | formattedOpenDate=>'6/19/00', | ||
| 214 : | functAbsTolDefault=> 0.0000001, | ||
| 215 : | functLLimitDefault=>0, | ||
| 216 : | functMaxConstantOfIntegration=> 1000000000000.0, | ||
| 217 : | functNumOfPoints=> 5, | ||
| 218 : | functRelPercentTolDefault=> 0.000001, | ||
| 219 : | functULimitDefault=>1, | ||
| 220 : | functVarDefault=> 'x', | ||
| 221 : | functZeroLevelDefault=> 0.000001, | ||
| 222 : | functZeroLevelTolDefault=>0.000001, | ||
| 223 : | htmlDirectory =>'/ww/webwork/courses/gage_course/html/', | ||
| 224 : | htmlURL =>'http://webwork-db.math.rochester.edu/gage_course/', | ||
| 225 : | inputs_ref => { | ||
| 226 : | AnSwEr1 => '', | ||
| 227 : | AnSwEr2 => '', | ||
| 228 : | AnSwEr3 => '', | ||
| 229 : | }, | ||
| 230 : | macroDirectory=>'/ww/webwork/courses/gage_course/templates/macros/', | ||
| 231 : | numAbsTolDefault=>0.0000001, | ||
| 232 : | numFormatDefault=>'%0.13g', | ||
| 233 : | numOfAttempts=> 0, | ||
| 234 : | numRelPercentTolDefault => 0.0001, | ||
| 235 : | numZeroLevelDefault =>0.000001, | ||
| 236 : | numZeroLevelTolDefault =>0.000001, | ||
| 237 : | openDate=> '3014438528', | ||
| 238 : | PRINT_FILE_NAMES_FOR => [ 'gage'], | ||
| 239 : | probFileName => 'set0/prob1a.pg', | ||
| 240 : | problemSeed => 1234, | ||
| 241 : | problemValue =>1, | ||
| 242 : | probNum => 13, | ||
| 243 : | psvn => 54321, | ||
| 244 : | psvnNumber=> 54321, | ||
| 245 : | questionNumber => 1, | ||
| 246 : | scriptDirectory => 'Not defined', | ||
| 247 : | sectionName => 'Gage', | ||
| 248 : | sectionNumber => 1, | ||
| 249 : | sessionKey=> 'Not defined', | ||
| 250 : | setNumber =>'MAAtutorial', | ||
| 251 : | studentLogin =>'gage', | ||
| 252 : | studentName => 'Mike Gage', | ||
| 253 : | tempDirectory => '/ww/htdocs/tmp/gage_course/', | ||
| 254 : | templateDirectory=>'/ww/webwork/courses/gage_course/templates/', | ||
| 255 : | tempURL=>'http://webwork-db.math.rochester.edu/tmp/gage_course/', | ||
| 256 : | webworkDocsURL => 'http://webwork.math.rochester.edu/webwork_gage_system_html', | ||
| 257 : | }; | ||
| 258 : | $envir; | ||
| 259 : | }; | ||
| 260 : | |||
| 261 : | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |