-
Notifications
You must be signed in to change notification settings - Fork 38
/
pwc.py
executable file
·36 lines (26 loc) · 961 Bytes
/
pwc.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
#!python3
# This little helper script was implemented to extract the sources from the spellcheck configuration file
# The name pwc comes from Python WCMatch, which is used to match the files against the sources
# That is the short name I call it PriceWaterhouseCoopers, since it revises the file listing
# read file and interpret it as yaml
def read_yaml(file):
with open(file) as f:
data = yaml.safe_load(f)
return data
import sys
import yaml
from wcmatch import glob
# read filename from command line as first argument
spellcheck_configuration_file = sys.argv[1]
data = read_yaml(spellcheck_configuration_file)
# fetch the sources from the YAML data
sources = data.get('matrix')[0].get('sources')
for changed_file in sys.stdin:
if 'q' == changed_file.rstrip():
break
changed_file = changed_file.rstrip()
matched = glob.globmatch(changed_file, sources, flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)
if matched:
exit(0)
else:
exit(1)