Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach entire class object instead of entry func #429

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/gallia/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def build_cli(
epilog=cls.EPILOG,
)
cmd = cls(subparser, config)
subparser.set_defaults(run_func=cmd.entry_point)
subparser.set_defaults(cls_object=cmd)


def cmd_show_config(
Expand Down Expand Up @@ -361,16 +361,13 @@ def cmd_template(args: argparse.Namespace) -> None:
print(template.strip())


def main() -> None:
def build_parser() -> tuple[argparse.ArgumentParser, Config, Path | None]:
registry = cmd_registry[:]

plugin_cmds = load_command_plugins()
if len(plugin_cmds) > 0:
registry += plugin_cmds

# Will be set to the correct verbosity later.
setup_logging()

parsers = load_parsers()

# Load plugins.
Expand All @@ -386,9 +383,17 @@ def main() -> None:
build_cli(parsers, config, registry)

parser = parsers["parser"]
return parser, config, config_path


def main() -> None:
parser, config, config_path = build_parser()
argcomplete.autocomplete(parser)
args = parser.parse_args()

# Will be set to the correct verbosity later.
setup_logging()

if args.show_config:
cmd_show_config(args, config, config_path)
sys.exit(exitcode.OK)
Expand All @@ -409,11 +414,11 @@ def main() -> None:
cmd_template(args)
sys.exit(exitcode.OK)

if not hasattr(args, "run_func"):
if not hasattr(args, "cls_object"):
args.help_func()
parser.exit(exitcode.USAGE)

sys.exit(args.run_func(args))
sys.exit(args.cls_object.entry_point(args))


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions src/gallia/commands/primitive/uds/read_by_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ async def main(self, args: Namespace) -> None:
data = resp.data_record
self.logger.info(f"hex: {data.hex()}")
self.logger.info(f"raw: {repr(data)}")
self.logger.result(
f"{self.ecu.transport.target} responds to {args.data_id:#06x} with {data.hex()}"
)
self.result = data
2 changes: 2 additions & 0 deletions src/gallia/commands/scan/uds/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def configure_parser(self) -> None:
)

async def main(self, args: Namespace) -> None:
self.result: list[tuple[int, int]] = []
self.ecu.max_retry = 1
found: dict[int, dict[int, Any]] = {}

Expand Down Expand Up @@ -170,6 +171,7 @@ async def main(self, args: Namespace) -> None:
for key, value in found.items():
self.logger.result(f"findings in session 0x{key:02X}:")
for sid, data in value.items():
self.result.append((key, sid))
try:
self.logger.result(
f" [{g_repr(sid)}] {UDSIsoServices(sid).name}: {data}"
Expand Down
2 changes: 2 additions & 0 deletions src/gallia/commands/scan/uds/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async def recover_stack(self, stack: list[int], use_hooks: bool) -> bool:
return True

async def main(self, args: Namespace) -> None:
self.result: list[int] = []
found: dict[int, list[list[int]]] = {0: [[0x01]]}
positive_results: list[dict[str, Any]] = []
negative_results: list[dict[str, Any]] = []
Expand Down Expand Up @@ -237,6 +238,7 @@ async def main(self, args: Namespace) -> None:

if session != previous_session:
previous_session = session
self.result.append(int(session))
self.logger.result(f"* Session {g_repr(session)} ")

if self.db_handler is not None:
Expand Down
Loading