2016-07-31 19:37:20 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
from lib.css_parser import parse, CssParserException
|
2017-03-19 03:33:05 +01:00
|
|
|
from typing import Iterable, Text
|
2016-07-31 19:37:20 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
2016-07-31 19:37:20 +02:00
|
|
|
|
|
|
|
def validate(fn):
|
2017-03-19 03:33:05 +01:00
|
|
|
# type: (Text) -> None
|
2016-07-31 19:37:20 +02:00
|
|
|
text = open(fn).read()
|
|
|
|
section_list = parse(text)
|
|
|
|
if text != section_list.text():
|
2017-03-17 12:34:45 +01:00
|
|
|
print('%s seems to be broken:' % (fn,))
|
|
|
|
open('/var/tmp/pretty_css.txt', 'w').write(section_list.text())
|
|
|
|
os.system('diff %s /var/tmp/pretty_css.txt' % (fn,))
|
2016-07-31 19:37:20 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-03-19 03:33:05 +01:00
|
|
|
def check_our_files(filenames):
|
|
|
|
# type: (Iterable[Text]) -> None
|
|
|
|
for filename in filenames:
|
2016-07-31 19:37:20 +02:00
|
|
|
try:
|
2017-03-19 03:33:05 +01:00
|
|
|
validate(filename)
|
2016-07-31 19:37:20 +02:00
|
|
|
except CssParserException as e:
|
2017-02-01 15:31:24 +01:00
|
|
|
msg = '''
|
|
|
|
ERROR! Some CSS seems to be misformatted.
|
|
|
|
{}
|
|
|
|
See line {} in file {}
|
2017-03-19 03:33:05 +01:00
|
|
|
'''.format(e.msg, e.token.line, filename)
|
2017-02-01 15:31:24 +01:00
|
|
|
print(msg)
|
2016-07-31 19:37:20 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-03-19 03:33:05 +01:00
|
|
|
# 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)
|