2016-06-09 12:59:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Author: Jonpas
|
2021-10-21 16:27:25 +00:00
|
|
|
# Extracts dependencies to "docs/_includes/dependencies_list.md" for use with Jekyll include statement.
|
2016-09-08 19:19:07 +00:00
|
|
|
# Use the following line to add dependencies to an ACE3 feature page: {% include dependencies_list.md component="<component>" %}
|
|
|
|
|
2016-06-09 12:59:26 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
def get_dependencies(line):
|
|
|
|
dependencies = re.findall(r'"(.*?)"', line)
|
|
|
|
return dependencies
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2016-08-19 14:12:09 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
|
|
|
print("""
|
2016-09-08 19:19:07 +00:00
|
|
|
#############################################
|
2021-10-21 16:27:25 +00:00
|
|
|
# Extract ACE3 Module Dependencies #
|
2016-09-08 19:19:07 +00:00
|
|
|
# (for Jekyll include) #
|
|
|
|
#############################################
|
2016-08-19 14:12:09 +00:00
|
|
|
""")
|
2016-06-09 12:59:26 +00:00
|
|
|
|
2016-09-08 19:19:07 +00:00
|
|
|
# Mod paths
|
|
|
|
script_path = os.path.realpath(__file__)
|
|
|
|
project_path = os.path.dirname(os.path.dirname(script_path))
|
|
|
|
addons_path = os.path.join(project_path, "addons")
|
2016-09-17 09:40:50 +00:00
|
|
|
optionals_path = os.path.join(project_path, "optionals")
|
2016-09-08 19:19:07 +00:00
|
|
|
|
|
|
|
# Documentation paths
|
|
|
|
include_path = os.path.join(project_path, "docs", "_includes")
|
|
|
|
dependencies_path = os.path.join(include_path, "dependencies_list.md")
|
|
|
|
|
|
|
|
# Prepare files and paths list
|
|
|
|
if not os.path.exists(include_path):
|
2016-08-19 13:58:39 +00:00
|
|
|
print("Jekyll documentation not found!")
|
|
|
|
sys.exit(0)
|
2016-06-09 12:59:26 +00:00
|
|
|
|
2016-09-08 19:19:07 +00:00
|
|
|
open(dependencies_path, "w", newline="\n").close()
|
2016-09-17 09:40:50 +00:00
|
|
|
if os.path.exists(addons_path):
|
2018-02-07 21:38:34 +00:00
|
|
|
addons = sorted(next(os.walk(addons_path))[1])
|
2016-09-17 09:40:50 +00:00
|
|
|
if os.path.exists(optionals_path):
|
2018-02-07 21:38:34 +00:00
|
|
|
addons += ["."] + sorted(next(os.walk(optionals_path))[1])
|
2016-09-17 09:40:50 +00:00
|
|
|
|
2016-09-08 19:19:07 +00:00
|
|
|
dependencies_path_current = dependencies_path
|
|
|
|
addons_path_current = addons_path
|
2016-06-09 12:59:26 +00:00
|
|
|
|
2016-09-08 19:19:07 +00:00
|
|
|
# Iterate through folders in the addons directories
|
|
|
|
for folder in addons:
|
2016-08-19 13:58:39 +00:00
|
|
|
# Ignore "main" component
|
|
|
|
if folder == "main":
|
|
|
|
continue
|
|
|
|
|
2016-09-17 09:40:50 +00:00
|
|
|
# Change to optionals list on "." separator
|
2016-09-08 19:19:07 +00:00
|
|
|
if folder == ".":
|
2016-09-17 09:40:50 +00:00
|
|
|
if addons_path_current == addons_path:
|
|
|
|
addons_path_current = optionals_path
|
2016-09-08 19:19:07 +00:00
|
|
|
continue
|
|
|
|
|
2016-06-09 12:59:26 +00:00
|
|
|
# Open config.cpp file and extract dependencies
|
|
|
|
data = []
|
2016-09-08 19:19:07 +00:00
|
|
|
configfile = os.path.join(addons_path_current, folder, "config.cpp")
|
|
|
|
|
2016-08-19 14:12:09 +00:00
|
|
|
if os.path.exists(configfile):
|
2016-09-08 19:19:07 +00:00
|
|
|
with open(os.path.join(addons_path_current, folder, "config.cpp")) as file:
|
2016-08-19 14:12:09 +00:00
|
|
|
match = False
|
|
|
|
for line in file:
|
|
|
|
# One-line
|
|
|
|
if not match and re.match(r"\s+requiredAddons\[\]\ = {.+?};", line):
|
2016-06-09 12:59:26 +00:00
|
|
|
data += get_dependencies(line)
|
|
|
|
break
|
2016-08-19 14:12:09 +00:00
|
|
|
# Multi-line
|
|
|
|
else:
|
|
|
|
if re.match(r"\s+requiredAddons\[\]\ = {", line):
|
|
|
|
# First line
|
|
|
|
match = True
|
|
|
|
data += get_dependencies(line)
|
|
|
|
continue
|
|
|
|
elif match and re.match(r"\s+};", line):
|
|
|
|
# Final line
|
|
|
|
data += get_dependencies(line)
|
|
|
|
match = False
|
|
|
|
break
|
|
|
|
elif match:
|
|
|
|
# All lines between
|
|
|
|
data += get_dependencies(line)
|
|
|
|
continue
|
2016-06-09 12:59:26 +00:00
|
|
|
|
2024-08-12 13:16:27 +00:00
|
|
|
# Sort addons alphabetically
|
|
|
|
data.sort(key=str.casefold)
|
|
|
|
|
2016-09-17 09:40:50 +00:00
|
|
|
data = "`, `".join(data)
|
|
|
|
data = "`{}`".format(data)
|
2016-08-19 14:12:09 +00:00
|
|
|
|
2016-09-17 09:40:50 +00:00
|
|
|
jekyll_statement = "".join([
|
|
|
|
"{% if include.component == \"" + folder + "\" %}\n",
|
2021-12-02 14:40:46 +00:00
|
|
|
"- {}\n".format(data.replace(", ", "\n- ")),
|
2016-09-17 09:40:50 +00:00
|
|
|
"{% endif %}\n"
|
|
|
|
])
|
2016-06-09 12:59:26 +00:00
|
|
|
|
2016-09-17 09:40:50 +00:00
|
|
|
with open(dependencies_path_current, "a", newline="\n") as file:
|
|
|
|
file.writelines([jekyll_statement, "\n"])
|
2016-08-19 14:12:09 +00:00
|
|
|
|
2016-09-17 09:40:50 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
2021-10-21 16:27:25 +00:00
|
|
|
print("{}: {}".format(folder, data))
|
2016-09-17 09:40:50 +00:00
|
|
|
else:
|
|
|
|
print(jekyll_statement)
|
2016-06-09 12:59:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|