Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,39 +26,7 @@ def install_dependencies():
|
|
| 26 |
print(f"Failed to install dependencies: {e}")
|
| 27 |
sys.exit(1)
|
| 28 |
|
| 29 |
-
def ensure_docker_daemon():
|
| 30 |
-
logger = logging.getLogger(__name__)
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
subprocess.check_output(['docker', 'info'], stderr=subprocess.STDOUT, timeout=10)
|
| 34 |
-
logger.info("Docker daemon is already running")
|
| 35 |
-
return True
|
| 36 |
-
except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError):
|
| 37 |
-
logger.info("Docker daemon not responding, attempting to start...")
|
| 38 |
-
|
| 39 |
-
try:
|
| 40 |
-
logger.info("Starting Docker daemon...")
|
| 41 |
-
result = subprocess.run(['service', 'docker', 'start'],
|
| 42 |
-
capture_output=True, text=True, timeout=30)
|
| 43 |
-
|
| 44 |
-
if result.returncode == 0:
|
| 45 |
-
logger.info("Docker daemon started successfully")
|
| 46 |
-
import time
|
| 47 |
-
time.sleep(3)
|
| 48 |
-
|
| 49 |
-
subprocess.check_output(['docker', 'info'], stderr=subprocess.STDOUT, timeout=10)
|
| 50 |
-
logger.info("Docker daemon verified as running")
|
| 51 |
-
return True
|
| 52 |
-
else:
|
| 53 |
-
logger.error(f"Failed to start Docker daemon: {result.stderr}")
|
| 54 |
-
return False
|
| 55 |
-
|
| 56 |
-
except Exception as e:
|
| 57 |
-
logger.error(f"Error starting Docker daemon: {e}")
|
| 58 |
-
return False
|
| 59 |
-
|
| 60 |
install_dependencies()
|
| 61 |
-
ensure_docker_daemon()
|
| 62 |
|
| 63 |
from fastapi import FastAPI, Request, HTTPException
|
| 64 |
from fastapi.responses import PlainTextResponse, StreamingResponse, HTMLResponse
|
|
@@ -275,9 +243,11 @@ async def execute_get(command: str, files=None):
|
|
| 275 |
os.makedirs(workspace_dir)
|
| 276 |
|
| 277 |
if files:
|
|
|
|
| 278 |
for file in files:
|
| 279 |
content = await file.read()
|
| 280 |
file_path = os.path.join(workspace_dir, file.filename)
|
|
|
|
| 281 |
with open(file_path, 'wb') as f:
|
| 282 |
f.write(content)
|
| 283 |
|
|
|
|
| 26 |
print(f"Failed to install dependencies: {e}")
|
| 27 |
sys.exit(1)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
install_dependencies()
|
|
|
|
| 30 |
|
| 31 |
from fastapi import FastAPI, Request, HTTPException
|
| 32 |
from fastapi.responses import PlainTextResponse, StreamingResponse, HTMLResponse
|
|
|
|
| 243 |
os.makedirs(workspace_dir)
|
| 244 |
|
| 245 |
if files:
|
| 246 |
+
logger.info(f"Processing {len(files)} files")
|
| 247 |
for file in files:
|
| 248 |
content = await file.read()
|
| 249 |
file_path = os.path.join(workspace_dir, file.filename)
|
| 250 |
+
logger.info(f"Writing file {file.filename} ({len(content)} bytes) to {file_path}")
|
| 251 |
with open(file_path, 'wb') as f:
|
| 252 |
f.write(content)
|
| 253 |
|