sorting out zsh script calling and folder names
This commit is contained in:
parent
c5736014db
commit
ecde988fd9
6 changed files with 79 additions and 51 deletions
|
|
@ -10,26 +10,22 @@ from glob import glob
|
|||
from multiprocessing.pool import Pool
|
||||
|
||||
|
||||
def translate_dir(dir_in, tsv_out_dir, json_out_dir):
|
||||
def translate_dir(dir_in, tsv_out_dir, json_out_dir, is_global):
|
||||
files = [
|
||||
f
|
||||
for f in glob(
|
||||
os.path.join(dir_in, "**/Scenario/*.tsv"), recursive=True
|
||||
)
|
||||
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)
|
||||
|
||||
|
||||
def translate_file(file_in, tsv_out_dir, json_out_dir):
|
||||
def translate_file(file_in, tsv_out_dir, json_out_dir, is_global):
|
||||
try:
|
||||
if not file_in.endswith(".tsv"):
|
||||
raise ValueError("Invalid File Type for {}".format(file_in))
|
||||
|
|
@ -49,9 +45,7 @@ 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
|
||||
|
|
@ -90,11 +84,7 @@ 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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue