mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
Merge pull request #2602 from mhils/simplify-version
Simplify version output
This commit is contained in:
commit
45145ed08b
@ -1,10 +0,0 @@
|
|||||||
import os
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def chdir(dir):
|
|
||||||
orig_dir = os.getcwd()
|
|
||||||
os.chdir(dir)
|
|
||||||
yield
|
|
||||||
os.chdir(orig_dir)
|
|
@ -8,60 +8,49 @@ import traceback
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from mitmproxy import version
|
from mitmproxy import version
|
||||||
from mitmproxy import utils
|
|
||||||
|
|
||||||
from OpenSSL import SSL
|
from OpenSSL import SSL
|
||||||
|
|
||||||
|
|
||||||
def dump_system_info():
|
def dump_system_info():
|
||||||
git_describe = 'release version'
|
mitmproxy_version = version.VERSION
|
||||||
with utils.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))):
|
here = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
try:
|
try:
|
||||||
c = ['git', 'describe', '--tags', '--long']
|
git_describe = subprocess.check_output(
|
||||||
git_describe = subprocess.check_output(c, stderr=subprocess.STDOUT)
|
['git', 'describe', '--tags', '--long'],
|
||||||
last_tag, tag_dist, commit = git_describe.decode().strip().rsplit("-", 2)
|
stderr=subprocess.STDOUT,
|
||||||
|
cwd=here,
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
last_tag, tag_dist, commit = git_describe.decode().strip().rsplit("-", 2)
|
||||||
|
|
||||||
if last_tag.startswith('v'):
|
commit = commit.lstrip("g") # remove the 'g' prefix added by recent git versions
|
||||||
# remove the 'v' prefix
|
tag_dist = int(tag_dist)
|
||||||
last_tag = last_tag[1:]
|
|
||||||
if commit.startswith('g'):
|
|
||||||
# remove the 'g' prefix added by recent git versions
|
|
||||||
commit = commit[1:]
|
|
||||||
|
|
||||||
# build the same version specifier as used for snapshots by rtool
|
if tag_dist > 0:
|
||||||
git_describe = "{version}dev{tag:04}-0x{commit}".format(
|
tag_dist = "dev{:04}".format(tag_dist)
|
||||||
version=last_tag,
|
else:
|
||||||
tag=int(tag_dist),
|
tag_dist = ""
|
||||||
commit=commit,
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
bin_indicator = "" # PyInstaller builds indicator, if using precompiled binary
|
mitmproxy_version += "{tag_dist} ({commit})".format(
|
||||||
|
tag_dist=tag_dist,
|
||||||
|
commit=commit,
|
||||||
|
)
|
||||||
|
|
||||||
|
# PyInstaller builds indicator, if using precompiled binary
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
bin_indicator = "Precompiled Binary"
|
bin_indicator = "binary"
|
||||||
|
else:
|
||||||
|
bin_indicator = ""
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
"Mitmproxy version: {} ({}) {}".format(version.VERSION, git_describe, bin_indicator),
|
"Mitmproxy: {} {}".format(mitmproxy_version, bin_indicator),
|
||||||
"Python version: {}".format(platform.python_version()),
|
"Python: {}".format(platform.python_version()),
|
||||||
"Platform: {}".format(platform.platform()),
|
"OpenSSL: {}".format(SSL.SSLeay_version(SSL.SSLEAY_VERSION).decode()),
|
||||||
"SSL version: {}".format(SSL.SSLeay_version(SSL.SSLEAY_VERSION).decode()),
|
"Platform: {}".format(platform.platform()),
|
||||||
]
|
]
|
||||||
d = platform.linux_distribution()
|
|
||||||
t = "Linux distro: %s %s %s" % d
|
|
||||||
if d[0]: # pragma: no cover
|
|
||||||
data.append(t)
|
|
||||||
|
|
||||||
d = platform.mac_ver()
|
|
||||||
t = "Mac version: %s %s %s" % d
|
|
||||||
if d[0]: # pragma: no cover
|
|
||||||
data.append(t)
|
|
||||||
|
|
||||||
d = platform.win32_ver()
|
|
||||||
t = "Windows version: %s %s %s %s" % d
|
|
||||||
if d[0]: # pragma: no cover
|
|
||||||
data.append(t)
|
|
||||||
|
|
||||||
return "\n".join(data)
|
return "\n".join(data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,13 +11,19 @@ from mitmproxy.utils import debug
|
|||||||
def test_dump_system_info_precompiled(precompiled):
|
def test_dump_system_info_precompiled(precompiled):
|
||||||
sys.frozen = None
|
sys.frozen = None
|
||||||
with mock.patch.object(sys, 'frozen', precompiled):
|
with mock.patch.object(sys, 'frozen', precompiled):
|
||||||
assert ("Precompiled Binary" in debug.dump_system_info()) == precompiled
|
assert ("binary" in debug.dump_system_info()) == precompiled
|
||||||
|
|
||||||
|
|
||||||
def test_dump_system_info_version():
|
def test_dump_system_info_version():
|
||||||
|
with mock.patch('subprocess.check_output') as m:
|
||||||
|
m.return_value = b"v2.0.0-0-cafecafe"
|
||||||
|
x = debug.dump_system_info()
|
||||||
|
assert 'dev' not in x
|
||||||
|
assert 'cafecafe' in x
|
||||||
|
|
||||||
with mock.patch('subprocess.check_output') as m:
|
with mock.patch('subprocess.check_output') as m:
|
||||||
m.side_effect = subprocess.CalledProcessError(-1, 'git describe --tags --long')
|
m.side_effect = subprocess.CalledProcessError(-1, 'git describe --tags --long')
|
||||||
assert 'release version' in debug.dump_system_info()
|
assert 'dev' not in debug.dump_system_info()
|
||||||
|
|
||||||
|
|
||||||
def test_dump_info():
|
def test_dump_info():
|
||||||
|
Loading…
Reference in New Issue
Block a user