do not create application in shell handler

The main reason for having shell handler is to be able to fix if
something (e.g. migrations) goes wrong. In this way we need to reduce
actions inside this wrapper
This commit is contained in:
Evgenii Alekseev 2023-07-28 03:06:28 +03:00
parent 263c53bac5
commit 5904727da2
2 changed files with 4 additions and 8 deletions

View File

@ -904,8 +904,7 @@ def _set_service_shell_parser(root: SubParserAction) -> argparse.ArgumentParser:
argparse.ArgumentParser: created argument parser argparse.ArgumentParser: created argument parser
""" """
parser = root.add_parser("service-shell", aliases=["shell"], help="invoke python shell", parser = root.add_parser("service-shell", aliases=["shell"], help="invoke python shell",
description="drop into python shell while having created application", description="drop into python shell", formatter_class=_formatter)
formatter_class=_formatter)
parser.add_argument("code", help="instead of dropping into shell, just execute the specified code", nargs="?") parser.add_argument("code", help="instead of dropping into shell, just execute the specified code", nargs="?")
parser.add_argument("-v", "--verbose", help=argparse.SUPPRESS, action="store_true") parser.add_argument("-v", "--verbose", help=argparse.SUPPRESS, action="store_true")
parser.set_defaults(handler=handlers.Shell, lock=None, report=False) parser.set_defaults(handler=handlers.Shell, lock=None, report=False)

View File

@ -23,7 +23,6 @@ import sys
from pathlib import Path from pathlib import Path
from ahriman.application.application import Application
from ahriman.application.handlers import Handler from ahriman.application.handlers import Handler
from ahriman.core.configuration import Configuration from ahriman.core.configuration import Configuration
from ahriman.core.formatters import StringPrinter from ahriman.core.formatters import StringPrinter
@ -47,14 +46,12 @@ class Shell(Handler):
configuration(Configuration): configuration instance configuration(Configuration): configuration instance
report(bool): force enable or disable reporting report(bool): force enable or disable reporting
""" """
# pylint: disable=possibly-unused-variable
application = Application(architecture, configuration, report=report)
if args.verbose: if args.verbose:
# licensed by https://creativecommons.org/licenses/by-sa/3.0 # licensed by https://creativecommons.org/licenses/by-sa/3.0
path = Path(sys.prefix) / "share" / "ahriman" / "templates" / "shell" path = Path(sys.prefix) / "share" / "ahriman" / "templates" / "shell"
StringPrinter(path.read_text(encoding="utf8")).print(verbose=False) StringPrinter(path.read_text(encoding="utf8")).print(verbose=False)
# we only want to pass application instance inside local_variables = {"architecture": architecture, "configuration": configuration}
if args.code is None: if args.code is None:
code.interact(local={"application": application}) code.interact(local=local_variables)
else: else:
code.InteractiveConsole(locals={"application": application}).runcode(args.code) code.InteractiveConsole(locals=local_variables).runcode(args.code)