create remote evaluation
This commit is contained in:
88
app/assets/remote_scripts/client_script.ps1
Normal file
88
app/assets/remote_scripts/client_script.ps1
Normal file
@@ -0,0 +1,88 @@
|
||||
# run like this: powershell.exe -noprofile -executionpolicy bypass -file path\to\client_script.ps1 path\to\project_root
|
||||
|
||||
# CodeOcean Remote Client v0.4
|
||||
|
||||
#file_info format: <path/to/file/><file_name>=<id> (src/frog.java=34)
|
||||
#file_path format: <path/to/file/><file_name>
|
||||
|
||||
param (
|
||||
[string]$project_root
|
||||
)
|
||||
if ( !($project_root | select-string -pattern '[/\\]$') ){
|
||||
$project_root += '/'
|
||||
}
|
||||
|
||||
|
||||
function post_web_request ($content_type, $data, $url){
|
||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($data)
|
||||
[System.Net.HttpWebRequest] $web_request = [System.Net.WebRequest]::Create($url)
|
||||
$web_request.Method = 'POST'
|
||||
$web_request.ContentType = $content_type
|
||||
$web_request.ContentLength = $buffer.Length;
|
||||
|
||||
$request_stream = $web_request.GetRequestStream()
|
||||
$request_stream.Write($buffer, 0, $buffer.Length)
|
||||
$request_stream.Flush()
|
||||
$request_stream.Close()
|
||||
|
||||
[System.Net.HttpWebResponse] $web_response = $web_request.GetResponse()
|
||||
$stream_reader = new-object System.IO.StreamReader($web_response.GetResponseStream())
|
||||
$result = $stream_reader.ReadToEnd()
|
||||
return $result
|
||||
}
|
||||
|
||||
function find_file ($file_name){
|
||||
$search_result = get-childitem -recurse -path $project_root -filter $file_name
|
||||
if( !$search_result.exists ){
|
||||
write-host "Error: $file_name could not be found under $project_root."
|
||||
exit 1
|
||||
}elseif( $search_result.gettype().name -eq 'Object[]' ){
|
||||
$search_result = $search_result[0]
|
||||
}
|
||||
return $search_result
|
||||
}
|
||||
|
||||
function get_file ($file_path){
|
||||
$path_to_file = $project_root
|
||||
$path_to_file += ($file_path | select-string -pattern '^.+/').matches.value
|
||||
$file_name = ($file_path | select-string -pattern '[^/]+$').matches.value
|
||||
$file = get-childitem -path $path_to_file -filter $file_name
|
||||
if( !$file.exists ){
|
||||
write-host "Warning: $file_name should be in $path_to_file, but it is not. Searching whole project..."
|
||||
$file = find_file $file_name
|
||||
write-host 'Using '$file.fullname'.'
|
||||
}
|
||||
return $file
|
||||
}
|
||||
|
||||
function get_escaped_file_content ($file){
|
||||
$content = [IO.File]::ReadAllText($file.fullname)
|
||||
$content = $content -replace "`r`n", '\n'
|
||||
$content = $content -replace "`n", '\n'
|
||||
$content = $content.replace('"', '\"')
|
||||
return $content
|
||||
}
|
||||
|
||||
function get_file_attributes ($file_info){
|
||||
$file = get_file ($file_info | select-string -pattern '^.*(?==)').matches.value
|
||||
$escaped_file_content = get_escaped_file_content $file
|
||||
$file_id = ($file_info | select-string -pattern '[^=]+$').matches.value
|
||||
return "{`"file_id`": $file_id,`"content`": `"$escaped_file_content`"}"
|
||||
}
|
||||
|
||||
$co_file = get_file '.co'
|
||||
|
||||
$file_array = get-content $co_file.fullname
|
||||
|
||||
$validation_token = $file_array[0]
|
||||
|
||||
$files_attributes = get_file_attributes $file_array[1]
|
||||
|
||||
for ($i = 2; $i -lt $file_array.length; $i++){
|
||||
$files_attributes += ', '
|
||||
$files_attributes += get_file_attributes $file_array[$i]
|
||||
}
|
||||
|
||||
$post_data = "{`"remote_evaluation`": {`"validation_token`": `"$validation_token`",`"files_attributes`": [$files_attributes]}}"
|
||||
|
||||
post_web_request 'application/json' $post_data 'http://codeocean.openhpi.de/evaluate'
|
58
app/assets/remote_scripts/client_script.sh
Normal file
58
app/assets/remote_scripts/client_script.sh
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CodeOcean Remote Client v0.4
|
||||
|
||||
#file_info format: <path/to/file/><file_name>=<id> (src/frog.java=34)
|
||||
#file_path format: <path/to/file/><file_name>
|
||||
|
||||
|
||||
project_root="${1%/}"
|
||||
|
||||
function get_valid_file_path {
|
||||
file_path="$project_root/$1"
|
||||
if [ -e "$file_path" ]; then
|
||||
valid_file_path="$file_path"
|
||||
else
|
||||
file_name="${1##*/}"
|
||||
valid_file_path="$(find "$project_root" -name "$file_name" | head -1)"
|
||||
if ! [ "$valid_file_path" ]; then
|
||||
path_to_file="$(echo "$1" | grep -oP '^.+/')"
|
||||
echo "Error: $file_name is not in $project_root/$path_to_file and could not be found under $project_root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "$valid_file_path"
|
||||
}
|
||||
|
||||
function get_escaped_file_content {
|
||||
file_path="$1"
|
||||
cat "$file_path" |
|
||||
perl -p -e 's@\r\n@\\n@g' |
|
||||
perl -p -e 's@\n@\\n@g' |
|
||||
perl -p -e 's@"@\\"@g'
|
||||
}
|
||||
|
||||
function get_file_attributes {
|
||||
file_info="$1"
|
||||
file_path="$(get_valid_file_path "${file_info%=*}")"
|
||||
escaped_file_content="$(get_escaped_file_content "$file_path")"
|
||||
file_id="${file_info##*=}"
|
||||
echo "{\"file_id\": $file_id,\"content\": \"$escaped_file_content\"}"
|
||||
}
|
||||
|
||||
|
||||
co_file_path="$(get_valid_file_path '.co')"
|
||||
mapfile -t file_array < "$co_file_path"
|
||||
|
||||
validation_token="${file_array[0]}"
|
||||
|
||||
files_attributes="$(get_file_attributes "${file_array[1]}")"
|
||||
|
||||
for ((i = 2; i < ${#file_array[@]}; i++)); do
|
||||
files_attributes+=", $(get_file_attributes "${file_array[i]}")"
|
||||
done
|
||||
|
||||
post_data="{\"remote_evaluation\": {\"validation_token\": \"$validation_token\",\"files_attributes\": [$files_attributes]}}"
|
||||
|
||||
curl -H 'Content-Type: application/json' --data "$post_data" http://codeocean.openhpi.de/evaluate
|
||||
echo
|
68
app/assets/remote_scripts/client_script_osx.sh
Normal file
68
app/assets/remote_scripts/client_script_osx.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CodeOcean Remote Client v0.4
|
||||
|
||||
#file_info format: <path/to/file/><file_name>=<id> (src/frog.java=34)
|
||||
#file_path format: <path/to/file/><file_name>
|
||||
|
||||
|
||||
project_root="${1%/}"
|
||||
declare -a file_array
|
||||
|
||||
function get_valid_file_path {
|
||||
file_path="$project_root/$1"
|
||||
if [ -e "$file_path" ]; then
|
||||
valid_file_path="$file_path"
|
||||
else
|
||||
file_name="${1##*/}"
|
||||
valid_file_path="$(find "$project_root" -name "$file_name" | head -1)"
|
||||
if ! [ "$valid_file_path" ]; then
|
||||
path_to_file="$(echo "$1" | pcregrep -o '^.+/')"
|
||||
echo "Error: $file_name is not in $project_root/$path_to_file and could not be found under $project_root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "$valid_file_path"
|
||||
}
|
||||
|
||||
function get_escaped_file_content {
|
||||
file_path="$1"
|
||||
cat "$file_path" |
|
||||
perl -p -e 's@\r\n@\\n@g' |
|
||||
perl -p -e 's@\n@\\n@g' |
|
||||
perl -p -e 's@"@\\"@g'
|
||||
}
|
||||
|
||||
function get_file_attributes {
|
||||
file_info="$1"
|
||||
file_path="$(get_valid_file_path "${file_info%=*}")"
|
||||
escaped_file_content="$(get_escaped_file_content "$file_path")"
|
||||
file_id="${file_info##*=}"
|
||||
echo "{\"file_id\": $file_id,\"content\": \"$escaped_file_content\"}"
|
||||
}
|
||||
|
||||
function read_file_to_array {
|
||||
let i=0
|
||||
while IFS=$'\n' read -r line_data; do
|
||||
file_array[i]="${line_data}"
|
||||
((++i))
|
||||
done < $1
|
||||
}
|
||||
|
||||
|
||||
co_file_path="$(get_valid_file_path '.co')"
|
||||
read_file_to_array $co_file_path
|
||||
|
||||
validation_token="${file_array[0]}"
|
||||
|
||||
files_attributes="$(get_file_attributes "${file_array[1]}")"
|
||||
|
||||
for ((i = 2; i < ${#file_array[@]}; i++)); do
|
||||
files_attributes+=", $(get_file_attributes "${file_array[i]}")"
|
||||
done
|
||||
|
||||
post_data="{\"remote_evaluation\": {\"validation_token\": \"$validation_token\",\"files_attributes\": [$files_attributes]}}"
|
||||
|
||||
#echo ${post_data}
|
||||
curl -H 'Content-Type: application/json' --data "$post_data" http://codeocean.openhpi.de/evaluate
|
||||
echo
|
Reference in New Issue
Block a user