Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,24 @@ import shutil
|
|
9 |
from connect4 import PLAYER1, PLAYER2, Connect4
|
10 |
from user import User
|
11 |
import requests
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
JOIN = {}
|
15 |
|
@@ -330,7 +347,21 @@ async def exe(websocket,connected,key):
|
|
330 |
|
331 |
try:
|
332 |
if event["command"]["type"]=="shell":
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
elif event["command"]["type"]=="write":
|
335 |
|
336 |
await wirte_file(websocket, key,event["project_name"], event["path"], event["content"], connected)
|
|
|
9 |
from connect4 import PLAYER1, PLAYER2, Connect4
|
10 |
from user import User
|
11 |
import requests
|
12 |
+
from watchdog.observers import Observer
|
13 |
+
from watchdog.events import FileSystemEventHandler
|
14 |
|
15 |
+
class FileHandler(FileSystemEventHandler):
|
16 |
+
def on_modified(self, event):
|
17 |
+
if event.is_directory:
|
18 |
+
return
|
19 |
+
print(f'File {event.src_path} has been modified.')
|
20 |
+
|
21 |
+
def on_created(self, event):
|
22 |
+
if event.is_directory:
|
23 |
+
return
|
24 |
+
print(f'File {event.src_path} has been created.')
|
25 |
+
|
26 |
+
def on_deleted(self, event):
|
27 |
+
if event.is_directory:
|
28 |
+
return
|
29 |
+
print(f'File {event.src_path} has been deleted.')
|
30 |
|
31 |
JOIN = {}
|
32 |
|
|
|
347 |
|
348 |
try:
|
349 |
if event["command"]["type"]=="shell":
|
350 |
+
base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
|
351 |
+
directory_path = base_path
|
352 |
+
event_handler = FileHandler()
|
353 |
+
observer = Observer()
|
354 |
+
observer.schedule(event_handler, path=directory_path, recursive=True)
|
355 |
+
observer.start()
|
356 |
+
|
357 |
+
try:
|
358 |
+
await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
|
359 |
+
except KeyboardInterrupt:
|
360 |
+
pass # Handle KeyboardInterrupt to gracefully stop the observer
|
361 |
+
|
362 |
+
observer.stop()
|
363 |
+
observer.join()
|
364 |
+
|
365 |
elif event["command"]["type"]=="write":
|
366 |
|
367 |
await wirte_file(websocket, key,event["project_name"], event["path"], event["content"], connected)
|