mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
refactor: use f-strings in remaining modules, scripts and tests
This commit is contained in:
12 files changed
+55
-78
No files matched your search
@@ -77,14 +77,14 @@ class CrashReport:
|
||||
dsn=CrashReport.DSN, release=__version__, default_integrations=False, integrations=[sentry_logging]
|
||||
)
|
||||
except Exception as e:
|
||||
log.error("Crash report could not be sent: {}".format(e))
|
||||
log.error(f"Crash report could not be sent: {e}")
|
||||
return
|
||||
|
||||
tags = {
|
||||
"os:name": platform.system(),
|
||||
"os:release": platform.release(),
|
||||
"os:win_32": " ".join(platform.win32_ver()),
|
||||
"os:mac": "{} {}".format(platform.mac_ver()[0], platform.mac_ver()[2]),
|
||||
"os:mac": f"{platform.mac_ver()[0]} {platform.mac_ver()[2]}",
|
||||
"os:linux": distro.name(pretty=True),
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class CrashReport:
|
||||
scope.set_tag(key, value)
|
||||
|
||||
extra_context = {
|
||||
"python:version": "{}.{}.{}".format(sys.version_info[0], sys.version_info[1], sys.version_info[2]),
|
||||
"python:version": f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}",
|
||||
"python:bit": struct.calcsize("P") * 8,
|
||||
"python:encoding": sys.getdefaultencoding(),
|
||||
"python:frozen": "{}".format(hasattr(sys, "frozen")),
|
||||
|
||||
@@ -59,10 +59,10 @@ class GUID(TypeDecorator):
|
||||
return str(value)
|
||||
else:
|
||||
if not isinstance(value, uuid.UUID):
|
||||
return "{:032x}".format(uuid.UUID(value).int)
|
||||
return f"{uuid.UUID(value).int:032x}"
|
||||
else:
|
||||
# hexstring
|
||||
return "{:032x}".format(value.int)
|
||||
return f"{value.int:032x}"
|
||||
|
||||
def process_result_value(self, value, dialect):
|
||||
if value is None:
|
||||
|
||||
@@ -260,9 +260,7 @@ class Server:
|
||||
raise SystemExit("Python 3.9 or higher is required")
|
||||
|
||||
log.info(
|
||||
"Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
|
||||
major=sys.version_info[0], minor=sys.version_info[1], micro=sys.version_info[2], pid=os.getpid()
|
||||
)
|
||||
f"Running with Python {sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]} and has PID {os.getpid()}"
|
||||
)
|
||||
|
||||
# check for the correct locale (UNIX/Linux only)
|
||||
|
||||
@@ -48,7 +48,7 @@ def int_to_macaddress(integer):
|
||||
"""
|
||||
Convert an integer to a mac address
|
||||
"""
|
||||
return ":".join(textwrap.wrap("{:012x}".format(integer), width=2))
|
||||
return ":".join(textwrap.wrap(f"{integer:012x}", width=2))
|
||||
|
||||
|
||||
def parse_version(version):
|
||||
|
||||
@@ -184,7 +184,7 @@ class ZipFile(zipfile.ZipFile):
|
||||
"""
|
||||
|
||||
if not isinstance(comment, bytes):
|
||||
raise TypeError("comment: expected bytes, got {}".format(type(comment)))
|
||||
raise TypeError(f"comment: expected bytes, got {type(comment)}")
|
||||
# check for valid comment length
|
||||
if len(comment) >= zipfile.ZIP_MAX_COMMENT:
|
||||
if self.debug:
|
||||
|
||||
@@ -70,7 +70,7 @@ async def list_images(image_type):
|
||||
for root, _, filenames in _os_walk(directory, recurse=recurse):
|
||||
for filename in filenames:
|
||||
if filename in files:
|
||||
log.debug("File {} has already been found, skipping...".format(filename))
|
||||
log.debug(f"File {filename} has already been found, skipping...")
|
||||
continue
|
||||
if filename.endswith(".md5sum") or filename.startswith("."):
|
||||
continue
|
||||
|
||||
@@ -66,7 +66,7 @@ def _get_windows_interfaces_from_registry():
|
||||
if ip_address:
|
||||
# get the first IPv4 address only
|
||||
ip_address = ip_address[0]
|
||||
npf_interface = "\\Device\\NPF_{guid}".format(guid=guid)
|
||||
npf_interface = f"\\Device\\NPF_{guid}"
|
||||
interfaces.append(
|
||||
{
|
||||
"id": npf_interface,
|
||||
@@ -116,7 +116,7 @@ def get_windows_interfaces():
|
||||
ip_address = network_config.IPAddress[0]
|
||||
netmask = network_config.IPSubnet[0]
|
||||
break
|
||||
npf_interface = "\\Device\\NPF_{guid}".format(guid=adapter.GUID)
|
||||
npf_interface = f"\\Device\\NPF_{adapter.GUID}"
|
||||
interfaces.append(
|
||||
{
|
||||
"id": npf_interface,
|
||||
|
||||
Reference in new issue
Block a user