mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 18:11:54 +08:00
f-strings
This commit is contained in:
@@ -119,7 +119,7 @@ def _init_config(config_path: str, sections: List[str], override_options: List[s
|
||||
|
||||
return config
|
||||
except (ConfigError, UnknownPluginError) as err:
|
||||
raise SystemExit("Config error: %s" % (str(err)))
|
||||
raise SystemExit(f"Config error: {err}")
|
||||
|
||||
|
||||
def _dump_config(config: Section) -> None:
|
||||
|
||||
@@ -45,7 +45,8 @@ from .. import init
|
||||
# =====
|
||||
def _get_htpasswd_path(config: Section) -> str:
|
||||
if config.kvmd.auth.internal_type != "htpasswd":
|
||||
raise SystemExit("Error: KVMD internal auth not using 'htpasswd' (now configured %r)" % (config.kvmd.auth.internal_type))
|
||||
raise SystemExit(f"Error: KVMD internal auth not using 'htpasswd'"
|
||||
f" (now configured {config.kvmd.auth.internal_type!r})")
|
||||
return config.kvmd.auth.internal.file
|
||||
|
||||
|
||||
@@ -53,7 +54,7 @@ def _get_htpasswd_path(config: Section) -> str:
|
||||
def _get_htpasswd_for_write(config: Section) -> Generator[passlib.apache.HtpasswdFile, None, None]:
|
||||
path = _get_htpasswd_path(config)
|
||||
(tmp_fd, tmp_path) = tempfile.mkstemp(
|
||||
prefix=".%s." % (os.path.basename(path)),
|
||||
prefix=f".{os.path.basename(path)}.",
|
||||
dir=os.path.dirname(path),
|
||||
)
|
||||
try:
|
||||
|
||||
@@ -61,12 +61,12 @@ class IpmiAuthManager:
|
||||
continue
|
||||
|
||||
if " -> " not in line:
|
||||
raise IpmiPasswdError("Missing ' -> ' operator at line #%d" % (number))
|
||||
raise IpmiPasswdError(f"Missing ' -> ' operator at line #{number}")
|
||||
|
||||
(left, right) = map(str.lstrip, line.split(" -> ", 1))
|
||||
for (name, pair) in [("left", left), ("right", right)]:
|
||||
if ":" not in pair:
|
||||
raise IpmiPasswdError("Missing ':' operator in %s credentials at line #%d" % (name, number))
|
||||
raise IpmiPasswdError(f"Missing ':' operator in {name} credentials at line #{number}")
|
||||
|
||||
(ipmi_user, ipmi_passwd) = left.split(":")
|
||||
ipmi_user = ipmi_user.strip()
|
||||
@@ -75,7 +75,7 @@ class IpmiAuthManager:
|
||||
kvmd_user = kvmd_user.strip()
|
||||
|
||||
if ipmi_user in credentials:
|
||||
raise IpmiPasswdError("Found duplicating user %r (left) at line #%d" % (ipmi_user, number))
|
||||
raise IpmiPasswdError(f"Found duplicating user {ipmi_user!r} (left) at line #{number}")
|
||||
|
||||
credentials[ipmi_user] = IpmiUserCredentials(
|
||||
ipmi_user=ipmi_user,
|
||||
|
||||
@@ -155,7 +155,7 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute
|
||||
logger = get_logger(0)
|
||||
|
||||
assert handle.startswith("/")
|
||||
url = "http://%s:%d%s" % (self.__kvmd_host, self.__kvmd_port, handle)
|
||||
url = f"http://{self.__kvmd_host}:{self.__kvmd_port}{handle}"
|
||||
|
||||
credentials = self.__auth_manager.get_credentials(ipmi_session.username.decode())
|
||||
logger.info("Performing %r request to %r from user %r (IPMI) as %r (KVMD)",
|
||||
@@ -169,7 +169,7 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute
|
||||
headers={
|
||||
"X-KVMD-User": credentials.kvmd_user,
|
||||
"X-KVMD-Passwd": credentials.kvmd_passwd,
|
||||
"User-Agent": "KVMD-IPMI/%s" % (__version__),
|
||||
"User-Agent": f"KVMD-IPMI/{__version__}",
|
||||
},
|
||||
timeout=self.__kvmd_timeout,
|
||||
) as response:
|
||||
|
||||
@@ -156,7 +156,7 @@ def _ioctl_uint32(device_file: IO, request: int) -> int:
|
||||
|
||||
def _explore_device(device_path: str) -> _MassStorageDeviceInfo:
|
||||
if not stat.S_ISBLK(os.stat(device_path).st_mode):
|
||||
raise RuntimeError("Not a block device: %s" % (device_path))
|
||||
raise RuntimeError(f"Not a block device: {device_path}")
|
||||
|
||||
with open(device_path, "rb") as device_file:
|
||||
# size = BLKGETSIZE * BLKSSZGET
|
||||
|
||||
@@ -142,7 +142,7 @@ def _json_exception(err: Exception, status: int) -> aiohttp.web.Response:
|
||||
async def _get_multipart_field(reader: aiohttp.MultipartReader, name: str) -> aiohttp.BodyPartReader:
|
||||
field = await reader.next()
|
||||
if not field or field.name != name:
|
||||
raise ValidatorError("Missing %r field" % (name))
|
||||
raise ValidatorError(f"Missing {name!r} field")
|
||||
return field
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ def _exposed(http_method: str, path: str, auth_required: bool=True) -> Callable:
|
||||
|
||||
if user:
|
||||
user = valid_user(user)
|
||||
setattr(request, _ATTR_KVMD_AUTH_INFO, "%s (xhdr)" % (user))
|
||||
setattr(request, _ATTR_KVMD_AUTH_INFO, f"{user} (xhdr)")
|
||||
if not (await self._auth_manager.authorize(user, valid_passwd(passwd))):
|
||||
raise ForbiddenError("Forbidden")
|
||||
|
||||
@@ -177,7 +177,7 @@ def _exposed(http_method: str, path: str, auth_required: bool=True) -> Callable:
|
||||
if not user:
|
||||
setattr(request, _ATTR_KVMD_AUTH_INFO, "- (token)")
|
||||
raise ForbiddenError("Forbidden")
|
||||
setattr(request, _ATTR_KVMD_AUTH_INFO, "%s (token)" % (user))
|
||||
setattr(request, _ATTR_KVMD_AUTH_INFO, f"{user} (token)")
|
||||
|
||||
else:
|
||||
raise UnauthorizedError("Unauthorized")
|
||||
@@ -204,7 +204,7 @@ def _system_task(method: Callable) -> Callable:
|
||||
async def wrapper(self: "Server") -> None:
|
||||
try:
|
||||
await method(self)
|
||||
raise RuntimeError("Dead system task: %s" % (method))
|
||||
raise RuntimeError(f"Dead system task: {method}")
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except Exception:
|
||||
|
||||
@@ -121,8 +121,8 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
||||
state = None
|
||||
try:
|
||||
async with session.get(
|
||||
url="http://%s:%d/state" % (self.__host, self.__port),
|
||||
headers={"User-Agent": "KVMD/%s" % (__version__)},
|
||||
url=f"http://{self.__host}:{self.__port}/state",
|
||||
headers={"User-Agent": f"KVMD/{__version__}"},
|
||||
timeout=self.__timeout,
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user