Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import json
|
|
| 5 |
import os
|
| 6 |
import secrets
|
| 7 |
import signal
|
| 8 |
-
|
| 9 |
import websockets
|
| 10 |
|
| 11 |
from connect4 import PLAYER1, PLAYER2, Connect4
|
|
@@ -16,6 +16,23 @@ JOIN = {}
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
async def create_file_structure(websocket, data, base_path='.'):
|
| 20 |
if data['type'] == 'folder':
|
| 21 |
folder_path = os.path.join(base_path, data['name'])
|
|
|
|
| 5 |
import os
|
| 6 |
import secrets
|
| 7 |
import signal
|
| 8 |
+
import subprocess
|
| 9 |
import websockets
|
| 10 |
|
| 11 |
from connect4 import PLAYER1, PLAYER2, Connect4
|
|
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
| 19 |
+
async def execute_command(websocket, project_name, command):
|
| 20 |
+
base_path = os.path.join(os.getcwd(), 'projects', project_name)
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
process = subprocess.Popen(
|
| 24 |
+
command,
|
| 25 |
+
cwd=base_path,
|
| 26 |
+
stdout=subprocess.PIPE,
|
| 27 |
+
stderr=subprocess.PIPE,
|
| 28 |
+
shell=True
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Send the command output to the client
|
| 32 |
+
output, error = process.communicate()
|
| 33 |
+
response = f"Command executed:\n\nOutput:\n{output.decode('utf-8')}\nError:\n{error.decode('utf-8')}"
|
| 34 |
+
websockets.broadcast(connected, response)
|
| 35 |
+
|
| 36 |
async def create_file_structure(websocket, data, base_path='.'):
|
| 37 |
if data['type'] == 'folder':
|
| 38 |
folder_path = os.path.join(base_path, data['name'])
|