Ramesh-vani commited on
Commit
53f7550
·
verified ·
1 Parent(s): a1228dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -1
app.py CHANGED
@@ -473,7 +473,59 @@ async def exe(websocket,connected,key):
473
  observer.start()
474
 
475
  try:
476
- await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  except KeyboardInterrupt:
478
  pass # Handle KeyboardInterrupt to gracefully stop the observer
479
 
 
473
  observer.start()
474
 
475
  try:
476
+ # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
477
+ # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
478
+ print(base_path)
479
+ mod_command = f'cd {base_path}&& {command}'
480
+
481
+ try:
482
+ process = await asyncio.create_subprocess_shell(
483
+ mod_command,
484
+ # cwd=base_path,
485
+ stdin=asyncio.subprocess.PIPE,
486
+ stdout=asyncio.subprocess.PIPE,
487
+ stderr=asyncio.subprocess.PIPE,
488
+ # text=True,
489
+ )
490
+
491
+ async def send_message(message):
492
+ print('sending msg')
493
+ # await websocket.send(f'data: {message}')
494
+ websockets.broadcast(connected,json.dumps(message) )
495
+
496
+ # async for line in process.stdout:
497
+ # print('sending line')
498
+
499
+ # event = {
500
+ # "type": "terminal-data",
501
+ # "data": line.strip().decode('utf-8'),
502
+ # }
503
+ # await send_message(event)
504
+
505
+
506
+ # async for line in process.stderr:
507
+ # print(f'error:{line.strip()}')
508
+ # event = {
509
+ # "type": "terminal-error",
510
+ # "data": line.strip().decode('utf-8'),
511
+ # }
512
+ # await send_message(event)
513
+
514
+ await asyncio.gather(
515
+ handle_user_input(websocket, process),
516
+ read_process_output(process, websocket)
517
+ )
518
+
519
+ return_code = await process.wait()
520
+ if return_code == 0:
521
+ # await send_message('Code executed successfully')
522
+ pass
523
+ else:
524
+ # await send_message(f'error:Execution failed with return code {return_code}')
525
+ pass
526
+
527
+ except Exception as e:
528
+ await error(websocket, str(e))
529
  except KeyboardInterrupt:
530
  pass # Handle KeyboardInterrupt to gracefully stop the observer
531