py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-07-31 19:37:20 +02:00
|
|
|
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 sys
|
|
|
|
import glob
|
2017-05-24 08:46:44 +02:00
|
|
|
import subprocess
|
2016-07-31 19:37:20 +02:00
|
|
|
|
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-07-08 06:23:33 +02:00
|
|
|
# type: (str) -> 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())
|
2017-05-24 08:46:44 +02:00
|
|
|
subprocess.call(['diff', fn, '/var/tmp/pretty_css.txt'], stderr=subprocess.STDOUT)
|
2016-07-31 19:37:20 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-03-19 03:33:05 +01:00
|
|
|
def check_our_files(filenames):
|
2017-07-08 06:23:33 +02:00
|
|
|
# type: (Iterable[str]) -> None
|
2017-03-19 03:33:05 +01:00
|
|
|
for filename in filenames:
|
2017-11-13 17:26:11 +01:00
|
|
|
if 'pygments.css' in filename:
|
|
|
|
# This just has really strange formatting that our
|
|
|
|
# parser doesn't like
|
|
|
|
continue
|
|
|
|
|
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)
|