Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,15 +13,21 @@ 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:
|
@@ -354,7 +360,7 @@ async def exe(websocket,connected,key):
|
|
354 |
if event["command"]["type"]=="shell":
|
355 |
base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
|
356 |
directory_path = base_path
|
357 |
-
event_handler = FileHandler()
|
358 |
observer = Observer()
|
359 |
observer.schedule(event_handler, path=directory_path, recursive=True)
|
360 |
observer.start()
|
|
|
13 |
from watchdog.events import FileSystemEventHandler
|
14 |
|
15 |
class FileHandler(FileSystemEventHandler):
|
16 |
+
def __init__(self, websocket,connected):
|
17 |
+
super().__init__()
|
18 |
+
self.websocket = websocket
|
19 |
+
self.connected = connected
|
20 |
def on_modified(self, event):
|
21 |
if event.is_directory:
|
22 |
return
|
23 |
print(f'File {event.src_path} has been modified.')
|
24 |
+
self.websockets.broadcast(self.connected,f'File {event.src_path} has been modified.')
|
25 |
|
26 |
def on_created(self, event):
|
27 |
if event.is_directory:
|
28 |
return
|
29 |
print(f'File {event.src_path} has been created.')
|
30 |
+
self.websockets.broadcast(self.connected,f'File {event.src_path} has been created.')
|
31 |
|
32 |
def on_deleted(self, event):
|
33 |
if event.is_directory:
|
|
|
360 |
if event["command"]["type"]=="shell":
|
361 |
base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
|
362 |
directory_path = base_path
|
363 |
+
event_handler = FileHandler(websocket,connected)
|
364 |
observer = Observer()
|
365 |
observer.schedule(event_handler, path=directory_path, recursive=True)
|
366 |
observer.start()
|