Skip to content

Commit d2f93b2

Browse files
committed
Fix pylint warnings in kill module
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 0e3b30d commit d2f93b2

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ max-line-length = 100
6262
indent-string = " "
6363

6464
[tool.pylint.basic]
65-
good-names = ["i", "j", "k", "ex", "Run", "_", "fd", "dt", "id"]
65+
good-names = ["i", "j", "k", "ex", "Run", "_", "fd", "dt", "id", "e", "f"]
6666

6767
[tool.pylint.design]
6868
max-attributes = 10

src/kerf/kill/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@
1919
from .main import kill_cmd
2020

2121
__all__ = ['kill_cmd']
22-

src/kerf/kill/main.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
Kernel shutdown subcommand implementation using reboot syscall with MULTIKERNEL_HALT command.
1717
"""
1818

19-
import click
20-
import sys
21-
import os
2219
import ctypes
20+
import os
2321
import platform
22+
import sys
2423
from pathlib import Path
2524
from typing import Optional
25+
26+
import click
27+
2628
from ..models import InstanceState
2729
from ..utils import get_instance_id_from_name
2830

@@ -42,18 +44,17 @@ def get_reboot_syscall():
4244
arch = platform.machine().lower()
4345
if arch in ('x86_64', 'amd64'):
4446
return SYS_REBOOT_X86_64
45-
elif arch in ('aarch64', 'arm64'):
47+
if arch in ('aarch64', 'arm64'):
4648
return SYS_REBOOT_ARM64
47-
elif arch.startswith('arm'):
49+
if arch.startswith('arm'):
4850
return SYS_REBOOT_ARM
49-
elif arch in ('i386', 'i686', 'x86'):
51+
if arch in ('i386', 'i686', 'x86'):
5052
return SYS_REBOOT_X86
51-
else:
52-
click.echo(
53-
f"Warning: Unknown architecture '{arch}', assuming x86_64 syscall number",
54-
err=True
55-
)
56-
return SYS_REBOOT_X86_64
53+
click.echo(
54+
f"Warning: Unknown architecture '{arch}', assuming x86_64 syscall number",
55+
err=True
56+
)
57+
return SYS_REBOOT_X86_64
5758

5859

5960
class MultikernelBootArgs(ctypes.Structure):
@@ -62,6 +63,10 @@ class MultikernelBootArgs(ctypes.Structure):
6263
("mk_id", ctypes.c_int),
6364
]
6465

66+
def __init__(self):
67+
super().__init__()
68+
self.mk_id = 0
69+
6570

6671
def halt_multikernel(mk_id: int) -> int:
6772
libc = ctypes.CDLL(None, use_errno=True)
@@ -137,7 +142,7 @@ def kill_cmd(name: Optional[str], id: Optional[int], verbose: bool):
137142
err=True
138143
)
139144
click.echo(
140-
f"Check available instances in /sys/fs/multikernel/instances/",
145+
"Check available instances in /sys/fs/multikernel/instances/",
141146
err=True
142147
)
143148
sys.exit(1)
@@ -169,7 +174,7 @@ def kill_cmd(name: Optional[str], id: Optional[int], verbose: bool):
169174
err=True
170175
)
171176
click.echo(
172-
f"Check available instances in /sys/fs/multikernel/instances/",
177+
"Check available instances in /sys/fs/multikernel/instances/",
173178
err=True
174179
)
175180
sys.exit(1)
@@ -187,7 +192,7 @@ def kill_cmd(name: Optional[str], id: Optional[int], verbose: bool):
187192
sys.exit(1)
188193

189194
try:
190-
with open(status_path, 'r') as f:
195+
with open(status_path, 'r', encoding='utf-8') as f:
191196
status = f.read().strip()
192197

193198
status_lower = status.lower()
@@ -249,10 +254,9 @@ def kill_cmd(name: Optional[str], id: Optional[int], verbose: bool):
249254
)
250255
sys.exit(1)
251256

252-
except Exception as e:
253-
click.echo(f"Unexpected error: {e}", err=True)
257+
except Exception as exc:
258+
click.echo(f"Unexpected error: {exc}", err=True)
254259
if verbose:
255260
import traceback
256261
traceback.print_exc()
257262
sys.exit(1)
258-

0 commit comments

Comments
 (0)