Ramesh-vani commited on
Commit
d56852a
·
verified ·
1 Parent(s): 97715fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -44
app.py CHANGED
@@ -298,59 +298,60 @@ async def handle_user_input(websocket,key, process, connected):
298
  print(f'Received user input: {event}')
299
  try:
300
  if event["command"]["type"]=="shell":
301
- # await asyncio.sleep(0.1)
302
- # if process.returncode is not None:
303
- # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
304
- # directory_path = base_path
305
- # event_handler = FileHandler(websocket,connected)
306
- # observer = Observer()
307
- # observer.schedule(event_handler, path=directory_path, recursive=True)
308
- # observer.start()
309
 
310
- # try:
311
- # # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
312
- # # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
313
- # print(base_path)
314
- # mod_command = f'cd {base_path}&& {event["command"]["command"]}'
315
 
316
- # try:
317
- # process = await asyncio.create_subprocess_shell(
318
- # mod_command,
319
- # # cwd=base_path,
320
- # stdin=asyncio.subprocess.PIPE,
321
- # stdout=asyncio.subprocess.PIPE,
322
- # stderr=asyncio.subprocess.PIPE,
323
- # # text=True,
324
- # )
325
 
326
- # async def send_message(message):
327
- # print('sending msg')
328
- # # await websocket.send(f'data: {message}')
329
- # websockets.broadcast(connected,json.dumps(message) )
330
 
331
 
332
 
333
- # await asyncio.gather(
334
- # handle_user_input(websocket,key, process, connected),
335
- # read_process_output(process, websocket)
336
- # )
337
 
338
- # return_code = await process.wait()
339
- # if return_code == 0:
340
- # # await send_message('Code executed successfully')
341
- # pass
342
- # else:
343
- # # await send_message(f'error:Execution failed with return code {return_code}')
344
- # pass
345
 
346
- # except Exception as e:
347
- # await error(websocket, str(e))
348
- # except KeyboardInterrupt:
349
- # pass # Handle KeyboardInterrupt to gracefully stop the observer
350
 
351
- # observer.stop()
352
- # observer.join()
353
- process_input(event["command"]["command"], process)
 
354
 
355
  elif event["command"]["type"]=="write":
356
 
 
298
  print(f'Received user input: {event}')
299
  try:
300
  if event["command"]["type"]=="shell":
301
+ await asyncio.sleep(0.1)
302
+ if process.returncode is not None:
303
+ base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
304
+ directory_path = base_path
305
+ event_handler = FileHandler(websocket,connected)
306
+ observer = Observer()
307
+ observer.schedule(event_handler, path=directory_path, recursive=True)
308
+ observer.start()
309
 
310
+ try:
311
+ # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
312
+ # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
313
+ print(base_path)
314
+ mod_command = f'cd {base_path}&& {event["command"]["command"]}'
315
 
316
+ try:
317
+ process = await asyncio.create_subprocess_shell(
318
+ mod_command,
319
+ # cwd=base_path,
320
+ stdin=asyncio.subprocess.PIPE,
321
+ stdout=asyncio.subprocess.PIPE,
322
+ stderr=asyncio.subprocess.PIPE,
323
+ # text=True,
324
+ )
325
 
326
+ async def send_message(message):
327
+ print('sending msg')
328
+ # await websocket.send(f'data: {message}')
329
+ websockets.broadcast(connected,json.dumps(message) )
330
 
331
 
332
 
333
+ await asyncio.gather(
334
+ handle_user_input(websocket,key, process, connected),
335
+ read_process_output(process, websocket)
336
+ )
337
 
338
+ return_code = await process.wait()
339
+ if return_code == 0:
340
+ # await send_message('Code executed successfully')
341
+ pass
342
+ else:
343
+ # await send_message(f'error:Execution failed with return code {return_code}')
344
+ pass
345
 
346
+ except Exception as e:
347
+ await error(websocket, str(e))
348
+ except KeyboardInterrupt:
349
+ pass # Handle KeyboardInterrupt to gracefully stop the observer
350
 
351
+ observer.stop()
352
+ observer.join()
353
+ else:
354
+ process_input(event["command"]["command"], process)
355
 
356
  elif event["command"]["type"]=="write":
357