wmlunits: Correctly get Wesnoth paths in Windows

This commit is contained in:
Ivo Julca 2023-05-08 17:48:41 -05:00 committed by Gunter Labes
parent b61b045ae0
commit 5136c45b3e
2 changed files with 26 additions and 26 deletions

View file

@ -8,20 +8,6 @@ import sys, os, re, glob, shutil, copy, subprocess
import wesnoth.wmlparser3 as wmlparser3
from unit_tree.team_colorizer import colorize
def get_datadir(wesnoth_exe):
p = subprocess.Popen([wesnoth_exe, "--data-path"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
return out.strip()
def get_userdir(wesnoth_exe):
p = subprocess.Popen([wesnoth_exe, "--userdata-path"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
return out.strip()
class Image:
def __init__(self, id_name, ipath, bases, no_tc):
self.id_name = id_name
@ -40,11 +26,14 @@ class ImageCollector:
self.images_by_ipath = {}
self.binary_paths_per_addon = {}
self.datadir = datadir
if not self.datadir:
self.datadir = get_datadir(wesnoth_exe)
self.userdir = userdir
if not self.userdir:
self.userdir = get_userdir(wesnoth_exe)
self.hide_paths = [
os.path.join(self.userdir, "data", "add-ons"),
os.path.join(self.userdir, "data"),
os.path.join(self.userdir),
os.path.join(self.datadir, "data"),
os.path.join(self.datadir)
]
self.magick = magick_exe
def add_binary_paths_from_WML(self, addon, WML):

View file

@ -33,12 +33,15 @@ def copy_images():
shutil.copy2(os.path.join(os.path.dirname(os.path.realpath(__file__)), "unit_tree", "menu.js"),
options.output)
def shell_out(com):
p = subprocess.Popen(com,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
return out
def shell_out(wesnoth_exe, com):
base_com = [wesnoth_exe, "--nobanner"] + com
cli_opt_matrix = [[], ["--no-log-to-file"], ["--wnoconsole", "--wnoredirect"]]
for cli_opts in cli_opt_matrix:
com = base_com + cli_opts
p = subprocess.run(com, capture_output=True, text=True)
if p.returncode == 0:
return p.stdout.strip()
return ""
def move(f, t, name):
if os.path.exists(os.path.join(f, name + ".cfg")):
@ -615,11 +618,19 @@ if __name__ == '__main__':
options.wesnoth = "wesnoth"
if not options.data_dir:
options.data_dir = shell_out([options.wesnoth, "--data-path"]).strip().decode("utf8")
options.data_dir = shell_out(options.wesnoth, ["--data-path"]).strip()
if not options.data_dir:
sys.stderr.write("Need --data-dir.\n")
ap.print_help()
sys.exit(-1)
print("Using " + options.data_dir + " as data dir.")
if not options.config_dir:
options.config_dir = shell_out([options.wesnoth, "--userdata-path"]).strip().decode("utf8")
options.config_dir = shell_out(options.wesnoth, ["--userdata-path"]).strip()
if not options.config_dir:
sys.stderr.write("Need --config-dir.\n")
ap.print_help()
sys.exit(-1)
print("Using " + options.config_dir + " as config dir.")
if not options.transdir: