abouttreesummaryrefslogcommitdiff
path: root/gen_layouts.py
diff options
context:
space:
mode:
authorJules Aguillon2024-01-21 16:34:49 +0100
committerJules Aguillon2024-01-21 16:34:49 +0100
commitad7314a01684185f5cf33cc31ef35d1027776a88 (patch)
tree189c2f9c8e085335689dfe30cb907cea5ba5c08e /gen_layouts.py
parentbef29da3dee4aadc1f2c199cea846502e14aca5b (diff)
downloadunexpected-keyboard-ad7314a01684185f5cf33cc31ef35d1027776a88.tar.gz
unexpected-keyboard-ad7314a01684185f5cf33cc31ef35d1027776a88.zip
Move layout definitions into srcs/layouts
This separates the layout definitions from the special layouts (bottom_row, greekmath) and other unrelated files (method, settings). This is also a more intuitive location for layouts and make the resource directory easier to navigate. Under the hood, layouts are copied back into build/generated-resources/xml.
Diffstat (limited to 'gen_layouts.py')
-rw-r--r--gen_layouts.py13
1 files changed, 3 insertions, 10 deletions
diff --git a/gen_layouts.py b/gen_layouts.py
index c2e6e8d..4b8ac59 100644
--- a/gen_layouts.py
+++ b/gen_layouts.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Generates the list of layouts in res/values/layouts.xml from the layout files
-# in res/xml. Every layouts must have a 'name' attribute to be listed.
+# in srcs/layouts. Every layouts must have a 'name' attribute to be listed.
import itertools as it
import sys, os, glob
@@ -11,11 +11,6 @@ import xml.etree.ElementTree as XML
# are sorted alphabetically.
FIRST_LAYOUTS = [ "latn_qwerty_us", "latn_colemak", "latn_dvorak" ]
-# File names that are known not to be layouts. Avoid warning about them.
-KNOWN_NOT_LAYOUT = set([
- "number_row", "numpad", "pin", "bottom_row", "settings", "method",
- "greekmath", "numeric" ])
-
# Read a layout from a file. Returns [None] if [fname] is not a layout.
def read_layout(fname):
root = XML.parse(fname).getroot()
@@ -28,9 +23,7 @@ def read_layouts(files):
for layout_file in files:
layout_id, _ = os.path.splitext(os.path.basename(layout_file))
layout = read_layout(layout_file)
- if layout_id in KNOWN_NOT_LAYOUT:
- continue
- elif layout == None:
+ if layout == None:
print("Not a layout file: %s" % layout_file)
elif layout["name"] == None:
print("Layout doesn't have a name: %s" % layout_id)
@@ -66,6 +59,6 @@ def generate_arrays(out, layouts):
XML.indent(root)
XML.ElementTree(element=root).write(out, encoding="unicode", xml_declaration=True)
-layouts = sort_layouts(read_layouts(glob.glob("res/xml/*.xml")))
+layouts = sort_layouts(read_layouts(glob.glob("srcs/layouts/*.xml")))
with open("res/values/layouts.xml", "w") as out:
generate_arrays(out, layouts)