File: activate.py

package info (click to toggle)
libretro-nestopia 1.52.0%2B20230102.gitcb1e24e-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,960 kB
  • sloc: cpp: 107,513; xml: 27,221; python: 1,329; ansic: 772; makefile: 634
file content (70 lines) | stat: -rw-r--r-- 2,805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3

import os
import glob
import random as r

# --------------------          MAIN          -------------------- #

if __name__ == '__main__':
   DIR_PATH = os.path.dirname(os.path.realpath(__file__))
   if os.path.basename(DIR_PATH) != "intl":
      raise RuntimeError("Script is not in intl folder!")

   BASE_PATH = os.path.dirname(DIR_PATH)
   WORKFLOW_PATH = os.path.join(BASE_PATH, ".github", "workflows")
   PREP_WF = os.path.join(WORKFLOW_PATH, "crowdin_prep.yml")
   TRANSLATE_WF = os.path.join(WORKFLOW_PATH, "crowdin_translate.yml")
   CORE_NAME = os.path.basename(BASE_PATH)
   CORE_OP_FILE = os.path.join(BASE_PATH, "**", "libretro_core_options.h")

   core_options_hits = glob.glob(CORE_OP_FILE, recursive=True)

   if len(core_options_hits) == 0:
      raise RuntimeError("libretro_core_options.h not found!")
   elif len(core_options_hits) > 1:
      print("More than one libretro_core_options.h file found:\n\n")
      for i, file in enumerate(core_options_hits):
         print(f"{i} {file}\n")

      while True:
         user_choice = input("Please choose one ('q' will exit): ")
         if user_choice == 'q':
            exit(0)
         elif user_choice.isdigit():
            core_op_file = core_options_hits[int(user_choice)]
            break
         else:
            print("Please make a valid choice!\n\n")
   else:
      core_op_file = core_options_hits[0]

   core_intl_file = os.path.join(os.path.dirname(core_op_file.replace(BASE_PATH, ''))[1:],
                                 'libretro_core_options_intl.h')
   core_op_file   = os.path.join(os.path.dirname(core_op_file.replace(BASE_PATH, ''))[1:],
                                 'libretro_core_options.h')
   minutes = r.randrange(0, 59, 5)
   hour = r.randrange(0, 23)

   with open(PREP_WF, 'r') as wf_file:
      prep_txt = wf_file.read()

   prep_txt = prep_txt.replace("<CORE_NAME>", CORE_NAME)
   prep_txt = prep_txt.replace("<PATH/TO>/libretro_core_options.h",
                               core_op_file)
   with open(PREP_WF, 'w') as wf_file:
      wf_file.write(prep_txt)


   with open(TRANSLATE_WF, 'r') as wf_file:
      translate_txt = wf_file.read()

   translate_txt = translate_txt.replace('<0-59>', f"{minutes}")
   translate_txt = translate_txt.replace('<0-23>', f"{hour}")
   translate_txt = translate_txt.replace('# Fridays at , UTC',
                                         f"# Fridays at {hour%12}:{minutes if minutes > 9 else '0' + str(minutes)} {'AM' if hour < 12 else 'PM'}, UTC")
   translate_txt = translate_txt.replace("<CORE_NAME>", CORE_NAME)
   translate_txt = translate_txt.replace('<PATH/TO>/libretro_core_options_intl.h',
                                         core_intl_file)
   with open(TRANSLATE_WF, 'w') as wf_file:
      wf_file.write(translate_txt)