From c7825692a2f9afe138fe53954e28509cba5f3c6e Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 14 Oct 2022 18:08:32 +0200 Subject: [PATCH] Update UpdateMoose.py - Script will now search for all lua files that start with "moose" (case insensitive) and replace them with the most current Moose_.lua - Script will now extract all lua files that do NOT start with "moose" (case insensitive) and place them next to the miz file --- .scripts/UpdateMoose.py | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/.scripts/UpdateMoose.py b/.scripts/UpdateMoose.py index a6b301f141..edea0470f3 100644 --- a/.scripts/UpdateMoose.py +++ b/.scripts/UpdateMoose.py @@ -1,8 +1,8 @@ """ This script finds all miz files and updates the contained Moose.lua from a given one. + It also extracts the contained mission script and places it next to the miz file. -Here we assume that the stem of the file name is the same as the directory name, e.g. -"Auftrag - 10 - Arty.lua" if the miz file name is "Auftrag - 10 - Arty.miz" +All files that end with lua and do NOT start with Moose are extracted. This script is supposed to be run from, e.g., github actions when a new demo mission is uploaded. @@ -15,6 +15,20 @@ from shutil import rmtree, copy import argparse import filecmp +def findMoose(path: Path): + # Loop over all lua files (recursively) + for f in path.rglob("*.lua"): + if f.name.lower().startswith("moose"): + print(f"Found Moose file as: {f}") + return f + +def copyScripts(path: Path, topath): + # Loop over all lua files (recursively) + for f in path.rglob("*.lua"): + if not f.name.lower().startswith("moose"): + print(f"Found script: {f}") + copy(f, topath) + def update(f: Path, MooseLua: Path, Temp: Path): """ Update the Moose.lua file in given file. @@ -34,23 +48,33 @@ def update(f: Path, MooseLua: Path, Temp: Path): print(f"WARNING: {ScriptDir.name} does not exit!") return + # Find old Moose file in Scrit directory. + MooseOld=findMoose(ScriptDir) + if not MooseOld.is_file(): + print("WARNING: Could not find any file that starts with Moose!") + return + + + # Copy all script files (all files that do NOT start with moose and end with lua) + copyScripts(ScriptDir, f.parent) + # Script file. - ScriptFile=ScriptDir/Path(f.stem + ".lua") + #ScriptFile=ScriptDir/Path(f.stem + ".lua") #Copy script file to directory. - if ScriptFile.is_file(): - print(f"Copying script file {ScriptFile} to {f.parent}") - copy(ScriptFile, f.parent) - else: - print(f"Warning: expected script file {ScriptFile} does NOT exist in miz file!") + #if ScriptFile.is_file(): + # print(f"Copying script file {ScriptFile} to {f.parent}") + # copy(ScriptFile, f.parent) + #else: + # print(f"Warning: expected script file {ScriptFile} does NOT exist in miz file!") # Check if Moose.lua file is already. - if filecmp.cmp(MooseLua, ScriptDir/"Moose.lua"): + if filecmp.cmp(MooseLua, MooseOld): print(f"INFO: Moose.lua file is up-to-date ==> Nothing to do!") else: # Copy Moose.lua to temp dir. - copy(MooseLua, ScriptDir/"Moose.lua") + copy(MooseLua, MooseOld) # Create new miz file with ZipFile(f, mode='w') as archive: