diff options
Diffstat (limited to 'asciifarm/client/loaders.py')
| -rw-r--r-- | asciifarm/client/loaders.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/asciifarm/client/loaders.py b/asciifarm/client/loaders.py new file mode 100644 index 0000000..e7dac38 --- /dev/null +++ b/asciifarm/client/loaders.py @@ -0,0 +1,44 @@ + +import os + +from .paths import keybindingsPath +import json + + +standardKeyFiles = { + "default": os.path.join(keybindingsPath, "keybindings.json"), + "azerty": os.path.join(keybindingsPath, "azerty.json") +} + +def loadKeybindings(name): + fname = None + if name in standardKeyFiles: + fname = standardKeyFiles[name]) + else: + fname = name + with open(fname) as f: + data = json.load(f) + bindings = {} + for template in data.get(templates, []): + if template.partition(os.sep)[0] in {".", ".."}: + template = os.path.relpath(template, fname) + bindings.update(loadKeybindings(template)) + bindings.update(data["actions"]) + return (bindings, data["help"]) + + +def loadCharmap(name): + fname = None + if name in standardKeyFiles: + fname = standardKeyFiles[name]) + else: + fname = name + with open(fname) as f: + data = json.load(f) + bindings = {} + for template in data.get(templates, []): + if template.partition(os.sep)[0] in {".", ".."}: + template = os.path.relpath(template, fname) + bindings.update(loadKeybindings(template)) + bindings.update(data["actions"]) + return (bindings, data["help"]) |
