function check_static_files
Scans a 'static' directory for CSS and JavaScript files and prints their modification times relative to the current time.
/tf/active/vicechatdev/vice_ai/dev_tools.py
22 - 36
simple
Purpose
This diagnostic function helps developers monitor static file changes during development or debugging. It checks for the existence of a 'static' directory relative to the current file's location, then recursively searches for .css and .js files, displaying how recently each file was modified. This is useful for cache busting verification, deployment checks, or understanding when static assets were last updated.
Source Code
def check_static_files():
"""Check static file modification times"""
static_dir = Path(__file__).parent / "static"
if not static_dir.exists():
print("❌ Static directory not found")
return
print("📁 Static Files Status:")
for file_path in static_dir.rglob("*"):
if file_path.is_file() and file_path.suffix in ['.css', '.js']:
mtime = file_path.stat().st_mtime
relative_path = file_path.relative_to(static_dir)
age = time.time() - mtime
print(f" 📄 {relative_path}: Modified {age:.1f}s ago")
print()
Return Value
This function returns None (implicitly). It produces side effects by printing status information to stdout, including error messages if the static directory doesn't exist, or a formatted list of static files with their modification times.
Required Imports
import time
from pathlib import Path
Usage Example
import time
from pathlib import Path
def check_static_files():
"""Check static file modification times"""
static_dir = Path(__file__).parent / "static"
if not static_dir.exists():
print("❌ Static directory not found")
return
print("📁 Static Files Status:")
for file_path in static_dir.rglob("*"):
if file_path.is_file() and file_path.suffix in ['.css', '.js']:
mtime = file_path.stat().st_mtime
relative_path = file_path.relative_to(static_dir)
age = time.time() - mtime
print(f" 📄 {relative_path}: Modified {age:.1f}s ago")
print()
# Call the function to check static files
check_static_files()
Best Practices
- This function assumes it's called from a file that has a sibling 'static' directory - ensure proper file structure
- The function only checks .css and .js files; modify the suffix list if other file types are needed
- Uses Path(__file__).parent which requires the function to be defined in a file (won't work in interactive Python shells)
- Consider adding error handling for permission issues when accessing files
- The function prints directly to stdout; consider returning data instead for better testability and flexibility
- Modification times are shown in seconds; consider formatting for better readability (e.g., minutes, hours, days for older files)
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function touch_static_files 73.8% similar
-
function file_cleanup 62.9% similar
-
function get_file_version 58.1% similar
-
function get_file_version_v1 57.2% similar
-
function debug_cache_info 52.4% similar