provide git information with --version

fixes #1848
This commit is contained in:
Thomas Kriechbaumer 2017-01-19 14:00:50 +01:00
parent ea20bfb233
commit 72b753c60f
12 changed files with 42 additions and 33 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ bower_components
*.map
sslkeylogfile.log
.tox/
.python-version

View File

@ -140,7 +140,7 @@ If you would like to install mitmproxy directly from the master branch on GitHub
or would like to get set up to contribute to the project, install the
dependencies as you would for a regular installation from source. Then see the
Hacking_ section of the README on GitHub. You can check your system information
by running: ``mitmproxy --sysinfo``
by running: ``mitmproxy --version``
.. _Hacking: https://github.com/mitmproxy/mitmproxy/blob/master/README.rst#hacking

View File

@ -13,7 +13,7 @@
<!--
Cut and paste the output of "mitmdump --sysinfo".
Cut and paste the output of "mitmproxy --version".
If you're using an older version if mitmproxy, please specify the version
and OS.

View File

@ -19,14 +19,6 @@ def treader(bytes):
return tcp.Reader(fp)
@contextmanager
def chdir(dir):
orig_dir = os.getcwd()
os.chdir(dir)
yield
os.chdir(orig_dir)
@contextmanager
def tmpdir(*args, **kwargs):
orig_workdir = os.getcwd()

View File

@ -275,13 +275,8 @@ def get_common_options(args):
def basic_options(parser):
parser.add_argument(
'--version',
action='version',
version="%(prog)s" + " " + version.VERSION
)
parser.add_argument(
'--sysinfo',
action='store_true',
dest='sysinfo',
dest='version',
)
parser.add_argument(
'--shortversion',

View File

@ -35,9 +35,10 @@ def assert_utf8_env():
def process_options(parser, options, args):
if args.sysinfo:
print(debug.sysinfo())
if args.version:
print(debug.dump_system_info())
sys.exit(0)
debug.register_info_dumpers()
pconf = config.ProxyConfig(options)
if options.no_server:

View File

@ -0,0 +1,10 @@
import os
from contextlib import contextmanager
@contextmanager
def chdir(dir):
orig_dir = os.getcwd()
os.chdir(dir)
yield
os.chdir(orig_dir)

View File

@ -1,5 +1,3 @@
def setbit(byte, offset, value):
"""
Set a bit in a byte to 1 if value is truthy, 0 if not.

View File

@ -5,18 +5,29 @@ import threading
import signal
import platform
import traceback
import subprocess
from mitmproxy import version
from mitmproxy import utils
from OpenSSL import SSL
def sysinfo():
def dump_system_info():
git_describe = 'release version'
with utils.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))):
try:
c = ['git', 'describe', '--tags', '--long']
git_describe = subprocess.check_output(c, stderr=subprocess.STDOUT)
git_describe = git_describe.decode().strip()
except:
pass
data = [
"Mitmproxy version: %s" % version.VERSION,
"Python version: %s" % platform.python_version(),
"Platform: %s" % platform.platform(),
"SSL version: %s" % SSL.SSLeay_version(SSL.SSLEAY_VERSION).decode(),
"Mitmproxy version: {} ({})".format(version.VERSION, git_describe),
"Python version: {}".format(platform.python_version()),
"Platform: {}".format(platform.platform()),
"SSL version: {}".format(SSL.SSLeay_version(SSL.SSLEAY_VERSION).decode()),
]
d = platform.linux_distribution()
t = "Linux distro: %s %s %s" % d

View File

@ -10,6 +10,7 @@ from mitmproxy import exceptions
from mitmproxy import options
from mitmproxy import proxy
from mitmproxy import master
from mitmproxy import utils
from mitmproxy.addons import script
@ -72,7 +73,7 @@ class TestParseCommand:
script.parse_command(dir)
def test_parse_args(self):
with tutils.chdir(tutils.test_data.dirname):
with utils.chdir(tutils.test_data.dirname):
assert script.parse_command(
"mitmproxy/data/addonscripts/recorder.py"
) == ("mitmproxy/data/addonscripts/recorder.py", [])
@ -85,7 +86,7 @@ class TestParseCommand:
@ttutils.skip_not_windows
def test_parse_windows(self):
with tutils.chdir(tutils.test_data.dirname):
with utils.chdir(tutils.test_data.dirname):
assert script.parse_command(
"mitmproxy/data\\addonscripts\\recorder.py"
) == ("mitmproxy/data\\addonscripts\\recorder.py", [])

View File

@ -3,6 +3,10 @@ import io
from mitmproxy.utils import debug
def test_dump_system_info():
assert debug.dump_system_info()
def test_dump_info():
cs = io.StringIO()
debug.dump_info(None, None, file=cs, testing=True)
@ -15,9 +19,5 @@ def test_dump_stacks():
assert cs.getvalue()
def test_sysinfo():
assert debug.sysinfo()
def test_register_info_dumpers():
debug.register_info_dumpers()

View File

@ -10,7 +10,7 @@ deps =
passenv = CODECOV_TOKEN CI CI_* TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* SNAPSHOT_* OPENSSL_* RTOOL_*
setenv = HOME = {envtmpdir}
commands =
mitmdump --sysinfo
mitmdump --version
py.test --timeout 60 {posargs}
{env:CI_COMMANDS:python -c ""}
@ -20,7 +20,7 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
[testenv:lint]
commands =
mitmdump --sysinfo
mitmdump --version
flake8 --jobs 8 --count mitmproxy pathod examples test release
rstcheck README.rst
mypy --silent-imports \