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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -43
app.py CHANGED
@@ -282,7 +282,7 @@ async def read_process_output(process, websocket):
282
  async def handle_user_input(websocket,key, process, connected):
283
  while True:
284
  try:
285
- # await asyncio.sleep(0.1)
286
  if process.returncode is not None:
287
  break
288
  # message = await websocket.recv()
@@ -299,57 +299,57 @@ async def handle_user_input(websocket,key, process, connected):
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":
 
282
  async def handle_user_input(websocket,key, process, connected):
283
  while True:
284
  try:
285
+ await asyncio.sleep(0.1)
286
  if process.returncode is not None:
287
  break
288
  # message = await websocket.recv()
 
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":