-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.py
More file actions
216 lines (178 loc) · 6.22 KB
/
start.py
File metadata and controls
216 lines (178 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env python3
"""
Awesome Issue Resolution - Project Startup Script
Default (no flags): initialises DB if needed, refreshes news, re-renders
Markdown from DB, builds the static site, then launches the admin server.
Usage:
python start.py # Full update + start admin server (port 5000)
python start.py --port 8080 # Same, on a custom port
python start.py --init # Force re-import from YAML/CSV, then full update + start
python start.py --build # Build static site only and exit
python start.py --news # Refresh news section only and exit
python start.py --render # Re-render README/docs from DB only and exit
python start.py --no-update # Skip update steps, just start the server
"""
import sys
import os
import argparse
import subprocess
from pathlib import Path
# Ensure project root is on the path
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT))
if sys.platform == 'win32':
os.system('chcp 65001 >nul 2>&1')
def check_dependencies():
"""Check that required packages are installed."""
missing = []
packages = {
'flask': 'flask',
'flask_cors': 'flask-cors',
'sqlalchemy': 'sqlalchemy',
'yaml': 'pyyaml',
'requests': 'requests',
}
for module, pip_name in packages.items():
try:
__import__(module)
except ImportError:
missing.append(pip_name)
if missing:
print('[ERROR] Missing dependencies:')
for p in missing:
print(f' pip install {p}')
print('\nInstall all at once:')
print(' pip install ' + ' '.join(missing))
sys.exit(1)
def init_database(force: bool = False):
"""Initialize the SQLite database from YAML/CSV files."""
db_path = ROOT / 'database' / 'survey.db'
if db_path.exists() and not force:
print('[OK] Database already exists:', db_path.name)
return
print('[INFO] Initializing database from data files...')
result = subprocess.run(
[sys.executable, 'database/migrate.py'],
cwd=str(ROOT)
)
if result.returncode != 0:
print('[ERROR] Database initialization failed.')
sys.exit(1)
print('[OK] Database initialized.')
def update_news():
"""Refresh the Recent Papers section in docs/news.md and README.md."""
print('[INFO] Refreshing Recent Papers news section...')
result = subprocess.run(
[sys.executable, 'scripts/update_news.py'],
cwd=str(ROOT)
)
if result.returncode == 0:
print('[OK] News section updated.')
else:
print('[WARN] News update encountered an error (non-fatal).')
return result.returncode
def render_markdown():
"""Re-render README.md and docs/ tables from the database."""
print('[INFO] Rendering Markdown from database...')
result = subprocess.run(
[sys.executable, 'view/render_from_db.py'],
cwd=str(ROOT)
)
if result.returncode == 0:
print('[OK] Markdown rendered.')
else:
print('[WARN] Markdown render encountered an error (non-fatal).')
return result.returncode
def export_admin_json():
"""Export database to docs/admin/data.json for the static admin page."""
print('[INFO] Exporting admin JSON...')
result = subprocess.run(
[sys.executable, 'scripts/export_admin_json.py'],
cwd=str(ROOT)
)
if result.returncode == 0:
print('[OK] Admin JSON exported.')
else:
print('[WARN] Admin JSON export encountered an error (non-fatal).')
return result.returncode
def build_site():
"""Run mkdocs build."""
print('[INFO] Building static site with MkDocs...')
result = subprocess.run(['mkdocs', 'build'], cwd=str(ROOT))
if result.returncode == 0:
print('[OK] Static site built to site/')
else:
print('[WARN] MkDocs build failed. Make sure mkdocs is installed:')
print(' pip install mkdocs mkdocs-material')
return result.returncode
def run_full_update():
"""Run the full update pipeline: news -> render -> export JSON -> build."""
update_news()
render_markdown()
export_admin_json()
build_site()
def start_server(port: int = 5000):
"""Start the Flask admin server."""
import config
config.PORT = port
print()
print('=' * 60)
print(' Awesome Issue Resolution - Admin Server')
print('=' * 60)
print(f' [SERVER] http://localhost:{port}/')
print(f' [ADMIN] http://localhost:{port}/admin')
print(f' [API] http://localhost:{port}/api/stats')
print('=' * 60)
print()
from app import app
app.run(debug=config.DEBUG, host=config.HOST, port=port)
def main():
parser = argparse.ArgumentParser(
description='Awesome Issue Resolution - Project Manager'
)
parser.add_argument(
'--init', action='store_true',
help='Force re-import data from YAML/CSV into the database'
)
parser.add_argument(
'--build', action='store_true',
help='Build the static site (mkdocs build) and exit'
)
parser.add_argument(
'--news', action='store_true',
help='Refresh the Recent Papers section only and exit'
)
parser.add_argument(
'--render', action='store_true',
help='Re-render README/docs from DB only and exit'
)
parser.add_argument(
'--no-update', dest='no_update', action='store_true',
help='Skip all update steps and start the server immediately'
)
parser.add_argument(
'--port', type=int, default=5000,
help='Port for the admin server (default: 5000)'
)
args = parser.parse_args()
# Always check dependencies first
check_dependencies()
# --- Single-action flags (run task and exit) ---
if args.build:
sys.exit(build_site())
if args.news:
sys.exit(update_news())
if args.render:
sys.exit(render_markdown())
# --- Server startup ---
# Initialize (or re-import) the database
init_database(force=args.init)
if not args.no_update:
# Full update pipeline before serving
print()
print('[INFO] Running pre-start update pipeline...')
run_full_update()
print()
start_server(port=args.port)
if __name__ == '__main__':
main()