-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.py
executable file
·122 lines (105 loc) · 3.54 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
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Free Software Foundation Europe e.V. <https://fsfe.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import argparse
import logging
import multiprocessing
import os
from pathlib import Path
from build.phase0.full import full
from build.phase1.run import phase1_run
from build.phase2.run import phase2_run
from build.phase3.serve_websites import serve_websites
from build.phase3.stage_to_target import stage_to_target
logger = logging.getLogger(__name__)
def parse_arguments() -> argparse.Namespace:
"""
Parse the arguments of the website build process
"""
parser = argparse.ArgumentParser(
description="Python script to handle building of the fsfe webpage"
)
parser.add_argument(
"--target",
dest="target",
help="Final dirs for websites to be build to. Can be a single path, or a comma separated list of valid rsync targets. Supports custom rsynx extension for specifying ports for ssh targets, name@host:path?port.",
type=str,
default="./output/final",
)
parser.add_argument(
"--log-level",
dest="log_level",
type=str,
default="INFO",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
help="Set the logging level (default: INFO)",
)
parser.add_argument(
"--full",
dest="full",
help="Force a full rebuild of all webpages.",
action="store_true",
)
parser.add_argument(
"--processes",
dest="processes",
help="Number of processes to use when building the website",
type=int,
default=multiprocessing.cpu_count(),
)
parser.add_argument(
"--languages",
dest="languages",
help="Languages to build website in.",
default=list(
map(lambda path: path.name, Path(".").glob("global/languages/??"))
),
type=lambda input: input.split(","),
)
parser.add_argument(
"--stage",
dest="stage",
help="Force the use of an internal staging directory.",
action="store_true",
)
parser.add_argument(
"--serve",
dest="serve",
help="Serve the webpages after rebuild",
action="store_true",
)
args = parser.parse_args()
return args
def main(args: argparse.Namespace):
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=args.log_level,
)
logger.debug(args)
with multiprocessing.Pool(args.processes) as pool:
logger.info("Starting phase 0 - Conditional Setup")
# TODO Should also be triggered whenever any build python file is changed
if args.full:
full()
stage_required = any(
[args.stage, "@" in args.target, ":" in args.target, "," in args.target]
)
working_target = Path("./output/stage" if stage_required else args.target)
# Processes needed only for subdir stuff
phase1_run(args.languages, args.processes, pool)
phase2_run(args.languages, pool, working_target)
logger.info("Starting Phase 3 - Conditional Finishing")
if stage_required:
stage_to_target(working_target, args.target, pool)
if args.serve:
serve_websites(working_target, 2000, 100)
if __name__ == "__main__":
"""
Main process of the website builder
"""
# Change to the dir the script is in.
os.chdir(os.path.dirname(__file__))
args = parse_arguments()
main(args)