mostly cosmetic

master
Jaka Perovšek 2024-10-18 01:13:14 +02:00
parent fd0e5ddc3c
commit 3743dfbdaa
2 changed files with 19 additions and 26 deletions

View File

@ -18,6 +18,7 @@ from distutils.dir_util import copy_tree
from pathlib import Path from pathlib import Path
from subprocess import PIPE, STDOUT, CalledProcessError, CompletedProcess, Popen from subprocess import PIPE, STDOUT, CalledProcessError, CompletedProcess, Popen
def rmfulldir(dirpath): def rmfulldir(dirpath):
try: try:
shutil.rmtree(dirpath) shutil.rmtree(dirpath)
@ -71,7 +72,6 @@ class Deployer:
self.source_dir = "./source" self.source_dir = "./source"
self.install_dir = self.find_install_dir() self.install_dir = self.find_install_dir()
def find_install_dir(self): def find_install_dir(self):
self.logger.info("Trying to find Barotraumma install folder") self.logger.info("Trying to find Barotraumma install folder")
library_folders = Path("C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf") library_folders = Path("C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf")
@ -122,7 +122,7 @@ class Deployer:
os.remove(out_archive) os.remove(out_archive)
def update(self): def update(self):
self.logger.info(f"checking for updates via git pull.") self.logger.info(f"Checking for updates via git pull.")
pull = [f"{self.utils_dir}/git/bin/git.exe", "pull"] pull = [f"{self.utils_dir}/git/bin/git.exe", "pull"]
stream_command(pull, stdout_handler=self.logger.info) stream_command(pull, stdout_handler=self.logger.info)
@ -155,9 +155,8 @@ class Deployer:
try: try:
stream_command(cut, stdout_handler=self.logger.info) stream_command(cut, stdout_handler=self.logger.info)
except FileNotFoundError: except FileNotFoundError:
print("ffmpeg not in utils directory. Run python install_dependencies.py " self.logger.error("ffmpeg not in utils directory.")
"or download the latest release version manually.") return
sys.exit()
walkman = [f"{self.utils_dir}/ffmpeg-" + ffmpeg_version + "-full_build/bin/ffmpeg.exe", walkman = [f"{self.utils_dir}/ffmpeg-" + ffmpeg_version + "-full_build/bin/ffmpeg.exe",
"-i", f"{self.music_dir}/{tape['identifier']}.ogg", "-i", f"{self.music_dir}/{tape['identifier']}.ogg",
@ -167,10 +166,8 @@ class Deployer:
try: try:
stream_command(walkman, stdout_handler=self.logger.info) stream_command(walkman, stdout_handler=self.logger.info)
except FileNotFoundError: except FileNotFoundError:
self.logger.error("ffmpeg not in utils directory. Run python install_dependencies.py " self.logger.error("ffmpeg not in utils directory.")
"or download the latest release version manually.") return
sys.exit()
def assemble_png_images(self, tapes, outfile: str, resize=None): def assemble_png_images(self, tapes, outfile: str, resize=None):
img_names = [f"{self.source_dir}/images/{tape['identifier']}.png" for tape in tapes] img_names = [f"{self.source_dir}/images/{tape['identifier']}.png" for tape in tapes]
@ -203,7 +200,6 @@ class Deployer:
new_im.save(f"{self.build_dir}/{outfile}.png") new_im.save(f"{self.build_dir}/{outfile}.png")
def prepare_music(self, data): def prepare_music(self, data):
try: try:
os.mkdir(f'{self.music_dir}') os.mkdir(f'{self.music_dir}')
@ -212,7 +208,7 @@ class Deployer:
ffmpeg_version = get_ffmpeg_version() ffmpeg_version = get_ffmpeg_version()
self.logger.info("downloading and cutting the songs") self.logger.info("Downloading and cutting the songs.")
for i, tape in enumerate(data): for i, tape in enumerate(data):
if not (os.path.exists(f"{self.music_dir}/{tape['identifier']}.ogg") or os.path.exists( if not (os.path.exists(f"{self.music_dir}/{tape['identifier']}.ogg") or os.path.exists(
f"{self.music_dir}/{tape['identifier']}-walkman.ogg")): f"{self.music_dir}/{tape['identifier']}-walkman.ogg")):
@ -221,27 +217,25 @@ class Deployer:
else: else:
self.logger.info(f"{i + 1}/{len(data)} Already exists: {tape['name']}") self.logger.info(f"{i + 1}/{len(data)} Already exists: {tape['name']}")
self.logger.info(f"removing temporary music folder") self.logger.info(f"Removing temporary music folder.")
rmfulldir(f"{self.build_dir}/tmp_music/") rmfulldir(f"{self.build_dir}/tmp_music/")
self.logger.info(f"copying the sound effects to build") self.logger.info(f"Copying the sound effects to build.")
copy_tree(f"{self.source_dir}/sound_effects", f"{self.build_dir}/sound_effects") copy_tree(f"{self.source_dir}/sound_effects", f"{self.build_dir}/sound_effects")
def prepare_images(self, data): def prepare_images(self, data):
logging.info(f"assembling covers and icons into png files") self.logger.info(f"Assembling covers and icons into png files.")
self.assemble_png_images(data, "covers") self.assemble_png_images(data, "covers")
self.assemble_png_images(data, "icons", resize=(64, 41)) self.assemble_png_images(data, "icons", resize=(64, 41))
self.assemble_png_images(data, "sprites", resize=(33, 21)) self.assemble_png_images(data, "sprites", resize=(33, 21))
logging.info(f"copying other images") self.logger.info(f"Copying other images.")
shutil.copy(f"{self.source_dir}/images/players_icons.png", f"{self.build_dir}/players_icons.png") shutil.copy(f"{self.source_dir}/images/players_icons.png", f"{self.build_dir}/players_icons.png")
shutil.copy(f"{self.source_dir}/images/players_sprites.png", f"{self.build_dir}/players_sprites.png") shutil.copy(f"{self.source_dir}/images/players_sprites.png", f"{self.build_dir}/players_sprites.png")
shutil.copy(f"{self.source_dir}/images/PreviewImage.png", f"{self.build_dir}/PreviewImage.png") shutil.copy(f"{self.source_dir}/images/PreviewImage.png", f"{self.build_dir}/PreviewImage.png")
def build_xml_code(self, data, config): def build_xml_code(self, data, config):
self.logger.info(f"calculate the value that lets you use the songs n-times") self.logger.info(f"Calculate the value that lets you use the songs n-times.")
song_lengths = [OggVorbis(f"{self.music_dir}/{tape['identifier']}.ogg").info.length song_lengths = [OggVorbis(f"{self.music_dir}/{tape['identifier']}.ogg").info.length
for tape in data] for tape in data]
@ -254,7 +248,7 @@ class Deployer:
columns = int((len(data)) ** 0.5) columns = int((len(data)) ** 0.5)
positions = [{"column": i % columns, "row": math.floor(i / columns)} for i in range(len(data))] positions = [{"column": i % columns, "row": math.floor(i / columns)} for i in range(len(data))]
self.logger.info(f"creating jinja environment") self.logger.info(f"Creating jinja environment.")
# create jinja2 environment # create jinja2 environment
j2env = j2.Environment(loader=j2.FileSystemLoader(Path("."))) j2env = j2.Environment(loader=j2.FileSystemLoader(Path(".")))
j2env.globals.update(zip=zip) j2env.globals.update(zip=zip)
@ -264,7 +258,7 @@ class Deployer:
template1 = j2env.get_template(f"{self.source_dir}/sunken_tapes_template.xml") template1 = j2env.get_template(f"{self.source_dir}/sunken_tapes_template.xml")
template2 = j2env.get_template(f"{self.source_dir}/sunken_tapes_style_template.xml") template2 = j2env.get_template(f"{self.source_dir}/sunken_tapes_style_template.xml")
self.logger.info(f"rendering the xml files") self.logger.info(f"Rendering the xml files.")
with open(f"{self.build_dir}/filelist.xml", "w+", encoding="utf8") as output_file: with open(f"{self.build_dir}/filelist.xml", "w+", encoding="utf8") as output_file:
# render the template # render the template
output_file.write(template0.render(config=config, tapes=data)) output_file.write(template0.render(config=config, tapes=data))
@ -281,19 +275,18 @@ class Deployer:
# render the template # render the template
output_file.write(template2.render(tapes=data, config=config, positions=positions)) output_file.write(template2.render(tapes=data, config=config, positions=positions))
def deploy(self, local_mod_name: str, config): def deploy(self, local_mod_name: str, config):
try: try:
os.mkdir(self.build_dir) os.mkdir(self.build_dir)
except FileExistsError: except FileExistsError:
self.logger.info(f"removing old XML files in ./build/:") self.logger.info(f"Removing old XML files in {self.build_dir}/:")
for f in Path(self.build_dir).glob("*.xml"): for f in Path(self.build_dir).glob("*.xml"):
self.logger.info(f" {f}") self.logger.info(f" {f}")
os.remove(f) os.remove(f)
pass pass
self.logger.info("Reading tapes.yaml") self.logger.info("Reading tapes.yaml")
data_file = Path("./source/tapes.yaml") data_file = Path(f"{self.source_dir}/tapes.yaml")
# load yaml file # load yaml file
with data_file.open(encoding='utf-8') as fr: with data_file.open(encoding='utf-8') as fr:
@ -305,10 +298,10 @@ class Deployer:
mod_directory = f"{self.install_dir}/LocalMods/{local_mod_name}/" mod_directory = f"{self.install_dir}/LocalMods/{local_mod_name}/"
self.logger.info(f"removing the old installed mod directory {mod_directory}") self.logger.info(f"Removing the old installed mod directory {mod_directory}.")
rmfulldir(mod_directory) rmfulldir(mod_directory)
self.logger.info(f"copying the new build") self.logger.info(f"Copying the new build.")
if Path(f"{self.install_dir}").is_dir(): if Path(f"{self.install_dir}").is_dir():
copy_tree(self.build_dir, mod_directory) copy_tree(self.build_dir, mod_directory)
else: else:

View File

@ -441,7 +441,7 @@ class UpdateWidget(QGroupBox):
return exists return exists
def update_action(self): def update_action(self):
Thread(target=self.deployer.update).start() Thread(target=self.deployer.update).start()
class ConsoleWidget(QGroupBox): class ConsoleWidget(QGroupBox):