MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / main

Function main

scripts/freeze_viewer.py:107–197  ·  view source on GitHub ↗

Main function to generate static site

()

Source from the content-addressed store, hash-verified

105
106
107def main():
108 """Main function to generate static site"""
109 parser = argparse.ArgumentParser(description="Generate static version of CodeClash Trajectory Viewer")
110 parser.add_argument("--logs-dir", type=str, default="logs", help="Directory containing game logs (default: logs)")
111 parser.add_argument(
112 "--output-dir", type=str, default="build", help="Output directory for static files (default: build)"
113 )
114 parser.add_argument("--clean", action="store_true", help="Clean output directory before building")
115
116 args = parser.parse_args()
117
118 # Set up paths
119 logs_dir = Path(args.logs_dir).resolve()
120 output_dir = Path(args.output_dir).resolve()
121
122 assert logs_dir.exists()
123
124 # Set the logs directory for the app
125 set_log_base_directory(logs_dir)
126
127 # Clean output directory if requested
128 if args.clean and output_dir.exists():
129 print(f"Cleaning output directory: {output_dir}")
130 shutil.rmtree(output_dir)
131
132 # Create output directory
133 output_dir.mkdir(parents=True, exist_ok=True)
134
135 print(f"Generating static site from logs in: {logs_dir}")
136 print(f"Output directory: {output_dir}")
137
138 # Set up freezer
139 freezer = setup_freezer(str(output_dir))
140
141 # Generate static site
142 print("Freezing Flask application...")
143
144 # Try to freeze - it will likely fail on API endpoints, but we'll continue
145 try:
146 urls = freezer.freeze()
147 print(f"Successfully froze {len(urls)} URL(s)")
148 except Exception as e:
149 print(f"Initial freeze had errors (expected): {type(e).__name__}")
150
151 # Now manually generate the game view pages
152 print("Generating game view pages...")
153 from codeclash.viewer.app import LOG_BASE_DIR, game_view
154
155 game_folders = find_all_game_folders(LOG_BASE_DIR)
156 print(f"Found {len(game_folders)} game folder(s) to process")
157
158 for i, game_folder in enumerate(game_folders, 1):
159 folder_path = game_folder["name"]
160 print(f" [{i}/{len(game_folders)}] Generating page for: {folder_path}")
161
162 # Create the output directory structure if needed (for nested paths)
163 game_dir = output_dir / "game"
164 game_dir.mkdir(parents=True, exist_ok=True)

Callers 1

freeze_viewer.pyFile · 0.70

Calls 6

set_log_base_directoryFunction · 0.90
find_all_game_foldersFunction · 0.90
game_viewFunction · 0.90
setup_freezerFunction · 0.85
_cleanup_api_filesFunction · 0.85
_add_html_extensionsFunction · 0.85

Tested by

no test coverage detected