Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
projet
VPLPP
Commits
0ff3f684
Commit
0ff3f684
authored
Nov 05, 2020
by
Guillaume Huard
Browse files
Small fixes, removed xml parsing of the result
parent
e56ed9a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
push.pl
View file @
0ff3f684
...
...
@@ -9,6 +9,7 @@ use XML::LibXML;
$ENV
{
PERL_LWP_SSL_VERIFY_HOSTNAME
}
=
0
;
my
$url
=
'
https://moodle.caseine.org/webservice/rest/server.php
';
my
$debug
=
0
;
my
$json
=
0
;
my
$vplid
=
$ENV
{'
CASEINE_VPLID
'};
my
$token
=
$ENV
{'
CASEINE_TOKEN
'};
...
...
@@ -49,24 +50,29 @@ sub set_setting($@) {
push
@
{
$content
},
"
settingname
",
$name
,
"
settingvalue
",
$value
;
}
sub
void
($@)
{
}
my
%handlers
=
(
'
save
'
=>
\
&save
,
'
save_required_files
'
=>
\
&save
,
'
save_corrected_files
'
=>
\
&save
,
'
save_execution_files
'
=>
\
&save
,
'
get_setting
'
=>
\
&get_setting
,
'
set_setting
'
=>
\
&set_setting
'
set_setting
'
=>
\
&set_setting
,
'
info
'
=>
\
&void
);
my
@commands
=
keys
(
%handlers
);
sub
help
()
{
print
<<"END";
usage :
$0 [ --help ] [ --token value ] [ --vplid value ] command [ arguments ]
$0 [ --help ] [
--json ] [
--token value ] [ --vplid value ] command [ arguments ]
Pushes data to caseine, where :
- token is the personnal token associated to the user of this script (by default, the value of the CASEINE_TOKEN environment variable)
- vplid is the id of the involved VPL (by default, the value of the CASEINE_VPLID environment variable)
- the output is in JSON format is the --json option is given
- command is one of : @commands and its arguments are :
- filenames for save commands
- a setting name for get_setting
...
...
@@ -83,7 +89,8 @@ sub failure($) {
GetOptions
('
help|h|?
'
=>
\
&help
,
'
vplid|v=s
'
=>
\
$vplid
,
'
token|t=s
'
=>
\
$token
,
'
debug|d
'
=>
\
$debug
'
debug|d
'
=>
\
$debug
,
'
json|j
'
=>
\
$json
);
#failure "Missing command" if scalar(@ARGV) == 0;
...
...
@@ -95,6 +102,7 @@ my $content = [
wstoken
=>
"
$token
",
wsfunction
=>
"
mod_vpl_
$command
"
];
push
@
{
$content
},
"
moodlewsrestformat
",
"
json
"
if
$json
;
failure
"
Unknown command
"
unless
exists
(
$handlers
{
$command
});
&
{
$handlers
{
$command
}}(
$content
,
@ARGV
);
...
...
@@ -106,11 +114,12 @@ my $res = $ua->post( $url,
if
(
exists
(
$res
->
{'
_content
'}))
{
my
$answer
=
$res
->
{'
_content
'};
my
$parser
=
XML::
LibXML
->
new
();
my
$tree
=
$parser
->
parse_string
(
$answer
);
my
$root
=
$tree
->
getDocumentElement
;
my
@values
=
$root
->
getElementsByTagName
('
VALUE
');
print
$values
[
0
]
->
getFirstChild
->
getData
,
"
\n
";
print
$answer
;
# my $parser = XML::LibXML->new();
# my $tree = $parser->parse_string($answer);
# my $root = $tree->getDocumentElement;
# my @values = $root->getElementsByTagName('VALUE');
# print $values[0]->getFirstChild->getData, "\n";
}
else
{
failure
"
Invalid answer from server
";
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment