Skip to content
Snippets Groups Projects
Commit c748d0f5 authored by Jennifer Lindgren's avatar Jennifer Lindgren
Browse files

Backend: Run file and reset console temp file socketio methods.

parent a6a9a4b0
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -382,3 +382,49 @@ def run_cmd(data):
emit('runningDone', {
'on': 'runningDone'
}, room = 'user' + str(user_id))
@socketio.on('runFile')
def run_file(data):
data = json.loads(data)
file = data['file']
user_id = data['userId']
project_id = file['projectId']
file_path = str(project_id) + '/'
file_path += file['parent'] + '/' + file['name'] if file['parent'] else file['name']
p = subprocess.Popen(['python3', file_path], stdout=PIPE, stderr=PIPE)
while True:
line = p.stdout.readline().decode('utf-8')
if line != '':
emit('consoleOutput', {
'on': 'consoleOutput',
'consoleOutput': line.rstrip(),
'successful': True
}, room = 'user' + str(user_id))
else:
while True:
err = p.stderr.readline().decode('utf-8')
if err != '':
emit('consoleOutput', {
'on': 'consoleOutput',
'consoleOutput': err.rstrip(),
'successful': False
}, room = 'user' + str(user_id))
else:
break
break
emit('runningDone', {
'on': 'runningDone'
}, room = 'user' + str(user_id))
@socketio.on('resetConsoleFile')
def reset_console_file(data):
data = json.loads(data)
user_id = data['userId']
project_id = data['projectId']
user = db.get_user(user_id)
viewer = get_viewer(user.username, project_id)
if viewer['cmdFilePath']:
os.remove(viewer['cmdFilePath'])
viewer['cmdFilePath'] = None
\ No newline at end of file
def foo(num):
return num * 3
foo(3)
pass
3 + 3
while True:
break
i = 0
while i < 3:
i += 1
3 + 3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment