示例#1
0
def vizualize_request(message):
    print ("viz_request!!")
    string = message['data'] #unicode로 받아짐..!!!! 중요!!
    # string = string.encode('latin-1').decode('utf-8') #라틴에서 utf-8로..
    python_v = check_version(message['version'])
    print ("viz_request : python compile !!\n")
    print (string)
    try:
        if not (os.path.isdir(app_path + '/userfile')):
            os.makedirs(os.path.join(app_path + '/userfile'))
    except OSError as e:
        if e.errno != errno.EEXIST:
            print("Failed to create Directory!!")
            raise

    filepath = os.path.join(app_path + '/userfile/',session['username'] + '.py')

    fid = open(filepath,"w")
    if os.path.isfile(filepath):
        fid.write(string)
    fid.close()

    path = './' + session['username'] + '.py'
    res = docker_container.run(python_v, path)
    if res['state'] == 'success':
        viz_path = app_path + '/userfile/'+ session['username'] +'.py'
        viz_data = execute_return_json(viz_path)
        print (viz_data)
        emit("viz_response", {'data': viz_data})
    else:
        stderr = res['stderr']
        emit("viz_response", {'data' : stderr})
示例#2
0
def run_request(message):
    string = message['data'] #unicode로 받아짐..!!!! 중요!!
    # string = string.encode('latin-1').decode('utf-8') #라틴에서 utf-8로..
    python_v = check_version(message['version'])
    print ("run_request : python compile !!\n")
    try:
        if not (os.path.isdir(app_path + '/userfile')):
            os.makedirs(os.path.join(app_path + '/userfile'))
    except OSError as e:
        if e.errno != errno.EEXIST:
            print("Failed to create Directory!!")
            raise
    filepath = os.path.join(app_path + '/userfile/',session['username'] + '.py')
    print(filepath)

    fid = open(filepath,"w")
    if os.path.isfile(filepath):
        fid.write(string)
    fid.close()

    # docker run
    path = './' + session['username'] + '.py'
    res = docker_container.run(python_v, path)
    if res['state'] == 'success':
        stdout = res['stdout']
        stdout = stdout.strip()
        stdout = python_version(python_v) + stdout  #sys.version -> python version
        print(stdout)
        emit("run_response", {'data' : stdout})
    else:
        stderr = res['stderr']
        print(stderr)
        emit("run_response", {'data' : stderr})
示例#3
0
import sys

sys.path.append('/home/ubuntu/sv_flask/app/docker')
import docker_container

result = docker_container.run("python2", "./user_0.py")
print("result")
print(result)