aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorHenrique <typoon@gmail.com>2019-11-25 08:56:44 -0500
committerHenrique <typoon@gmail.com>2019-11-25 08:56:44 -0500
commit0d29804ab852893e4e41c415de1ce3cc08ffcfae (patch)
tree45661a56df0b2845d6d38b96e579a1f804b1cb76 /mitmproxy
parent6a7f27ff152fc05f9bbe847625e92dc1ecad3653 (diff)
downloadmitmproxy-0d29804ab852893e4e41c415de1ce3cc08ffcfae.tar.gz
mitmproxy-0d29804ab852893e4e41c415de1ce3cc08ffcfae.tar.bz2
mitmproxy-0d29804ab852893e4e41c415de1ce3cc08ffcfae.zip
Moved confdir check logic into the addon
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/addons/command_history.py6
-rw-r--r--mitmproxy/tools/_main.py14
2 files changed, 7 insertions, 13 deletions
diff --git a/mitmproxy/addons/command_history.py b/mitmproxy/addons/command_history.py
index 3df2fe5d..c66af2be 100644
--- a/mitmproxy/addons/command_history.py
+++ b/mitmproxy/addons/command_history.py
@@ -14,7 +14,11 @@ class CommandHistory:
self.current_index: int = -1
self.filter_str: str = ''
- _command_history_path = os.path.join(os.path.expanduser(ctx.options.confdir), 'command_history')
+ _command_history_dir = os.path.expanduser(ctx.options.confdir)
+ if not os.path.exists(_command_history_dir):
+ os.makedirs(_command_history_dir)
+
+ _command_history_path = os.path.join(_command_history_dir, 'command_history')
_history_lines: typing.List[str] = []
if os.path.exists(_command_history_path):
_history_lines = open(_command_history_path, 'r').readlines()
diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/_main.py
index 3e6933b9..77f8e675 100644
--- a/mitmproxy/tools/_main.py
+++ b/mitmproxy/tools/_main.py
@@ -69,6 +69,7 @@ def run(
debug.register_info_dumpers()
opts = options.Options()
+ master = master_cls(opts)
parser = make_parser(opts)
try:
@@ -77,24 +78,13 @@ def run(
arg_check.check()
sys.exit(1)
- try:
- opts.set(*args.setoptions, defer=True)
- opts.confdir = os.path.expanduser(opts.confdir)
- if not os.path.isdir(opts.confdir):
- os.makedirs(opts.confdir)
-
- except exceptions.OptionsError as e:
- print("%s: %s" % (sys.argv[0], e), file=sys.stderr)
- sys.exit(1)
-
- master = master_cls(opts)
-
# To make migration from 2.x to 3.0 bearable.
if "-R" in sys.argv and sys.argv[sys.argv.index("-R") + 1].startswith("http"):
print("-R is used for specifying replacements.\n"
"To use mitmproxy in reverse mode please use --mode reverse:SPEC instead")
try:
+ opts.set(*args.setoptions, defer=True)
optmanager.load_paths(
opts,
os.path.join(opts.confdir, "config.yaml"),