Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,12 @@ async def delete_item(websocket, project_name, path, connected):
|
|
45 |
shutil.rmtree(item_path) # Remove the directory and its contents
|
46 |
elif os.path.isfile(item_path):
|
47 |
os.remove(item_path) # Remove the file
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
websockets.broadcast(connected,'success')
|
50 |
else:
|
51 |
print('item not found')
|
@@ -59,13 +64,23 @@ async def create_file(websocket, project_name, path, connected):
|
|
59 |
# Create the file
|
60 |
with open(file_path, 'w'):
|
61 |
pass
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
async def create_folder(websocket, project_name, path, connected):
|
65 |
folder_path = os.path.join(os.getcwd(), 'projects', project_name, path)
|
66 |
# Create the folder
|
67 |
os.makedirs(folder_path)
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
async def wirte_file(websocket, project_name, path, content, connected):
|
71 |
try:
|
@@ -73,9 +88,19 @@ async def wirte_file(websocket, project_name, path, content, connected):
|
|
73 |
file_content = content
|
74 |
with open(file_path, 'w', encoding='utf-8') as file:
|
75 |
file.write(file_content)
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
77 |
except FileNotFoundError as e:
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|
81 |
async def execute_command(websocket, project_name, command, connected):
|
@@ -94,18 +119,25 @@ async def execute_command(websocket, project_name, command, connected):
|
|
94 |
async def send_message(message):
|
95 |
print('sending msg')
|
96 |
# await websocket.send(f'data: {message}')
|
97 |
-
websockets.broadcast(connected,
|
98 |
|
99 |
async for line in process.stdout:
|
100 |
print('sending line')
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
105 |
|
106 |
async for line in process.stderr:
|
107 |
print(f'error:{line.strip()}')
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
|
110 |
return_code = await process.wait()
|
111 |
if return_code == 0:
|
|
|
45 |
shutil.rmtree(item_path) # Remove the directory and its contents
|
46 |
elif os.path.isfile(item_path):
|
47 |
os.remove(item_path) # Remove the file
|
48 |
+
|
49 |
+
event = {
|
50 |
+
"type": "delete-success",
|
51 |
+
"data": item_path,
|
52 |
+
}
|
53 |
+
websockets.broadcast(connected,json.dumps(event))
|
54 |
websockets.broadcast(connected,'success')
|
55 |
else:
|
56 |
print('item not found')
|
|
|
64 |
# Create the file
|
65 |
with open(file_path, 'w'):
|
66 |
pass
|
67 |
+
event = {
|
68 |
+
"type": "file-created",
|
69 |
+
"data": file_path,
|
70 |
+
}
|
71 |
+
websockets.broadcast(connected,json.dumps(event))
|
72 |
+
|
73 |
|
74 |
async def create_folder(websocket, project_name, path, connected):
|
75 |
folder_path = os.path.join(os.getcwd(), 'projects', project_name, path)
|
76 |
# Create the folder
|
77 |
os.makedirs(folder_path)
|
78 |
+
event = {
|
79 |
+
"type": "folder-created",
|
80 |
+
"data": folder_path,
|
81 |
+
}
|
82 |
+
websockets.broadcast(connected,json.dumps(event))
|
83 |
+
|
84 |
|
85 |
async def wirte_file(websocket, project_name, path, content, connected):
|
86 |
try:
|
|
|
88 |
file_content = content
|
89 |
with open(file_path, 'w', encoding='utf-8') as file:
|
90 |
file.write(file_content)
|
91 |
+
|
92 |
+
event = {
|
93 |
+
"type": "write-success",
|
94 |
+
"data": file_path,
|
95 |
+
}
|
96 |
+
websockets.broadcast(connected,json.dumps(event))
|
97 |
except FileNotFoundError as e:
|
98 |
+
event = {
|
99 |
+
"type": "write-error",
|
100 |
+
"data": e,
|
101 |
+
}
|
102 |
+
websockets.broadcast(connected,json.dumps(event))
|
103 |
+
|
104 |
|
105 |
|
106 |
async def execute_command(websocket, project_name, command, connected):
|
|
|
119 |
async def send_message(message):
|
120 |
print('sending msg')
|
121 |
# await websocket.send(f'data: {message}')
|
122 |
+
websockets.broadcast(connected,json.dumps(message) )
|
123 |
|
124 |
async for line in process.stdout:
|
125 |
print('sending line')
|
126 |
+
|
127 |
+
event = {
|
128 |
+
"type": "terminal-data",
|
129 |
+
"data": line.strip(),
|
130 |
+
}
|
131 |
+
await send_message(event)
|
132 |
+
|
133 |
|
134 |
async for line in process.stderr:
|
135 |
print(f'error:{line.strip()}')
|
136 |
+
event = {
|
137 |
+
"type": "terminal-error",
|
138 |
+
"data": line.strip(),
|
139 |
+
}
|
140 |
+
await send_message(event)
|
141 |
|
142 |
return_code = await process.wait()
|
143 |
if return_code == 0:
|