From 1c06764d031f5e42c3fdffda89363518211b4f90 Mon Sep 17 00:00:00 2001 From: jonpas Date: Thu, 9 Jun 2016 14:59:26 +0200 Subject: [PATCH] Add Extract Dependencies script (#2640) * Add Extract Dependencies Python script, Add tools\temp to .gitignore * Change backtick to single quote * Remove unnecessary import * Remove all whitespace * Add support for multi-line dependencies, Add header comment, Improve * Fix final message * Update output to Jekyll IF statements for inclusion on pages * Space * Correct comments for Jekyll usage --- .gitignore | 1 + tools/extract_dependencies.py | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 tools/extract_dependencies.py diff --git a/.gitignore b/.gitignore index f312ddb55e..4bc9845ffe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ release/* +tools/temp *.cache *.pbo texHeaders.bin diff --git a/tools/extract_dependencies.py b/tools/extract_dependencies.py new file mode 100644 index 0000000000..53c9e3f9b4 --- /dev/null +++ b/tools/extract_dependencies.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +# Author: Jonpas +# Extracts dependencies to a file (defined in globals) for use with Jekyll include statement. +# Place generated file to "_includes/" folder on gh-pages branch and use the following line to add dependencies to a feature page: +# {% include dependencies_list.md component="" %} + +import os +import sys +import re + +######## GLOBALS ######### +FILE_EXTRACTED = "temp\\dependencies_list.md" +########################## + +def get_dependencies(line): + dependencies = re.findall(r'"(.*?)"', line) + return dependencies + + +def main(): + print(""" + #################################### + # Extract ACE3 Module Dependencies # + # (for Jekyll include) # + #################################### + """) + + scriptpath = os.path.realpath(__file__) + projectpath = os.path.dirname(os.path.dirname(scriptpath)) + addonspath = os.path.join(projectpath, "addons") + + # Prepare directory and file + if not os.path.exists("temp"): + os.makedirs("temp") + + open(FILE_EXTRACTED, "w").close() + + # Iterate through folders in the addons directory + for folder in next(os.walk(addonspath))[1]: + # Open config.cpp file and extract dependencies + data = [] + with open(os.path.join(addonspath, folder, "config.cpp")) as file: + match = False + for line in file: + # One-line + if not match and re.match(r"\s+requiredAddons\[\]\ = {.+?};", line): + data += get_dependencies(line) + break + # 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 + + data = "`, `".join(data) + data = "`{}`".format(data) + print("{}: {}".format(folder,data)) + + with open(FILE_EXTRACTED, "a") as file: + file.writelines([ + "{% if include.component == \"" + folder + "\" %}\n", + "{}\n".format(data), + "{% endif %}\n", + ]) + + print("\nCopy 'temp\dependencies_list.md' to '_includes/' folder on 'gh-pages' branch.") + + +if __name__ == "__main__": + main()