Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ JOIN = {}
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
| 19 |
-
async def generate_file_structure(path
|
| 20 |
file_structure = {'name': os.path.basename(path), 'type': 'folder', 'path': path, 'children': []}
|
| 21 |
|
| 22 |
try:
|
|
@@ -119,6 +119,8 @@ async def create_folder(websocket, key,project_name, path,name, connected):
|
|
| 119 |
event = {
|
| 120 |
"type": "folder-created",
|
| 121 |
"data": folder_path,
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
websockets.broadcast(connected,json.dumps(event))
|
| 124 |
|
|
@@ -133,6 +135,8 @@ async def wirte_file(websocket, key,project_name, path, content, connected):
|
|
| 133 |
event = {
|
| 134 |
"type": "write-success",
|
| 135 |
"data": file_path,
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
websockets.broadcast(connected,json.dumps(event))
|
| 138 |
except FileNotFoundError as e:
|
|
@@ -400,9 +404,23 @@ async def join(websocket, key):
|
|
| 400 |
# Register to receive moves from this game.
|
| 401 |
connected.add(websocket)
|
| 402 |
try:
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
# Send the first move, in case the first player already played it.
|
| 405 |
-
file_structure = await generate_file_structure(
|
| 406 |
# Receive and process moves from the second player.
|
| 407 |
event = {
|
| 408 |
"type": "join",
|
|
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
| 19 |
+
async def generate_file_structure(path, encoding='utf-8'):
|
| 20 |
file_structure = {'name': os.path.basename(path), 'type': 'folder', 'path': path, 'children': []}
|
| 21 |
|
| 22 |
try:
|
|
|
|
| 119 |
event = {
|
| 120 |
"type": "folder-created",
|
| 121 |
"data": folder_path,
|
| 122 |
+
"path": path,
|
| 123 |
+
"name": name,
|
| 124 |
}
|
| 125 |
websockets.broadcast(connected,json.dumps(event))
|
| 126 |
|
|
|
|
| 135 |
event = {
|
| 136 |
"type": "write-success",
|
| 137 |
"data": file_path,
|
| 138 |
+
"path": path,
|
| 139 |
+
"content": content,
|
| 140 |
}
|
| 141 |
websockets.broadcast(connected,json.dumps(event))
|
| 142 |
except FileNotFoundError as e:
|
|
|
|
| 404 |
# Register to receive moves from this game.
|
| 405 |
connected.add(websocket)
|
| 406 |
try:
|
| 407 |
+
process = await asyncio.create_subprocess_shell(
|
| 408 |
+
'ls',
|
| 409 |
+
# cwd=base_path,
|
| 410 |
+
stdin=asyncio.subprocess.PIPE,
|
| 411 |
+
stdout=asyncio.subprocess.PIPE,
|
| 412 |
+
stderr=asyncio.subprocess.PIPE,
|
| 413 |
+
# text=True,
|
| 414 |
+
)
|
| 415 |
+
project_name = []
|
| 416 |
+
async for line in process.stdout:
|
| 417 |
+
project_name.append(line)
|
| 418 |
+
|
| 419 |
+
return_code = await process.wait()
|
| 420 |
+
base_path = os.path.join(os.getcwd(), 'projects', key,project_name[0])
|
| 421 |
+
# current_directory = f'projects/{key}/{project_name[0]}'
|
| 422 |
# Send the first move, in case the first player already played it.
|
| 423 |
+
file_structure = await generate_file_structure(base_path)
|
| 424 |
# Receive and process moves from the second player.
|
| 425 |
event = {
|
| 426 |
"type": "join",
|