forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-css
executable file
·51 lines (45 loc) · 1.56 KB
/
check-css
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
#!/usr/bin/env python3
from lib.css_parser import parse, CssParserException
from typing import Iterable, Text
import sys
import glob
import subprocess
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
def validate(fn):
# type: (str) -> None
text = open(fn).read()
section_list = parse(text)
if text != section_list.text():
sys.stderr.write('''
FAIL: {} is being rejected by our finicky linter)
(you can manually apply the diff to fix)\n\n'''.format(fn,))
sys.stderr.flush()
open('/var/tmp/pretty_css.txt', 'w').write(section_list.text())
subprocess.call(['diff', '-u', fn, '/var/tmp/pretty_css.txt'], stderr=subprocess.STDOUT)
sys.exit(1)
def check_our_files(filenames):
# type: (Iterable[str]) -> None
for filename in filenames:
if 'pygments.css' in filename:
# This just has really strange formatting that our
# parser doesn't like
continue
try:
validate(filename)
except CssParserException as e:
msg = '''
ERROR! Some CSS seems to be misformatted.
{}
See line {} in file {}
'''.format(e.msg, e.token.line, filename)
print(msg)
sys.exit(1)
if __name__ == '__main__':
# If command arguments are provided, we only check those filenames.
# Otherwise, we check all possible filenames.
filenames = sys.argv[1:]
if not filenames:
filenames = glob.glob('static/styles/*.css')
check_our_files(filenames)