|
| 1 | +# Check shortcuts |
| 2 | +# Copyright (C) 2023 Cyrille Bougot |
| 3 | +# This file is covered by the GNU General Public License. |
| 4 | + |
| 5 | +"""A script to check NVDA's shortcuts between doc and code. |
| 6 | +This script list all the shortcuts defined in NVDA's code which are not listed in NVDA's user guide. |
| 7 | +""" |
| 8 | + |
| 9 | +import os |
| 10 | +import re |
| 11 | + |
| 12 | +# locale folder |
| 13 | +pathRoot = os.path.join( |
| 14 | + os.getenv('homepath'), |
| 15 | + r"Documents\DevP\GIT\nvda", |
| 16 | +) |
| 17 | +pathSource = os.path.join(pathRoot, 'source') |
| 18 | +pathDoc = os.path.join(pathRoot, 'user_docs', 'en', 'userGuide.t2t') |
| 19 | + |
| 20 | +def pythonFilesGenerator(pathRoot): |
| 21 | + for path, folders, files in os.walk(pathRoot): |
| 22 | + for name in files: |
| 23 | + if not (name.endswith('.py') or name.endswith('.pyw')): |
| 24 | + continue |
| 25 | + yield os.path.join(path, name) |
| 26 | + |
| 27 | +RE_SHORTCUT = r'(?:(?:nvda|alt|control|shift|windows)\+)+[a-z0-9]+' |
| 28 | +RE_SHORTCUT_IN_CODE = r'kb(?:\(\desktop|laptop\))?:' + RE_SHORTCUT |
| 29 | +REC_SHORTCUT = re.compile(RE_SHORTCUT, re.I) |
| 30 | +REC_SHORTCUT_IN_CODE = re.compile(RE_SHORTCUT_IN_CODE, re.I) |
| 31 | + |
| 32 | + |
| 33 | +def getSourceShortcuts(path): |
| 34 | + shortcuts = set() |
| 35 | + for file in pythonFilesGenerator(path): |
| 36 | + shortcuts.update(getSourceShortcutsInFile(file, inCode=True)) |
| 37 | + return shortcuts |
| 38 | + |
| 39 | +def getSourceShortcutsInFile(path, inCode): |
| 40 | + shortcuts = set() |
| 41 | + with open(path, 'r', encoding='utf8') as f: |
| 42 | + for line in f: |
| 43 | + line = line.lower().strip() |
| 44 | + if line.startswith('#'): |
| 45 | + continue |
| 46 | + recShortcut = REC_SHORTCUT_IN_CODE if inCode else REC_SHORTCUT |
| 47 | + shortcuts.update(recShortcut.findall(line)) |
| 48 | + return shortcuts |
| 49 | + |
| 50 | + |
| 51 | +shortcutsInSource = getSourceShortcuts(pathSource) |
| 52 | +shortcutsInDoc = getSourceShortcutsInFile(pathDoc, inCode=False) |
| 53 | + |
| 54 | +srcNotDoc = '\n'.join(sorted(shortcutsInSource - shortcutsInDoc)) |
| 55 | +print('In source, not in doc:\n{}'.format(srcNotDoc)) |
0 commit comments