diff options
author | prashantsinalkar | 2019-06-28 21:44:43 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-06-28 21:44:43 +0530 |
commit | 1473227a75101f5b76d6b522da5737df2f5eb058 (patch) | |
tree | dab59c0b7970a0b059d4eeb84aafd54e14ed47e9 /instances.py | |
parent | 459d1aec769f62570af51a3a53ebe0bce4a6754c (diff) | |
download | R_on_Cloud_Web_Interface-1473227a75101f5b76d6b522da5737df2f5eb058.tar.gz R_on_Cloud_Web_Interface-1473227a75101f5b76d6b522da5737df2f5eb058.tar.bz2 R_on_Cloud_Web_Interface-1473227a75101f5b76d6b522da5737df2f5eb058.zip |
added basic interface for development
Diffstat (limited to 'instances.py')
-rw-r--r-- | instances.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/instances.py b/instances.py new file mode 100644 index 0000000..c6f4f1a --- /dev/null +++ b/instances.py @@ -0,0 +1,61 @@ +# importing the global modules +import pexpect +import os +import re +import time +import sys +import psutil +import requests +import json +import urllib.request +import base64 + +from datetime import datetime +from django.template.loader import render_to_string, get_template +from django.core.mail import EmailMultiAlternatives +# importing the local variables +from R_on_Cloud.settings import PROJECT_DIR +from R_on_Cloud.config import (BIN) + +URL = "http://127.0.0.1:8001/rscript" + +def execute_code(code, token): + # Check for system commands + system_commands = re.compile( + 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|' + 'unix_x\(.*\)|unix_s\(.*\)|host|newfun' + '|execstr|ascii|mputl|dir\(\)' + ) + if system_commands.search(code): + return { + 'output': 'System Commands not allowed', + } + + code = re.sub(r"View\(", "print(", code) + + + + + body = {'code': code} + req = urllib.request.Request(URL) + req.add_header('Content-Type', 'application/json; charset=utf-8') + jsondata = json.dumps(body) + jsondataasbytes = jsondata.encode('utf-8') # needs to be bytes always as it R code + req.add_header('Content-Length', len(jsondataasbytes)) + print (jsondataasbytes) + result = urllib.request.urlopen(req, jsondataasbytes) + result = result.read().decode("utf8") + print("----------", result) + #print("----", json.loads(result)['value']) + output = json.loads(result)["output"] + print ("-------------------------------", output) + #output = "okk" + data = { + 'output': output + } + return data +#https://github.com/trestletech/plumber/issues/105 +def trim(output): + output = [line for line in output.split('\n') if line.strip() != ''] + output = '\n'.join(output) + return output |