2022-06-07 17:52:22 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-06-17 01:47:54 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
curr_dir = os.path.dirname(__file__)
|
2022-06-07 17:52:22 +00:00
|
|
|
xkb = "/usr/share/X11/xkb"
|
|
|
|
|
2022-06-17 01:47:54 +00:00
|
|
|
|
2022-06-07 17:52:22 +00:00
|
|
|
def brackets(text):
|
|
|
|
res = 0
|
|
|
|
slash = 0
|
|
|
|
for i in text:
|
2023-10-16 21:35:20 +00:00
|
|
|
if i == "/":
|
|
|
|
slash += 1
|
|
|
|
if slash == 2:
|
|
|
|
break
|
|
|
|
continue
|
2023-10-16 21:40:58 +00:00
|
|
|
elif i == "{":
|
2023-10-16 21:35:20 +00:00
|
|
|
res += 1
|
2023-10-16 21:40:58 +00:00
|
|
|
elif i == "}":
|
2023-10-16 21:35:20 +00:00
|
|
|
res -= 1
|
2022-06-07 17:52:22 +00:00
|
|
|
slash = 0
|
|
|
|
return res
|
|
|
|
|
2022-06-17 01:47:54 +00:00
|
|
|
|
|
|
|
def bracket_end(code, pos):
|
2022-06-07 17:52:22 +00:00
|
|
|
indent = 0
|
|
|
|
while indent := indent + brackets(code[pos]):
|
|
|
|
pos += 1
|
|
|
|
return pos + 1
|
|
|
|
|
2022-06-17 01:47:54 +00:00
|
|
|
|
2022-06-07 17:52:22 +00:00
|
|
|
with open(f"{xkb}/rules/evdev.extras.xml", "r") as f:
|
2022-06-17 01:47:54 +00:00
|
|
|
evdev = f.read().split("\n")
|
|
|
|
with open(f"{curr_dir}/patches/evdev", "r") as f:
|
|
|
|
evdev_patch = f.read().split("\n")
|
|
|
|
with open(f"{xkb}/symbols/de", "r") as f:
|
|
|
|
de = f.read().split("\n")
|
|
|
|
with open(f"{curr_dir}/patches/de_neo_base") as f:
|
|
|
|
de_neo_base_patch = f.read().split("\n")
|
|
|
|
with open(f"{curr_dir}/patches/de_koy") as f:
|
|
|
|
de_koy_patch = f.read().split("\n")
|
|
|
|
with open(f"{xkb}/symbols/level3", "r") as f:
|
|
|
|
level3 = f.read()
|
|
|
|
with open(f"{curr_dir}/patches/level3") as f:
|
|
|
|
level3_patch = f.read().split("\n")
|
|
|
|
|
|
|
|
if "vou" not in "\n".join(evdev):
|
2022-06-07 17:52:22 +00:00
|
|
|
koy = [i for i in range(len(evdev)) if "koy" in evdev[i]][0] - 2
|
|
|
|
vou = koy + 6
|
2022-06-17 01:47:54 +00:00
|
|
|
evdev = evdev[:vou] + evdev_patch + evdev[vou:]
|
2022-06-07 17:52:22 +00:00
|
|
|
with open(f"{xkb}/rules/evdev.extras.xml", "w") as f:
|
|
|
|
f.write("\n".join(evdev))
|
|
|
|
|
2022-06-17 01:47:54 +00:00
|
|
|
if "vou" not in "\n".join(de):
|
2022-06-07 17:52:22 +00:00
|
|
|
neo_base = ([i for i in range(len(de)) if "\"neo_base\"" in de[i]][0], -1)
|
2022-06-17 01:47:54 +00:00
|
|
|
neo_base = (neo_base[0] - 1, bracket_end(de, neo_base[0]))
|
|
|
|
de = de[:neo_base[0]] + de_neo_base_patch + de[neo_base[1]:]
|
2022-06-07 17:52:22 +00:00
|
|
|
koy = ([i for i in range(len(de)) if "\"koy\"" in de[i]][0], -1)
|
2022-06-17 01:47:54 +00:00
|
|
|
koy = (koy[0] - 1, bracket_end(de, koy[0]))
|
|
|
|
de = de[:koy[1]] + de_koy_patch + de[koy[1]:]
|
2023-10-16 23:09:35 +00:00
|
|
|
with open(f"{xkb}/symbols/de", "w") as f:
|
2022-06-07 17:52:22 +00:00
|
|
|
f.write("\n".join(de))
|
2022-06-17 01:47:54 +00:00
|
|
|
|
|
|
|
if "quote_switch" not in "\n".join(level3):
|
2022-06-07 17:52:22 +00:00
|
|
|
level3 = level3.split("\n")
|
|
|
|
bksl_switch = ([i for i in range(len(level3)) if "\"bksl_switch\"" in level3[i]][0], -1)
|
2022-06-17 01:47:54 +00:00
|
|
|
bksl_switch = (bksl_switch[0] - 1, bracket_end(level3, bksl_switch[0]))
|
|
|
|
level3 = level3[:bksl_switch[1]] + level3_patch + level3[bksl_switch[1]:]
|
2022-06-07 17:52:22 +00:00
|
|
|
with open(f"{xkb}/symbols/level3", "w") as f:
|
|
|
|
f.write("\n".join(level3))
|