Skip to content

Commit

Permalink
Various ruff-related fixes
Browse files Browse the repository at this point in the history
Change-Id: I4d5f56379f761aa330f79e6d484fe99c7f0571fc
  • Loading branch information
spt29 committed Dec 3, 2024
1 parent eb67040 commit 17731fd
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 87 deletions.
6 changes: 3 additions & 3 deletions bin/check_mk
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class CrashReport(ABCCrashReport):
cls,
crashdir: Path,
version_info: dict[str, object],
details: object = None,
type_specific_attributes: object = None,
_details: object = None,
_type_specific_attributes: object = None,
) -> Self:
return super().from_exception(
crashdir,
Expand Down Expand Up @@ -163,7 +163,7 @@ except MKTerminate:
sys.exit(1)

except (MKGeneralException, MKBailOut) as e:
sys.stderr.write("%s\n" % e)
sys.stderr.write(f"{e}\n")
if cmk.ccc.debug.enabled():
raise
sys.exit(3)
Expand Down
2 changes: 1 addition & 1 deletion bin/cmk-piggyback
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _write(message: str) -> None:


def _command_track(
args: argparse.Namespace,
_args: argparse.Namespace,
) -> int:
"""Track incoming piggyback messages.
Expand Down
5 changes: 2 additions & 3 deletions bin/cmk-trigger-api-spec-job
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
# conditions defined in the file COPYING, which is part of this source code package.

import sys
from collections.abc import Sequence
from logging import getLogger

from cmk.gui.openapi.spec.spec_generator_job import trigger_spec_generation_in_background


def main(args: Sequence[str]) -> int:
def main() -> int:
logger = getLogger("api-spec")
try:
trigger_spec_generation_in_background(user_id=None)
Expand All @@ -21,4 +20,4 @@ def main(args: Sequence[str]) -> int:


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
sys.exit(main())
5 changes: 2 additions & 3 deletions bin/cmk-wait-for-background-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ shutdown proces.

import logging
import sys
from collections.abc import Sequence

from cmk.gui.background_job import wait_for_background_jobs


def main(args: Sequence[str]) -> int:
def main() -> int:
logger = logging.getLogger("cmk-wait-for-background-jobs")
logger.addHandler(handler := logging.StreamHandler(stream=sys.stdout))
handler.setFormatter(logging.Formatter("%(message)s"))
Expand All @@ -33,4 +32,4 @@ def main(args: Sequence[str]) -> int:


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
sys.exit(main())
56 changes: 27 additions & 29 deletions bin/livedump
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ def livedump_config(args: Arguments) -> None:
f" host_name {args.prefix}{row['name']}\n"
)
sys.stdout.write(
" alias %(alias)s\n"
" address %(address)s\n"
" host_groups %(groupstring)s\n"
" check_command %(check_command)s\n"
" max_check_attempts %(max_check_attempts)d\n" % row
f" alias {row['alias']}\n"
f" address {row['address']}\n"
f" host_groups {row['groupstring']}\n"
f" check_command {row['check_command']}\n"
f" max_check_attempts {row['max_check_attempts']}\n"
)
if args.include_groups:
sys.stdout.write(" contacts %s\n" % row["contactsstring"])
sys.stdout.write(f" contacts {row['contactsstring']}\n")
else:
sys.stdout.write(" contact_groups %s\n" % row["contact_groups"])
sys.stdout.write(f" contact_groups {row['contact_groups']}\n")
if args.include_host_icon:
if row.get("icon_image"):
sys.stdout.write(" icon_image %s\n" % row["icon_image"])
sys.stdout.write(f" icon_image {row['icon_image']}\n")
sys.stdout.write("}\n\n")

# Dump service config
Expand All @@ -246,12 +246,12 @@ def livedump_config(args: Arguments) -> None:
f" host_name {args.prefix}{row['host_name']}\n"
)
sys.stdout.write(
" description %(description)s\n"
" %(groupstring)s\n"
" check_command check-livedump\n"
" contacts %(contactsstring)s\n"
" max_check_attempts %(max_check_attempts)d\n"
"}\n\n" % row
f" description {row['description']}\n"
f" {row['groupstring']}\n"
f" check_command check-livedump\n"
f" contacts {row['contactsstring']}\n"
f" max_check_attempts {row['max_check_attempts']}\n"
"}\n\n"
)


Expand All @@ -272,18 +272,17 @@ def livedump_state(args: Arguments) -> None:
row["now"] = now
sys.stdout.write(f"host_name={args.prefix}{row['name']}")
sys.stdout.write(
"""
f"""
check_type=1
check_options=0
reschedule_check
latency=%(latency).2f
start_time=%(now).1f
finish_time=%(now).1f
return_code=%(state)d
output=%(plugin_output)s|%(perf_data)s
latency={row['latency']:.2f}
start_time={row['now']:.1f}
finish_time={row['now']:.1f}
return_code={row['state']}
output={row['plugin_output']}|{row['perf_data']}
"""
% row
)

query = "\n".join(
Expand All @@ -298,19 +297,18 @@ output=%(plugin_output)s|%(perf_data)s
row["now"] = now
sys.stdout.write(f"host_name={args.prefix}{row['host_name']}")
sys.stdout.write(
"""
service_description=%(description)s
f"""
service_description={row['description']}
check_type=1
check_options=0
reschedule_check
latency=%(latency).2f
start_time=%(now).1f
finish_time=%(now).1f
return_code=%(state)d
output=%(plugin_output)s|%(perf_data)s
latency={row['latency']:.2f}
start_time={row['now']:.1f}
finish_time={row['now']:.1f}
return_code={row['state']}
output={row['plugin_output']}|{row['perf_data']}
"""
% row
)


Expand Down
Loading

0 comments on commit 17731fd

Please sign in to comment.