aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hydrilla/mitmproxy_launcher/launch.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/hydrilla/mitmproxy_launcher/launch.py b/src/hydrilla/mitmproxy_launcher/launch.py
index 8133413..e197ad5 100644
--- a/src/hydrilla/mitmproxy_launcher/launch.py
+++ b/src/hydrilla/mitmproxy_launcher/launch.py
@@ -37,12 +37,18 @@ import os
import subprocess as sp
from pathlib import Path
+# The following import requires at least Python 3.8. There is no point adding
+# a workaround for Python 3.7 because mitmproxy itself (which we're loading
+# here) relies on Python 3.9+. This does not affect the Hydrilla server and
+# builder which continue to work under Python 3.7.
+from importlib.metadata import distribution
import click
from .. import _version
from ..translations import smart_gettext as _
+
addon_script_text = '''
from hydrilla.proxy.addon import HaketiloAddon
@@ -70,12 +76,19 @@ def launch(port: int, directory: str):
script_path.write_text(addon_script_text)
- code = sp.call(['mitmdump',
- '-p', str(port),
- '--set', f'confdir={directory_path / "mitmproxy"}',
- '--set', 'upstream_cert=false',
- '--set', 'connection_strategy=lazy',
- '--set', f'haketilo_dir={directory_path}',
- '--scripts', str(script_path)])
+ sys.argv = [
+ 'mitmdump',
+ '-p', str(port),
+ '--set', f'confdir={directory_path / "mitmproxy"}',
+ '--set', 'upstream_cert=false',
+ '--set', 'connection_strategy=lazy',
+ '--set', f'haketilo_dir={directory_path}',
+ '--scripts', str(script_path)
+ ]
+
+ for entry_point in distribution('mitmproxy').entry_points:
+ if entry_point.group == 'console_scripts' and \
+ entry_point.name == 'mitmdump':
+ sys.exit(entry_point.load()())
- sys.exit(code)
+ sys.exit(1)