abouttreesummaryrefslogcommitdiff
path: root/check_layout.py
diff options
context:
space:
mode:
authorJules Aguillon2025-05-11 22:55:05 +0200
committerJules Aguillon2025-05-11 23:05:57 +0200
commitff9d2e7d31aea2fb08e1390b245a212185eac1f2 (patch)
tree69000a65de2080cef53b0f1ed4cb6e971e3caf0f /check_layout.py
parentb670fe0da2226f7f0729694f9210c1dd675d1ea1 (diff)
downloadunexpected-keyboard-ff9d2e7d31aea2fb08e1390b245a212185eac1f2.tar.gz
unexpected-keyboard-ff9d2e7d31aea2fb08e1390b245a212185eac1f2.zip
check_layout: Check for unknown keys
This can spot mispelled special keys.
Diffstat (limited to 'check_layout.py')
-rw-r--r--check_layout.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/check_layout.py b/check_layout.py
index ee1cbc9..0208a97 100644
--- a/check_layout.py
+++ b/check_layout.py
@@ -1,5 +1,5 @@
import xml.etree.ElementTree as ET
-import sys, os, glob
+import sys, os, glob, re
layout_file_name = 0
warnings = []
@@ -15,6 +15,9 @@ KEY_ATTRIBUTES = set([
"c", "nw", "ne", "sw", "se", "w", "e", "n", "s"
])
+# Keys defined in KeyValue.java
+known_keys = set()
+
def warn(msg):
global warnings
warnings.append("%s: %s" % (layout_file_name, msg))
@@ -103,6 +106,23 @@ def check_layout(layout):
if root.get("script") == None:
warn("Layout doesn't specify a script.")
+ keys_without_loc = set(( k.removeprefix("loc ") for k in keys ))
+ # Keys with a len under 3 are often composed characters
+ special_keys = set(( k for k in keys_without_loc if len(k) > 3 and ":" not in k ))
+ unknown = special_keys.difference(known_keys)
+ if len(unknown) > 0:
+ warn("Layout contains unknown keys: %s" % key_list_str(unknown))
+
+# Fill 'known_keys', which is used for some checks
+def parse_known_keys():
+ global known_keys
+ with open("srcs/juloo.keyboard2/KeyValue.java", "r") as f:
+ known_keys = set(
+ ( m.group(1) for m in re.finditer('case "([^"]+)":', f.read()) )
+ )
+
+parse_known_keys()
+
for fname in sorted(glob.glob("srcs/layouts/*.xml")):
layout_id, _ = os.path.splitext(os.path.basename(fname))
if layout_id in KNOWN_NOT_LAYOUT: