summaryrefslogtreecommitdiff
path: root/Meta/lint-keymaps.py
diff options
context:
space:
mode:
authorBrendan Coles <bcoles@gmail.com>2021-04-02 09:26:37 +0000
committerAndreas Kling <kling@serenityos.org>2021-04-02 23:07:58 +0200
commit666aeecaa2c9ec252e0c6d725bf06eee3cf2be5c (patch)
tree5b1a7daa223b412efc1a814eca81306c33004401 /Meta/lint-keymaps.py
parente875513ff7e34be086d6d8f3c8d77a2f208660f2 (diff)
downloadserenity-666aeecaa2c9ec252e0c6d725bf06eee3cf2be5c.zip
Meta: Resolve some pylint violations in Python lint scripts
Resolves: * all: consider-using-sys-exit * all: wrong-import-order * all: TODO: Require that a few keys are set? (fixme) * some: missing-function-docstring * some: line-too-long
Diffstat (limited to 'Meta/lint-keymaps.py')
-rwxr-xr-xMeta/lint-keymaps.py56
1 files changed, 53 insertions, 3 deletions
diff --git a/Meta/lint-keymaps.py b/Meta/lint-keymaps.py
index 9b2f9b7a7d..a22258c0ce 100755
--- a/Meta/lint-keymaps.py
+++ b/Meta/lint-keymaps.py
@@ -2,7 +2,7 @@
import json
import os
-
+import sys
PERMITTED_MAPS = ['map', 'shift_map', 'alt_map', 'altgr_map', 'shift_altgr_map']
REQUIRED_MAPS = ['map', 'shift_map', 'alt_map']
@@ -12,10 +12,27 @@ GOOD_MAP_LENGTHS = {90, 128}
def report(filename, problem):
+ """Print a lint problem to stdout.
+
+ Args:
+ filename (str): keymap file name
+ problem (str): problem message
+ """
print('{}: {}'.format(filename, problem))
def validate_single_map(filename, mapname, values):
+ """Validate a key map.
+
+ Args:
+ filename (str): keymap file name
+ mapname (str): map name (altgr_map, alt_map, shift_altgr_map)
+ values (list): key values
+
+ Returns:
+ bool: key map is valid
+ """
+
all_good = True
if not isinstance(values, list):
@@ -31,7 +48,9 @@ def validate_single_map(filename, mapname, values):
report(filename, 'more than one character ("{}") for charmap index {} of {}'.format(c, i, mapname))
all_good = False
- # TODO: Require that a few keys are set?
+ if len(values) == 0:
+ report(filename, 'map {} is empty.'.format(mapname))
+ all_good = False
if len(values) not in GOOD_MAP_LENGTHS:
report(filename, 'length {} of map {} is suspicious. Off-by-one?'.format(len(values), mapname))
@@ -41,6 +60,16 @@ def validate_single_map(filename, mapname, values):
def validate_fullmap(filename, fullmap):
+ """Validate a full key map for all map names (including maps for key modifiers).
+
+ Args:
+ filename (str): keymap file name
+ fullmap (dict): key mappings
+
+ Returns:
+ bool: keymap file contains valid key mappings
+ """
+
all_good = True
if not isinstance(fullmap, dict):
@@ -73,6 +102,15 @@ def validate_fullmap(filename, fullmap):
def run_with(filenames):
+ """Check list of keymap files for errors.
+
+ Args:
+ filenames (list): keymap files to check
+
+ Returns:
+ bool: All keymap files are valid
+ """
+
passed = 0
for filename in filenames:
with open(filename, 'r') as fp:
@@ -85,6 +123,12 @@ def run_with(filenames):
def list_files_here():
+ """Retrieve a list of all '.json' files in the working directory.
+
+ Returns:
+ list: JSON file names
+ """
+
filelist = []
for filename in os.listdir():
if filename.endswith('.json'):
@@ -98,10 +142,16 @@ def list_files_here():
def run_here():
+ """Check all keymap files in the working directory for errors.
+
+ Returns:
+ bool: All keymap files are valid
+ """
+
return run_with(list_files_here())
if __name__ == '__main__':
os.chdir(os.path.dirname(__file__) + "/../Base/res/keymaps/")
if not run_here():
- exit(1)
+ sys.exit(1)