-
-
Notifications
You must be signed in to change notification settings - Fork 580
/
check.py
87 lines (77 loc) · 2.87 KB
/
check.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
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
Network monitoring, controls & Application development, testing, debugging.
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import sys
import subprocess
from pathlib import Path
from proxy.common.version import __version__ as lib_version
# This script ensures our versions never run out of sync.
#
# 1. TODO: Version is hardcoded in homebrew stable package
# installer file, but it only needs to match with lib
# versions if current git branch is master
PY_FILE_PREFIX = b'# -*- coding: utf-8 -*-\n' + \
b'"""\n' + \
b' proxy.py\n' + \
b' ~~~~~~~~\n' + \
b' \xe2\x9a\xa1\xe2\x9a\xa1\xe2\x9a\xa1 Fast, Lightweight, Pluggable, TLS interception capable' + \
b' proxy server focused on\n' + \
b' Network monitoring, controls & Application development, testing, debugging.\n' + \
b'\n' + \
b' :copyright: (c) 2013-present by Abhinav Singh and contributors.\n' + \
b' :license: BSD, see LICENSE for more details.\n'
REPO_ROOT = Path(__file__).parent
ALL_PY_FILES = (
list(REPO_ROOT.glob('*.py')) +
list((REPO_ROOT / 'proxy').rglob('*.py')) +
list((REPO_ROOT / 'examples').rglob('*.py')) +
list((REPO_ROOT / 'skeleton').rglob('*.py')) +
list((REPO_ROOT / 'benchmark').rglob('*.py')) +
list((REPO_ROOT / 'tests').rglob('*.py'))
)
# Ensure all python files start with licensing information
for py_file in ALL_PY_FILES:
if py_file.is_file() and py_file.name != '_scm_version.py':
with open(py_file, 'rb') as f:
code = f.read(len(PY_FILE_PREFIX))
if code != PY_FILE_PREFIX:
print(
'Expected license not found in {0}'.format(
str(py_file),
),
)
sys.exit(1)
# Update README.md flags section to match current library --help output
lib_help = subprocess.check_output(
['python', '-m', 'proxy', '-h'],
)
with open('README.md', 'rb+') as f:
c = f.read()
pre_flags, post_flags = c.split(b'# Flags')
f.seek(0)
f.write(
pre_flags +
b'# Flags\n\n```console\n\xe2\x9d\xaf proxy -h\n' +
lib_help +
b'```\n',
)
# Version is also hardcoded in README.md flags section
readme_version_cmd = 'cat README.md | grep "proxy.py v" | tail -2 | head -1 | cut -d " " -f 2 | cut -c2-'
readme_version_output = subprocess.check_output(
['bash', '-c', readme_version_cmd],
)
# Doesn't contain "v" prefix
readme_version = readme_version_output.decode().strip()
if readme_version != lib_version:
print(
'Version mismatch found. {0} (readme) vs {1} (lib).'.format(
readme_version, lib_version,
),
)
sys.exit(1)