-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
110 lines (91 loc) · 3.73 KB
/
build.py
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
import sys
import os
import warnings
import webassets
from flask_frozen import Freezer, MissingURLGeneratorWarning
sys.modules["uwsgi"] = {"mule_msg": lambda x: None, "mule_get_msg": lambda: None}
from content import app, assets, config
from resources_lib import documentation
completely_static_files = [
"/favicon.ico",
"/favicon.png",
"/logo/SkyWars.png",
"/robots.txt",
]
def build_assets():
for bundle in assets:
assert isinstance(bundle, webassets.Bundle)
print("Building bundle {}".format(bundle.output))
bundle.build(force=True, disable_cache=True)
# This is a copy of Freezer.no_argument_rules() modified to ignore certain paths
def no_argument_rules_urls_with_ignore():
"""URL generator for URL rules that take no arguments."""
ignored = app.config.get('FREEZER_IGNORE_ENDPOINTS', [])
for rule in app.url_map.iter_rules():
if rule.endpoint not in ignored and not rule.arguments and 'GET' in rule.methods:
yield rule.endpoint, {}
def markdown_url_generator():
return documentation.get_all_possible_pages_for_frozen_flask()
def build_pages():
ignored = [bundle.output for bundle in assets] + ["rust"]
app.config['FREEZER_DESTINATION'] = os.path.abspath("static")
app.config['FREEZER_BASE_URL'] = "https://dabo.guru/"
app.config['FREEZER_DESTINATION_IGNORE'] = ignored
app.config['FREEZER_IGNORE_ENDPOINTS'] = ['oauth_respond', 'mc_api_name', 'mc_api_uuid', 'serve_markdown',
'uuid_api']
freezer = Freezer(app=app, with_static_files=False, with_no_argument_rules=False, log_url_for=True)
freezer.register_generator(no_argument_rules_urls_with_ignore)
freezer.register_generator(markdown_url_generator)
freezer.register_generator(lambda: completely_static_files)
print("Updating documentation")
documentation.update_all_repositories(config)
print("Freezing")
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=MissingURLGeneratorWarning)
freezer.freeze()
def build_individual_repositories(repository_list):
app.config['FREEZER_DESTINATION'] = os.path.abspath("static")
app.config['FREEZER_BASE_URL'] = "https://dabo.guru/"
app.config['FREEZER_REMOVE_EXTRA_FILES'] = False
freezer = Freezer(app=app, with_static_files=False, with_no_argument_rules=False, log_url_for=True)
for repository in repository_list:
def url_generator():
return documentation.get_possible_pages_for_frozen_flask(repository)
freezer.register_generator(url_generator)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=MissingURLGeneratorWarning)
freezer.freeze()
def main():
args = sys.argv[1:]
if args:
is_assets = False
is_pages = False
repositories = []
next_is_repo = False
for arg in args:
if next_is_repo:
repositories.append(arg)
next_is_repo = False
elif arg == "--assets" or arg == "-a":
is_assets = True
elif arg == "--pages" or arg == "-p":
is_pages = True
elif arg == "--repo" or arg == "-r":
next_is_repo = True
else:
print("Unknown argument '{}'".format(arg))
print("Valid arguments: --assets -a --pages -p")
return
else:
is_assets = True
is_pages = True
repositories = []
if is_assets:
build_assets()
if is_pages:
build_pages()
elif repositories:
# All repositories will have already been built if pages is set.
build_individual_repositories(repositories)
if __name__ == "__main__":
main()