Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -300,7 +300,56 @@ async def handle_user_input(websocket, process):
|
|
300 |
if event["command"]["type"]=="shell":
|
301 |
await asyncio.sleep(0.1)
|
302 |
if process.returncode is not None:
|
303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
process_input(event["command"]["command"], process)
|
305 |
|
306 |
elif event["command"]["type"]=="write":
|
|
|
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, process),
|
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":
|