-
Notifications
You must be signed in to change notification settings - Fork 35
/
check-config.py
executable file
·75 lines (66 loc) · 2.55 KB
/
check-config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
import json
import os
import fnmatch
import re
import sys
IGNORE_ENTRIES = [
'latex-workshop-dev.*',
'latex-workshop.structure-toggle-follow-cursor',
'latex-workshop.citation',
'latex-workshop.setViewer',
'latex-workshop.log',
'latex-workshop.synctex',
'latex-workshop.tab'
]
def get_from_package(pkgfile):
with open(pkgfile, 'r', encoding='utf8') as fp:
package_file_content = json.load(fp)
all_variables = package_file_content['contributes']['configuration']['properties']
variables = {}
for key in all_variables.keys():
entry = all_variables[key]
subkeys = entry.keys()
if 'deprecationMessage' not in subkeys and 'markdownDeprecationMessage' not in subkeys:
variables[key] = entry
commands = package_file_content['contributes']['commands']
variable_names = set(variables.keys())
commands_names = set([e['command'] for e in commands])
return (variable_names, commands_names)
def get_variables_from_wiki():
variables = set()
for dirpath, _, filenames in os.walk('.'):
for f in filenames:
filepath = os.path.join(dirpath, f)
(_, ext) = os.path.splitext(filepath)
if ext != '.md':
continue
with open(f, 'r', encoding='utf8') as fp:
content = fp.read()
for match in re.finditer(r'latex-workshop(\.[a-zA-Z-]+)+', content):
if match:
variables.add(match.group(0))
return variables
def print_if_not_ignored(s):
"""
Print s if it is not in the list IGNORE_ENTRIES
"""
if any(fnmatch.fnmatch(e, pat) for pat in IGNORE_ENTRIES):
return
print(s)
if __name__ == "__main__":
if len(sys.argv) != 2 or sys.argv[1] == '-h':
print("Usage: check-config.py LW-package.json")
sys.exit(0)
vars_package, commands_package = get_from_package(sys.argv[1])
vars_wiki = get_variables_from_wiki()
print('--> Variables in package.json but not in the wiki:')
for e in sorted(vars_package.difference(vars_wiki)):
print_if_not_ignored("\t" + e)
print('--> Commands in package.json but not in the wiki:')
for e in sorted(commands_package.difference(vars_wiki)):
print_if_not_ignored("\t" + e)
print('--> Variables/commands in the wiki but not in package.json:')
all_package = commands_package.union(vars_package)
for e in sorted(vars_wiki.difference(all_package)):
print_if_not_ignored("\t" + e)