Spaces:
Running
Running
Remove all emojis from code - keep professional clean text
Browse files- Remove emojis from all logging messages
- Clean up git commit message template
- Maintain professional appearance in logs and version control
- No functional changes, only text cleanup
app.py
CHANGED
@@ -24,6 +24,7 @@ from fastapi.staticfiles import StaticFiles
|
|
24 |
from pydantic import BaseModel, Field, field_validator, model_validator
|
25 |
import uuid
|
26 |
import aiofiles
|
|
|
27 |
|
28 |
from config import get_settings
|
29 |
from master_tree_database import create_master_tree_database, get_tree_suggestions, get_all_tree_codes
|
@@ -38,7 +39,7 @@ logging.basicConfig(
|
|
38 |
logger = logging.getLogger(__name__)
|
39 |
|
40 |
# Log build info to help with cache debugging
|
41 |
-
|
42 |
build_time = os.environ.get('BUILD_TIME', 'unknown')
|
43 |
logger.info(f"TreeTrack starting - Build time: {build_time}")
|
44 |
|
@@ -430,9 +431,9 @@ def initialize_app():
|
|
430 |
# Try to ensure persistent directory exists (may fail on some systems)
|
431 |
try:
|
432 |
persistent_db_path.parent.mkdir(parents=True, exist_ok=True)
|
433 |
-
logger.info("
|
434 |
except (PermissionError, OSError) as e:
|
435 |
-
logger.warning(f"
|
436 |
# Fallback to local backup strategy only
|
437 |
persistent_db_path = None
|
438 |
|
@@ -444,7 +445,7 @@ def initialize_app():
|
|
444 |
cursor = conn.cursor()
|
445 |
cursor.execute("SELECT COUNT(*) FROM trees")
|
446 |
tree_count = cursor.fetchone()[0]
|
447 |
-
logger.info(f"
|
448 |
else:
|
449 |
# Check for backup files in multiple locations
|
450 |
backup_locations = [
|
@@ -471,7 +472,7 @@ def initialize_app():
|
|
471 |
cursor = conn.cursor()
|
472 |
cursor.execute("SELECT COUNT(*) FROM trees")
|
473 |
tree_count = cursor.fetchone()[0]
|
474 |
-
logger.info(f"
|
475 |
|
476 |
# Initialize database (creates tables if they don't exist)
|
477 |
init_db()
|
@@ -480,7 +481,7 @@ def initialize_app():
|
|
480 |
if persistent_db_path:
|
481 |
_backup_to_persistent_storage()
|
482 |
else:
|
483 |
-
logger.info("
|
484 |
|
485 |
# Log current status
|
486 |
if local_db_path.exists():
|
@@ -488,7 +489,7 @@ def initialize_app():
|
|
488 |
cursor = conn.cursor()
|
489 |
cursor.execute("SELECT COUNT(*) FROM trees")
|
490 |
tree_count = cursor.fetchone()[0]
|
491 |
-
logger.info(f"
|
492 |
|
493 |
except Exception as e:
|
494 |
logger.error(f"Application initialization failed: {e}")
|
@@ -509,10 +510,10 @@ def _backup_to_persistent_storage():
|
|
509 |
try:
|
510 |
persistent_db.parent.mkdir(parents=True, exist_ok=True)
|
511 |
shutil.copy2(source_db, persistent_db)
|
512 |
-
logger.info(f"
|
513 |
return True
|
514 |
except (PermissionError, OSError) as e:
|
515 |
-
logger.warning(f"
|
516 |
return False
|
517 |
except Exception as e:
|
518 |
logger.error(f"Persistent storage backup failed: {e}")
|
@@ -553,11 +554,11 @@ def backup_database():
|
|
553 |
if _is_docker_environment():
|
554 |
git_success = _git_commit_backup([root_db, root_csv, root_status], tree_count)
|
555 |
if git_success:
|
556 |
-
logger.info(f"
|
557 |
else:
|
558 |
-
logger.info(f"
|
559 |
else:
|
560 |
-
logger.info(f"
|
561 |
|
562 |
return True
|
563 |
|
@@ -672,13 +673,13 @@ def _git_commit_backup(files: list, tree_count: int) -> bool:
|
|
672 |
|
673 |
# Create commit message with tree count and timestamp
|
674 |
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M UTC')
|
675 |
-
commit_message = f"
|
676 |
|
677 |
# Commit changes
|
678 |
subprocess.run(['git', 'commit', '-m', commit_message],
|
679 |
check=True, capture_output=True, text=True)
|
680 |
|
681 |
-
logger.info(f"
|
682 |
|
683 |
# Note: HF Spaces automatically syncs commits to the repository
|
684 |
# No need to explicitly push
|
|
|
24 |
from pydantic import BaseModel, Field, field_validator, model_validator
|
25 |
import uuid
|
26 |
import aiofiles
|
27 |
+
import os
|
28 |
|
29 |
from config import get_settings
|
30 |
from master_tree_database import create_master_tree_database, get_tree_suggestions, get_all_tree_codes
|
|
|
39 |
logger = logging.getLogger(__name__)
|
40 |
|
41 |
# Log build info to help with cache debugging
|
42 |
+
|
43 |
build_time = os.environ.get('BUILD_TIME', 'unknown')
|
44 |
logger.info(f"TreeTrack starting - Build time: {build_time}")
|
45 |
|
|
|
431 |
# Try to ensure persistent directory exists (may fail on some systems)
|
432 |
try:
|
433 |
persistent_db_path.parent.mkdir(parents=True, exist_ok=True)
|
434 |
+
logger.info("Persistent storage directory available at /data")
|
435 |
except (PermissionError, OSError) as e:
|
436 |
+
logger.warning(f"Cannot create /data directory: {e}. Using local backup strategy.")
|
437 |
# Fallback to local backup strategy only
|
438 |
persistent_db_path = None
|
439 |
|
|
|
445 |
cursor = conn.cursor()
|
446 |
cursor.execute("SELECT COUNT(*) FROM trees")
|
447 |
tree_count = cursor.fetchone()[0]
|
448 |
+
logger.info(f"Database restored from persistent storage: {tree_count} trees")
|
449 |
else:
|
450 |
# Check for backup files in multiple locations
|
451 |
backup_locations = [
|
|
|
472 |
cursor = conn.cursor()
|
473 |
cursor.execute("SELECT COUNT(*) FROM trees")
|
474 |
tree_count = cursor.fetchone()[0]
|
475 |
+
logger.info(f"Database restored from backup: {tree_count} trees")
|
476 |
|
477 |
# Initialize database (creates tables if they don't exist)
|
478 |
init_db()
|
|
|
481 |
if persistent_db_path:
|
482 |
_backup_to_persistent_storage()
|
483 |
else:
|
484 |
+
logger.info("Using local backup strategy only (no persistent storage)")
|
485 |
|
486 |
# Log current status
|
487 |
if local_db_path.exists():
|
|
|
489 |
cursor = conn.cursor()
|
490 |
cursor.execute("SELECT COUNT(*) FROM trees")
|
491 |
tree_count = cursor.fetchone()[0]
|
492 |
+
logger.info(f"TreeTrack initialized with {tree_count} trees")
|
493 |
|
494 |
except Exception as e:
|
495 |
logger.error(f"Application initialization failed: {e}")
|
|
|
510 |
try:
|
511 |
persistent_db.parent.mkdir(parents=True, exist_ok=True)
|
512 |
shutil.copy2(source_db, persistent_db)
|
513 |
+
logger.info(f"Database backed up to persistent storage: {persistent_db}")
|
514 |
return True
|
515 |
except (PermissionError, OSError) as e:
|
516 |
+
logger.warning(f"Cannot backup to persistent storage: {e}")
|
517 |
return False
|
518 |
except Exception as e:
|
519 |
logger.error(f"Persistent storage backup failed: {e}")
|
|
|
554 |
if _is_docker_environment():
|
555 |
git_success = _git_commit_backup([root_db, root_csv, root_status], tree_count)
|
556 |
if git_success:
|
557 |
+
logger.info(f"Database backed up to all locations including persistent storage: {tree_count} trees")
|
558 |
else:
|
559 |
+
logger.info(f"Database backed up to static files and persistent storage: {tree_count} trees")
|
560 |
else:
|
561 |
+
logger.info(f"Database backed up locally: {tree_count} trees")
|
562 |
|
563 |
return True
|
564 |
|
|
|
673 |
|
674 |
# Create commit message with tree count and timestamp
|
675 |
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M UTC')
|
676 |
+
commit_message = f"TreeTrack Auto-backup: {tree_count:,} trees - {timestamp}"
|
677 |
|
678 |
# Commit changes
|
679 |
subprocess.run(['git', 'commit', '-m', commit_message],
|
680 |
check=True, capture_output=True, text=True)
|
681 |
|
682 |
+
logger.info(f"Database backup committed to git: {tree_count} trees")
|
683 |
|
684 |
# Note: HF Spaces automatically syncs commits to the repository
|
685 |
# No need to explicitly push
|