Parent Directory
|
Revision Log
Minimal code for a client which will connect to the xmlrpc access within webwork 2 Use at your own risk :-)
1 #!/usr/bin/perl -w 2 use MIME::Base64 qw( encode_base64 decode_base64); 3 4 5 # -- SOAP::Lite -- soaplite.com -- Copyright (C) 2001 Paul Kulchenko -- 6 7 # use XMLRPC::Lite; 8 # 9 # print XMLRPC::Lite 10 # -> proxy('http://devel.webwork.rochester.edu:11002/mod_xmlrpc') 11 # -> call('Demo:bye', 25) 12 # -> result; 13 print STDERR "inputs are ", join (" | ", @ARGV), "\n"; 14 our $source; 15 16 if (@ARGV) { 17 my $command = $ARGV[0]; 18 19 warn "executing WebworkXMLRPC.$command"; 20 $source = `cat $ARGV[1]`; 21 xmlrpcCall($command); 22 23 24 } else { 25 26 print STDERR "Useage: .xmlrpc_client4.pl command file_name"; 27 28 } 29 30 31 32 33 34 35 sub xmlrpcCall { 36 my $command = shift; 37 $command = 'listLibraries' unless $command; 38 use XMLRPC::Lite; 39 my $xmlrpc = XMLRPC::Lite 40 # ->uri('http://webwork-db.math.rochester.edu/Demo/') 41 -> proxy('http://devel.webwork.rochester.edu:11002/mod_xmlrpc'); 42 43 my $test = [3,4,5,6]; 44 my $input = setInputTable(); 45 local( $result); 46 eval { $result = $xmlrpc->call("WebworkXMLRPC.$command",$input) }; 47 print STDERR "There were a lot of errors" if $@; 48 print "Errors: \n $@\n End Errors\n" if $@; 49 50 51 52 unless (ref($result) and $result->fault) { 53 if (defined($result->result()->{text}) ) { 54 $result->result()->{text} = decode_base64($result->result()->{text}); 55 } 56 print pretty_print_rh($result->result()),"\n"; #$result->result() 57 } else { 58 print 'oops ', join ', ', 59 $result->faultcode, 60 $result->faultstring; 61 } 62 } 63 64 sub source { 65 encode_base64($source); 66 } 67 sub pretty_print_rh { 68 shift if UNIVERSAL::isa($_[0] => __PACKAGE__); 69 my $rh = shift; 70 my $indent = shift || 0; 71 my $out = ""; 72 my $type = ref($rh); 73 74 if (defined($type) and $type) { 75 $out .= " type = $type; "; 76 } elsif (! defined($rh )) { 77 $out .= " type = UNDEFINED; "; 78 } 79 if ( ref($rh) =~/HASH/ or "$rh" =~/HASH/ ) { 80 $out .= "{\n"; 81 $indent++; 82 foreach my $key (sort keys %{$rh}) { 83 $out .= " "x$indent."$key => " . pretty_print_rh( $rh->{$key}, $indent ) . "\n"; 84 } 85 $indent--; 86 $out .= "\n"." "x$indent."}\n"; 87 88 } elsif (ref($rh) =~ /ARRAY/ or "$rh" =~/ARRAY/) { 89 $out .= " ( "; 90 foreach my $elem ( @{$rh} ) { 91 $out .= pretty_print_rh($elem, $indent); 92 93 } 94 $out .= " ) \n"; 95 } elsif ( ref($rh) =~ /SCALAR/ ) { 96 $out .= "scalar reference ". ${$rh}; 97 } elsif ( ref($rh) =~/Base64/ ) { 98 $out .= "base64 reference " .$$rh; 99 } else { 100 $out .= $rh; 101 } 102 103 return $out." "; 104 } 105 106 sub setInputTable_for_listLib { 107 $out = { 108 #password => 'geometry', 109 pw => 'geometry', 110 set => 'set0', 111 library_name => 'rochesterLibrary', 112 command => 'all', 113 }; 114 115 $out; 116 } 117 sub setInputTable { 118 $out = { 119 #password => 'geometry', 120 pw => 'geometry', 121 set => 'set0', 122 library_name => 'rochesterLibrary', 123 command => 'all', 124 answer_form_submitted => 1, 125 course => 'daemon_course', 126 extra_packages_to_load => [qw( AlgParserWithImplicitExpand Expr 127 ExprWithImplicitExpand AnswerEvaluator 128 AnswerEvaluatorMaker 129 )], 130 mode => undef, 131 modules_to_evaluate => [ qw( 132 Exporter 133 134 DynaLoader 135 136 137 GD 138 WWPlot 139 Fun 140 Circle 141 Label 142 143 144 PGrandom 145 Units 146 Hermite 147 148 List 149 150 151 Match 152 Multiple 153 Select 154 155 156 AlgParser 157 158 AnswerHash 159 160 161 Fraction 162 VectorField 163 164 165 Complex1 166 Complex 167 168 169 MatrixReal1 Matrix 170 171 172 Distributions 173 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(), #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=>'HTML_dpng', 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 };
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |