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

View File

@@ -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: