Moved confdir check logic into the addon

This commit is contained in:
Henrique 2019-11-25 08:56:44 -05:00
parent 6a7f27ff15
commit 0d29804ab8
2 changed files with 7 additions and 13 deletions

View File

@ -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()

View File

@ -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"),