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