1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 07:54:58 +00:00

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
This commit is contained in:
Brendan Coles 2021-04-02 09:26:37 +00:00 committed by Andreas Kling
parent e875513ff7
commit 666aeecaa2
4 changed files with 140 additions and 54 deletions

View file

@ -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)