Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,25 @@ JOIN = {}
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
async def delete_item(websocket, project_name, path, connected):
|
| 20 |
try:
|
| 21 |
|
|
@@ -218,7 +237,7 @@ async def exe(websocket,connected):
|
|
| 218 |
await delete_item(websocket, event["project_name"], event["path"], connected)
|
| 219 |
elif event["command"]["type"]=="rename":
|
| 220 |
|
| 221 |
-
await
|
| 222 |
|
| 223 |
else:
|
| 224 |
# First player starts a new game.
|
|
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
| 19 |
+
async def rename_item(websocket, project_name, path,new_name connected):
|
| 20 |
+
|
| 21 |
+
old_path = os.path.join(os.getcwd(), 'projects', project_name, path)
|
| 22 |
+
new_name = new_name
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
if os.path.exists(old_path):
|
| 26 |
+
# Determine the new path
|
| 27 |
+
new_path = os.path.join(os.path.dirname(old_path), new_name)
|
| 28 |
+
|
| 29 |
+
# Rename the file or folder
|
| 30 |
+
os.rename(old_path, new_path)
|
| 31 |
+
|
| 32 |
+
websockets.broadcast(connected,'success')
|
| 33 |
+
else:
|
| 34 |
+
websockets.broadcast(connected,'Item not found')
|
| 35 |
+
except Exception as e:
|
| 36 |
+
websockets.broadcast(connected,str(e))
|
| 37 |
+
|
| 38 |
async def delete_item(websocket, project_name, path, connected):
|
| 39 |
try:
|
| 40 |
|
|
|
|
| 237 |
await delete_item(websocket, event["project_name"], event["path"], connected)
|
| 238 |
elif event["command"]["type"]=="rename":
|
| 239 |
|
| 240 |
+
await rename_item(websocket, event["project_name"], event["path"], event["name"], connected)
|
| 241 |
|
| 242 |
else:
|
| 243 |
# First player starts a new game.
|