Skip to content

Commit

Permalink
provide git information with --version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriechi committed Jan 19, 2017
1 parent ea20bfb commit 72b753c
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ bower_components
*.map
sslkeylogfile.log
.tox/
.python-version
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions mitmproxy/test/tutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions mitmproxy/tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions mitmproxy/tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions mitmproxy/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 0 additions & 2 deletions mitmproxy/utils/bits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


def setbit(byte, offset, value):
"""
Set a bit in a byte to 1 if value is truthy, 0 if not.
Expand Down
21 changes: 16 additions & 5 deletions mitmproxy/utils/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@
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
Expand Down
5 changes: 3 additions & 2 deletions test/mitmproxy/addons/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from mitmproxy import options
from mitmproxy import proxy
from mitmproxy import master
from mitmproxy import utils

from mitmproxy.addons import script

Expand Down Expand Up @@ -72,7 +73,7 @@ def test_no_script_file(self):
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", [])
Expand All @@ -85,7 +86,7 @@ def test_parse_args(self):

@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", [])
Expand Down
8 changes: 4 additions & 4 deletions test/mitmproxy/utils/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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)
Expand All @@ -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()
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""}

Expand All @@ -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 \
Expand Down

0 comments on commit 72b753c

Please sign in to comment.