proper scene folder discovery
This commit is contained in:
parent
c87c517217
commit
4046e757ef
7 changed files with 94 additions and 31 deletions
|
|
@ -19,7 +19,9 @@ def crypt_dir(dir_in, key, encrypt=False, no_compress=False):
|
|||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
|
||||
pcrypt = partial(crypt_file, key=key, encrypt=encrypt, no_compress=no_compress)
|
||||
pcrypt = partial(
|
||||
crypt_file, key=key, encrypt=encrypt, no_compress=no_compress
|
||||
)
|
||||
with Pool() as p:
|
||||
p.map(pcrypt, files)
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,11 @@ def update_names(dir_in, old_path, languages):
|
|||
langfile, "w", newline="\n"
|
||||
) as lang_file: # you're using git right
|
||||
json.dump(
|
||||
out_dict, lang_file, ensure_ascii=False, indent="\t", sort_keys=True
|
||||
out_dict,
|
||||
lang_file,
|
||||
ensure_ascii=False,
|
||||
indent="\t",
|
||||
sort_keys=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -97,6 +101,8 @@ def read_mission(tsv_path, char_names, char_sets):
|
|||
if row["Command"] and row["Command"].startswith("//"):
|
||||
continue
|
||||
if row["Text"] and row["Arg1"]:
|
||||
if (row["Arg1"] not in char_names) and (row["Arg1"] not in char_sets):
|
||||
if (row["Arg1"] not in char_names) and (
|
||||
row["Arg1"] not in char_sets
|
||||
):
|
||||
new_names.add(row["Arg1"])
|
||||
return new_names
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import errno
|
|||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
from functools import partial
|
||||
|
|
@ -12,17 +11,20 @@ from multiprocessing.pool import Pool
|
|||
|
||||
|
||||
def translate_dir(dir_in, tsv_out_dir, json_out_dir):
|
||||
# we only want to key files that are mission ids
|
||||
files = [
|
||||
f
|
||||
for f in glob(os.path.join(dir_in, "**/*.tsv"), recursive=True)
|
||||
if re.search(r"/[0-9]{9}\.tsv$", f)
|
||||
for f in glob(
|
||||
os.path.join(dir_in, "**/Scenario/*.tsv"), recursive=True
|
||||
)
|
||||
if "{os.path.sep}Diva{os.path.sep}" not in f
|
||||
]
|
||||
|
||||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
|
||||
ptrans = partial(translate_file, tsv_out_dir=tsv_out_dir, json_out_dir=json_out_dir)
|
||||
ptrans = partial(
|
||||
translate_file, tsv_out_dir=tsv_out_dir, json_out_dir=json_out_dir
|
||||
)
|
||||
with Pool() as p:
|
||||
p.map(ptrans, files)
|
||||
|
||||
|
|
@ -36,7 +38,7 @@ def translate_file(file_in, tsv_out_dir, json_out_dir):
|
|||
# ie, Utage/>>>main01<<</Scenario/whatever.tsv
|
||||
try:
|
||||
event_folder = os.path.normpath(file_in).split(os.sep)[-3]
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print("Error processing tsv: Please reference from Utage root")
|
||||
raise
|
||||
|
|
@ -47,7 +49,9 @@ def translate_file(file_in, tsv_out_dir, json_out_dir):
|
|||
tsv_out_dir, event_folder, "Scenario", "{}_t.tsv".format(id_num)
|
||||
)
|
||||
json_output_path = os.path.join(
|
||||
json_out_dir, event_folder, "{}_translations_jpn.json".format(id_num)
|
||||
json_out_dir,
|
||||
event_folder,
|
||||
"{}_translations_jpn.json".format(id_num),
|
||||
)
|
||||
|
||||
# need to create output paths and avoid races when threading
|
||||
|
|
@ -86,10 +90,14 @@ def translate_file(file_in, tsv_out_dir, json_out_dir):
|
|||
with io.open(json_output_path, "w", newline="\n") as json_out:
|
||||
# we don't want to sort these because they're _1, ..., _10, etc
|
||||
json.dump(
|
||||
json_str, json_out, ensure_ascii=False, indent="\t", sort_keys=False
|
||||
json_str,
|
||||
json_out,
|
||||
ensure_ascii=False,
|
||||
indent="\t",
|
||||
sort_keys=False,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print("Error processing file: " + file_in)
|
||||
|
||||
|
|
@ -110,7 +118,7 @@ def process_tsv(tsv, id_num):
|
|||
row["English"] = key
|
||||
key_dict[key] = row["Text"]
|
||||
tsv_keyed.append(row)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print("Error processing tsv: " + id_num)
|
||||
raise
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue