From f4ea358ff01eea172125cda165612a4c15cbbfee Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 19 Oct 2022 10:21:14 +0200 Subject: [proxy] instead of writing addon.py under Haketilo state directory, include the script in package data files --- src/hydrilla/mitmproxy_launcher/addon_script.py.mitmproxy | 9 +++++++++ src/hydrilla/mitmproxy_launcher/launch.py | 15 ++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 src/hydrilla/mitmproxy_launcher/addon_script.py.mitmproxy diff --git a/src/hydrilla/mitmproxy_launcher/addon_script.py.mitmproxy b/src/hydrilla/mitmproxy_launcher/addon_script.py.mitmproxy new file mode 100644 index 0000000..fe853d1 --- /dev/null +++ b/src/hydrilla/mitmproxy_launcher/addon_script.py.mitmproxy @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: CC0-1.0 + +# Copyright (C) 2022 Wojtek Kosior +# +# Available under the terms of Creative Commons Zero v1.0 Universal. + +from hydrilla.proxy.addon import HaketiloAddon + +addons = [HaketiloAddon()] diff --git a/src/hydrilla/mitmproxy_launcher/launch.py b/src/hydrilla/mitmproxy_launcher/launch.py index 2f706fd..3b7749d 100644 --- a/src/hydrilla/mitmproxy_launcher/launch.py +++ b/src/hydrilla/mitmproxy_launcher/launch.py @@ -45,16 +45,13 @@ from .. import _version from ..translations import smart_gettext as _ +here = Path(__file__).resolve().parent + + xdg_state_home = os.environ.get('XDG_STATE_HOME', '.local/state') default_dir = str(Path.home() / xdg_state_home / 'haketilo') old_default_dir_path = Path.home() / '.haketilo/' -addon_script_text = ''' -from hydrilla.proxy.addon import HaketiloAddon - -addons = [HaketiloAddon()] -''' - @click.command(help=_('cli_help.haketilo')) @click.option('-l', '--listen-host', default='127.0.0.1', type=click.STRING, help=_('cli_opt.haketilo.listen_host')) @@ -83,10 +80,6 @@ def launch(listen_host: str, port: int, launch_browser: bool, directory: str) \ directory_path.mkdir(parents=True, exist_ok=True) - script_path = directory_path / 'addon.py' - - script_path.write_text(addon_script_text) - launch_browser_str = 'true' if launch_browser else 'false' sys.argv = [ @@ -100,7 +93,7 @@ def launch(listen_host: str, port: int, launch_browser: bool, directory: str) \ '--set', f'haketilo_listen_host={listen_host}', '--set', f'haketilo_listen_port={port}', '--set', f'haketilo_launch_browser={launch_browser_str}', - '--scripts', str(script_path) + '--scripts', str(here / 'addon_script.py.mitmproxy') ] for entry_point in distribution('mitmproxy').entry_points: -- cgit v1.2.3