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
This commit is contained in:
Frank
2022-10-14 18:08:32 +02:00
parent 82aba06cb4
commit c7825692a2
+34 -10
View File
@@ -1,8 +1,8 @@
""" """
This script finds all miz files and updates the contained Moose.lua from a given one. 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. 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. All files that end with lua and do NOT start with Moose are extracted.
"Auftrag - 10 - Arty.lua" if the miz file name is "Auftrag - 10 - Arty.miz"
This script is supposed to be run from, e.g., github actions when a new demo mission is This script is supposed to be run from, e.g., github actions when a new demo mission is
uploaded. uploaded.
@@ -15,6 +15,20 @@ from shutil import rmtree, copy
import argparse import argparse
import filecmp 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): def update(f: Path, MooseLua: Path, Temp: Path):
""" """
Update the Moose.lua file in given file. 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!") print(f"WARNING: {ScriptDir.name} does not exit!")
return 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. # Script file.
ScriptFile=ScriptDir/Path(f.stem + ".lua") #ScriptFile=ScriptDir/Path(f.stem + ".lua")
#Copy script file to directory. #Copy script file to directory.
if ScriptFile.is_file(): #if ScriptFile.is_file():
print(f"Copying script file {ScriptFile} to {f.parent}") # print(f"Copying script file {ScriptFile} to {f.parent}")
copy(ScriptFile, f.parent) # copy(ScriptFile, f.parent)
else: #else:
print(f"Warning: expected script file {ScriptFile} does NOT exist in miz file!") # print(f"Warning: expected script file {ScriptFile} does NOT exist in miz file!")
# Check if Moose.lua file is already. # 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!") print(f"INFO: Moose.lua file is up-to-date ==> Nothing to do!")
else: else:
# Copy Moose.lua to temp dir. # Copy Moose.lua to temp dir.
copy(MooseLua, ScriptDir/"Moose.lua") copy(MooseLua, MooseOld)
# Create new miz file # Create new miz file
with ZipFile(f, mode='w') as archive: with ZipFile(f, mode='w') as archive: