Debian Codegraph @

intl/activate.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 import os
4 import glob
5 import random as r
6
7 # -------------------- MAIN -------------------- #
8
9 if __name__ == '__main__':
10 DIR_PATH = os.path.dirname(os.path.realpath(__file__))
11 if os.path.basename(DIR_PATH) != "intl":
12 raise RuntimeError("Script is not in intl folder!")
13
14 BASE_PATH = os.path.dirname(DIR_PATH)
15 WORKFLOW_PATH = os.path.join(BASE_PATH, ".github", "workflows")
16 PREP_WF = os.path.join(WORKFLOW_PATH, "crowdin_prep.yml")
17 TRANSLATE_WF = os.path.join(WORKFLOW_PATH, "crowdin_translate.yml")
18 CORE_NAME = os.path.basename(BASE_PATH)
19 CORE_OP_FILE = os.path.join(BASE_PATH, "**", "libretro_core_options.h")
20
21 core_options_hits = glob.glob(CORE_OP_FILE, recursive=True)
22
23 if len(core_options_hits) == 0:
24 raise RuntimeError("libretro_core_options.h not found!")
25 elif len(core_options_hits) > 1:
26 print("More than one libretro_core_options.h file found:\n\n")
27 for i, file in enumerate(core_options_hits):
28 print(f"{i} {file}\n")
29
30 while True:
31 user_choice = input("Please choose one ('q' will exit): ")
32 if user_choice == 'q':
33 exit(0)
34 elif user_choice.isdigit():
35 core_op_file = core_options_hits[int(user_choice)]
36 break
37 else:
38 print("Please make a valid choice!\n\n")
39 else:
40 core_op_file = core_options_hits[0]
41
42 core_intl_file = os.path.join(os.path.dirname(core_op_file.replace(BASE_PATH, ''))[1:],
43 'libretro_core_options_intl.h')
44 core_op_file = os.path.join(os.path.dirname(core_op_file.replace(BASE_PATH, ''))[1:],
45 'libretro_core_options.h')
46 minutes = r.randrange(0, 59, 5)
47 hour = r.randrange(0, 23)
48
49 with open(PREP_WF, 'r') as wf_file:
50 prep_txt = wf_file.read()
51
52 prep_txt = prep_txt.replace("<CORE_NAME>", CORE_NAME)
53 prep_txt = prep_txt.replace("<PATH/TO>/libretro_core_options.h",
54 core_op_file)
55 with open(PREP_WF, 'w') as wf_file:
56 wf_file.write(prep_txt)
57
58
59 with open(TRANSLATE_WF, 'r') as wf_file:
60 translate_txt = wf_file.read()
61
62 translate_txt = translate_txt.replace('<0-59>', f"{minutes}")
63 translate_txt = translate_txt.replace('<0-23>', f"{hour}")
64 translate_txt = translate_txt.replace('# Fridays at , UTC',
65 f"# Fridays at {hour%12}:{minutes if minutes > 9 else '0' + str(minutes)} {'AM' if hour < 12 else 'PM'}, UTC")
66 translate_txt = translate_txt.replace("<CORE_NAME>", CORE_NAME)
67 translate_txt = translate_txt.replace('<PATH/TO>/libretro_core_options_intl.h',
68 core_intl_file)
69 with open(TRANSLATE_WF, 'w') as wf_file:
70 wf_file.write(translate_txt)