aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2017-01-19 14:00:50 +0100
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2017-01-19 20:27:29 +0100
commit72b753c60f7208ee536dc79bd20b3ba93563668b (patch)
tree1864d781b05ae2e564ced10659e9c425da00d209
parentea20bfb233a9cad44755417ec0a353bfab116fda (diff)
downloadmitmproxy-72b753c60f7208ee536dc79bd20b3ba93563668b.tar.gz
mitmproxy-72b753c60f7208ee536dc79bd20b3ba93563668b.tar.bz2
mitmproxy-72b753c60f7208ee536dc79bd20b3ba93563668b.zip
provide git information with --version
fixes #1848
-rw-r--r--.gitignore1
-rw-r--r--docs/install.rst2
-rw-r--r--issue_template.md2
-rw-r--r--mitmproxy/test/tutils.py8
-rw-r--r--mitmproxy/tools/cmdline.py7
-rw-r--r--mitmproxy/tools/main.py5
-rw-r--r--mitmproxy/utils/__init__.py10
-rw-r--r--mitmproxy/utils/bits.py2
-rw-r--r--mitmproxy/utils/debug.py21
-rw-r--r--test/mitmproxy/addons/test_script.py5
-rw-r--r--test/mitmproxy/utils/test_debug.py8
-rw-r--r--tox.ini4
12 files changed, 42 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index 91caf620..f1a481cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,4 @@ bower_components
*.map
sslkeylogfile.log
.tox/
+.python-version
diff --git a/docs/install.rst b/docs/install.rst
index c10c1e01..bcf07023 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -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
diff --git a/issue_template.md b/issue_template.md
index fe123d44..5c5f95ed 100644
--- a/issue_template.md
+++ b/issue_template.md
@@ -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.
diff --git a/mitmproxy/test/tutils.py b/mitmproxy/test/tutils.py
index f5cec1b1..ae0ce2d8 100644
--- a/mitmproxy/test/tutils.py
+++ b/mitmproxy/test/tutils.py
@@ -20,14 +20,6 @@ def treader(bytes):
@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()
temp_workdir = tempfile.mkdtemp(*args, **kwargs)
diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py
index d0b53b2c..f607ad71 100644
--- a/mitmproxy/tools/cmdline.py
+++ b/mitmproxy/tools/cmdline.py
@@ -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',
diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py
index d07ae666..727e993f 100644
--- a/mitmproxy/tools/main.py
+++ b/mitmproxy/tools/main.py
@@ -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:
diff --git a/mitmproxy/utils/__init__.py b/mitmproxy/utils/__init__.py
index e69de29b..86649864 100644
--- a/mitmproxy/utils/__init__.py
+++ b/mitmproxy/utils/__init__.py
@@ -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)
diff --git a/mitmproxy/utils/bits.py b/mitmproxy/utils/bits.py
index ec0d40ef..2c89a999 100644
--- a/mitmproxy/utils/bits.py
+++ b/mitmproxy/utils/bits.py
@@ -1,5 +1,3 @@
-
-
def setbit(byte, offset, value):
"""
Set a bit in a byte to 1 if value is truthy, 0 if not.
diff --git a/mitmproxy/utils/debug.py b/mitmproxy/utils/debug.py
index ac8fedd7..93fefa9d 100644
--- a/mitmproxy/utils/debug.py
+++ b/mitmproxy/utils/debug.py
@@ -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
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index 777f8f4d..f6fca23e 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -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", [])
diff --git a/test/mitmproxy/utils/test_debug.py b/test/mitmproxy/utils/test_debug.py
index 9acf8192..18f5cdbc 100644
--- a/test/mitmproxy/utils/test_debug.py
+++ b/test/mitmproxy/utils/test_debug.py
@@ -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()
diff --git a/tox.ini b/tox.ini
index 85c962f7..88f9ce86 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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 \