53
53
}
54
54
55
55
56
- # print "credentials: ", join(" | ", %credentials), "\n";
56
+ # print "credentials: ", join(" | ", %credentials), "\n";
57
57
58
58
my @COMMANDS = qw( listLibraries renderProblem listLib readFile tex2pdf ) ;
59
59
62
62
63
63
# end configuration section
64
64
65
- our $courseName = $credentials {courseID };
65
+ our $courseID = $credentials {courseID };
66
66
67
67
print STDERR " inputs are " , join (" | " , @ARGV ), " \n " ;
68
68
our $source ;
80
80
userID => $credentials {userID },
81
81
session_key => $credentials {session_key },
82
82
);
83
- # initialize client with source
84
- # $xmlrpc_client->encodeSource($source);
85
83
86
84
# prepare additional input values
87
85
97
95
if (-r $ARGV [1] ) {
98
96
$source = ` cat $ARGV [1]` ;
99
97
$xmlrpc_client -> encodeSource($source );
100
- my $input = { password => $credentials {password },};
98
+ my $input = {
99
+ userID => $credentials {userID }||' ' ,
100
+ session_key => $credentials {session_key }||' ' ,
101
+ courseID => $credentials {courseID }||' ' ,
102
+ courseName => $credentials {courseID }||' ' ,
103
+ password => $credentials {password }||' ' ,
104
+ site_password => $credentials {site_password }||' ' ,
105
+ };
106
+ # print STDERR "input is ", %$input,"\n";
101
107
$result = $xmlrpc_client -> xmlrpcCall($command , $input );
108
+ print " \n\n Result of renderProblem \n\n " ;
102
109
print pretty_print_rh($result );
103
110
} else {
104
111
print STDERR " Can't read source file $ARGV [1]\n " ;
107
114
print STDERR " Useage: ./webwork_xmlrpc_client.pl command <file_name>\n " ;
108
115
}
109
116
} when (' listLibraries' ) {
110
- my $input = { password => $credentials {password },};
111
- $result = $xmlrpc_client -> xmlrpcCall($command , $input );
117
+ my $input = {
118
+ userID => $credentials {userID }||' ' ,
119
+ session_key => $credentials {session_key }||' ' ,
120
+ courseID => $credentials {courseID }||' ' ,
121
+ password => $credentials {password }||' ' ,
122
+ site_password => $credentials {site_password }||' ' ,
123
+ };
124
+ # print STDERR "ww_xmlrpc_client: input for listLibraries command is ", %$input,"\n";
125
+ eval {
126
+ $result = $xmlrpc_client -> xmlrpcCall($command , $input );
127
+ };
112
128
if (defined ($result ) ) {
113
129
my @lib_array = @ { $result -> {ra_out } };
114
- print STDOUT " The libraries available in course $courseName are:\n\t " , join (" \n\t " , @lib_array ), " \n " ;
130
+ print STDOUT " ww_xmlrpc_client: The libraries available in course $courseID are:\n\t " , join (" \n\t " , @lib_array ), " \n " ;
115
131
} else {
116
- print STDOUT " No libraries available for course $courseName \n " ;
132
+ print STDOUT " ww_xmlrpc_client: No libraries available for course $courseID \n " ;
117
133
}
118
134
} when (' listLib' ) {
119
135
$result = listLib( @ARGV );
120
136
my $command = $ARGV [1];
121
-
137
+ print " listLib returned \n " ;
122
138
print pretty_print_rh($result );
139
+ print " \n " ;
123
140
124
141
} when (' listSets' ) {
125
142
$input = { site_password => ' xmluser' ,
126
143
password => $credentials {password },
127
- user => $credentials {userID },
144
+ userID => $credentials {userID },
128
145
courseID => $credentials {courseID },
129
146
};
130
147
my $result = $xmlrpc_client -> xmlrpcCall($command , $input );
133
150
print STDERR " Command $command not yet implemented\n "
134
151
} when (' tex2pdf' ) {
135
152
print STDERR " Command $command not yet implemented\n "
153
+ } default {
154
+ print STDERR " Command '$command ' not recognized. Commands " ,@COMMANDS ;
136
155
}
137
156
}
138
157
151
170
152
171
153
172
154
- # sub xmlrpcCall {
155
- # my $command = shift;
156
- # my $input = shift||{};
157
- # $command = 'listLibraries' unless defined $command;
158
- # my $std_input = standard_input();
159
- #
160
- # $input = {%$std_input, %$input}; # concatenate and override standard_input
161
- #
162
- # my $requestResult = TRANSPORT_METHOD
163
- # #->uri('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_CLASS)
164
- # -> proxy(PROTOCOL.'://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_URI);
165
- #
166
- # if ($UNIT_TESTS_ON) {
167
- # print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall issued with command $command\n";
168
- # print STDERR "WebworkClient.pm ".__LINE__." input is: ",join(" ", %$input);
169
- # print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall $command returned $requestResult\n";
170
- # }
171
- # local( $result);
172
- # # use eval to catch errors
173
- # eval { $result = $requestResult->call(REQUEST_CLASS.'.'.$command,$input) };
174
- # print STDERR "There were a lot of errors\n" if $@;
175
- # print "Errors: \n $@\n End Errors\n" if $@;
176
- #
177
- #
178
- # unless (ref($result) and $result->fault) {
179
- #
180
- # if (ref($result->result())=~/HASH/ and defined($result->result()->{text}) ) {
181
- # $result->result()->{text} = decode_base64($result->result()->{text});
182
- # }
183
- # print pretty_print_rh($result->result()),"\n"if $UNIT_TESTS_ON;
184
- # $self->{output} = $result->result();
185
- # $self->{session_key}=$self->{output}->{session_key}; # update session key
186
- # return $result->result();
187
- #
188
- # } else {
189
- # print STDERR 'oops ', join ', ',
190
- # "command:",
191
- # $command,
192
- # "\nfaultcode:",
193
- # $result->faultcode,
194
- # "\nfaultstring:",
195
- # $result->faultstring;
196
- # return undef;
197
- #
198
- # }
199
- # }
200
-
173
+
201
174
sub source {
202
175
return " " unless $source ;
203
176
return encode_base64($source );
@@ -208,9 +181,9 @@ sub listLib {
208
181
my $result ;
209
182
given ($ARGS [1]) {
210
183
when (" all" ) {
211
- $input = { site_password => ' xmluser' ,
184
+ $input = { site_password => ' xmluser' ,
212
185
password => $credentials {password },
213
- user => $credentials {userID },
186
+ userID => $credentials {userID },
214
187
courseID => $credentials {courseID },
215
188
command => ' all' ,
216
189
};
@@ -220,9 +193,9 @@ sub listLib {
220
193
my %options = @ARGS [2..$#ARGS ];
221
194
my $path = $options {-path} || ' ' ;
222
195
my $maxdepth = defined ($options {-depth}) ? $options {-depth}: 10000;
223
- $input = { site_password => ' xmluser' ,
196
+ $input = { site_password => ' xmluser' ,
224
197
password => $credentials {password },
225
- user => $credentials {userID },
198
+ userID => $credentials {userID },
226
199
courseID => $credentials {courseID },
227
200
command => ' dirOnly' ,
228
201
dirPath => $path ,
@@ -236,7 +209,7 @@ sub listLib {
236
209
my $path = $options {-path} || ' ' ;
237
210
$input = { site_password => ' xmluser' ,
238
211
password => $credentials {password },
239
- user => $credentials {userID },
212
+ userID => $credentials {userID },
240
213
courseID => $credentials {courseID },
241
214
command => ' files' ,
242
215
dirPath => $path ,
0 commit comments