Skip to content

Commit

Permalink
refactor: logs.py add typing and small misc refactors (#5414)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon committed Jul 18, 2024
1 parent 6acb06c commit 6495a31
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions cloudinit/cmd/devel/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class ApportFile(NamedTuple):
]


def get_parser(parser=None):
def get_parser(
parser: Optional[argparse.ArgumentParser] = None,
) -> argparse.ArgumentParser:
"""Build or extend and arg parser for collect-logs utility.
@param parser: Optional existing ArgumentParser instance representing the
Expand Down Expand Up @@ -145,7 +147,7 @@ def get_parser(parser=None):
return parser


def _get_copytree_ignore_files(paths: LogPaths):
def _get_copytree_ignore_files(paths: LogPaths) -> List[str]:
"""Return a list of files to ignore for /run/cloud-init directory"""
ignored_files = [
"hook-hotplug-cmd", # named pipe for hotplug
Expand Down Expand Up @@ -229,8 +231,7 @@ def _collect_version_info(log_dir: str) -> None:
msg="dpkg version",
)
if not version:
version = dpkg_ver if dpkg_ver else "not-available"
LOG.debug("collected cloud-init version: %s", version)
version = dpkg_ver or "not-available"


def _collect_system_logs(log_dir: str) -> None:
Expand Down Expand Up @@ -333,7 +334,7 @@ def _setup_logger(verbosity: int) -> None:
LOG.addHandler(handler)


def handle_collect_logs_args(name, args):
def handle_collect_logs_args(_name: str, args: argparse.Namespace) -> int:
"""Handle calls to 'cloud-init collect-logs' as a subcommand."""
_setup_logger(args.verbosity)
return collect_logs(
Expand All @@ -342,11 +343,5 @@ def handle_collect_logs_args(name, args):
)


def main():
"""Tool to collect and tar all cloud-init related logs."""
parser = get_parser()
return handle_collect_logs_args("collect-logs", parser.parse_args())


if __name__ == "__main__":
sys.exit(main())
sys.exit(handle_collect_logs_args("", get_parser().parse_args()))

0 comments on commit 6495a31

Please sign in to comment.