Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,23 @@ import tempfile
|
|
| 4 |
|
| 5 |
# Use temporary directory or current working directory for app data
|
| 6 |
# This avoids permission issues in containerized environments
|
| 7 |
-
|
| 8 |
-
|
| 9 |
app_data_path = '/tmp/app_data'
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Fallback to current directory or temp directory
|
| 13 |
-
app_data_path = os.path.join(os.getcwd(), 'app_data')
|
| 14 |
try:
|
|
|
|
|
|
|
| 15 |
os.makedirs(app_data_path, exist_ok=True)
|
| 16 |
except PermissionError:
|
| 17 |
-
#
|
| 18 |
-
app_data_path =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Make sure the necessary directories exist and have proper permissions
|
| 21 |
try:
|
|
@@ -452,5 +457,5 @@ def get_attendance():
|
|
| 452 |
records = list(mongo.db.attendance1.find({}, {"_id": 0}))
|
| 453 |
return jsonify({"attendance": records})
|
| 454 |
|
| 455 |
-
if __name__ == '__main__':
|
| 456 |
-
|
|
|
|
| 4 |
|
| 5 |
# Use temporary directory or current working directory for app data
|
| 6 |
# This avoids permission issues in containerized environments
|
| 7 |
+
# Check if running in container with pre-created directories
|
| 8 |
+
if os.path.exists('/tmp/app_data') and os.access('/tmp/app_data', os.W_OK):
|
| 9 |
app_data_path = '/tmp/app_data'
|
| 10 |
+
print("Using pre-created /tmp/app_data directory")
|
| 11 |
+
else:
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
+
# Try to use /tmp first (usually writable in containers)
|
| 14 |
+
app_data_path = '/tmp/app_data'
|
| 15 |
os.makedirs(app_data_path, exist_ok=True)
|
| 16 |
except PermissionError:
|
| 17 |
+
# Fallback to current directory or temp directory
|
| 18 |
+
app_data_path = os.path.join(os.getcwd(), 'app_data')
|
| 19 |
+
try:
|
| 20 |
+
os.makedirs(app_data_path, exist_ok=True)
|
| 21 |
+
except PermissionError:
|
| 22 |
+
# Last resort: use system temp directory
|
| 23 |
+
app_data_path = tempfile.mkdtemp(prefix='app_data_')
|
| 24 |
|
| 25 |
# Make sure the necessary directories exist and have proper permissions
|
| 26 |
try:
|
|
|
|
| 457 |
records = list(mongo.db.attendance1.find({}, {"_id": 0}))
|
| 458 |
return jsonify({"attendance": records})
|
| 459 |
|
| 460 |
+
# if __name__ == '__main__':
|
| 461 |
+
# app.run(debug=True)
|