mirror of
https://github.com/seemoo-lab/opendrop.git
synced 2026-09-14 15:16:11 -04:00
Use f-strings in logging statements
This commit is contained in:
+6
-15
@@ -123,9 +123,7 @@ class AirDropCli:
|
||||
pass
|
||||
finally:
|
||||
self.browser.stop()
|
||||
logger.debug(
|
||||
"Save discovery results to {}".format(self.config.discovery_report)
|
||||
)
|
||||
logger.debug(f"Save discovery results to {self.config.discovery_report}")
|
||||
with open(self.config.discovery_report, "w") as f:
|
||||
json.dump(self.discover, f)
|
||||
|
||||
@@ -137,16 +135,12 @@ class AirDropCli:
|
||||
try:
|
||||
address = info.parsed_addresses()[0] # there should only be one address
|
||||
except IndexError:
|
||||
logger.warn("Ignoring receiver with missing address {}".format(info))
|
||||
logger.warn(f"Ignoring receiver with missing address {info}")
|
||||
return
|
||||
id = info.name.split(".")[0]
|
||||
hostname = info.server
|
||||
port = int(info.port)
|
||||
logger.debug(
|
||||
"AirDrop service found: {}, {}:{}, ID {}".format(
|
||||
hostname, address, port, id
|
||||
)
|
||||
)
|
||||
logger.debug(f"AirDrop service found: {hostname}, {address}:{port}, ID {id}")
|
||||
client = AirDropClient(self.config, (address, int(port)))
|
||||
try:
|
||||
flags = int(info.properties[b"flags"])
|
||||
@@ -175,11 +169,9 @@ class AirDropCli:
|
||||
self.lock.acquire()
|
||||
self.discover.append(node_info)
|
||||
if discoverable:
|
||||
logger.info(
|
||||
"Found index {} ID {} name {}".format(index, id, receiver_name)
|
||||
)
|
||||
logger.info(f"Found index {index} ID {id} name {receiver_name}")
|
||||
else:
|
||||
logger.debug("Receiver ID {} is not discoverable".format(id))
|
||||
logger.debug(f"Receiver ID {id} is not discoverable")
|
||||
self.lock.release()
|
||||
|
||||
def receive(self):
|
||||
@@ -210,8 +202,7 @@ class AirDropCli:
|
||||
age = time.time() - os.path.getmtime(self.config.discovery_report)
|
||||
if age > 60: # warn if report is older than a minute
|
||||
logger.warning(
|
||||
"Old discovery report (%.1f seconds), consider running 'opendrop find' again",
|
||||
age,
|
||||
f"Old discovery report ({age:.1f} seconds), consider running 'opendrop find' again"
|
||||
)
|
||||
with open(self.config.discovery_report, "r") as f:
|
||||
infos = json.load(f)
|
||||
|
||||
+8
-11
@@ -41,14 +41,11 @@ class AirDropBrowser:
|
||||
if self.ip_addr is None:
|
||||
if config.interface == "awdl0":
|
||||
raise RuntimeError(
|
||||
"Interface {} does not have an IPv6 address. "
|
||||
"Make sure that `owl` is running.".format(config.interface)
|
||||
f"Interface {config.interface} does not have an IPv6 address. Make sure that `owl` is running."
|
||||
)
|
||||
else:
|
||||
raise RuntimeError(
|
||||
"Interface {} does not have an IPv6 address".format(
|
||||
config.interface
|
||||
)
|
||||
f"Interface {config.interface} does not have an IPv6 address"
|
||||
)
|
||||
|
||||
self.zeroconf = Zeroconf(
|
||||
@@ -78,13 +75,13 @@ class AirDropBrowser:
|
||||
|
||||
def add_service(self, zeroconf, type, name):
|
||||
info = zeroconf.get_service_info(type, name)
|
||||
logger.debug("Add service {}".format(name))
|
||||
logger.debug(f"Add service {name}")
|
||||
if self.callback_add is not None:
|
||||
self.callback_add(info)
|
||||
|
||||
def remove_service(self, zeroconf, type, name):
|
||||
info = zeroconf.get_service_info(type, name)
|
||||
logger.debug("Remove service {}".format(name))
|
||||
logger.debug(f"Remove service {name}")
|
||||
if self.callback_remove is not None:
|
||||
self.callback_remove(info)
|
||||
|
||||
@@ -97,7 +94,7 @@ class AirDropClient:
|
||||
self.http_conn = None
|
||||
|
||||
def send_POST(self, url, body, headers=None):
|
||||
logger.debug("Send {} request".format(url))
|
||||
logger.debug(f"Send {url} request")
|
||||
|
||||
AirDropUtil.write_debug(
|
||||
self.config, body, "send_{}_request.plist".format(url.lower().strip("/"))
|
||||
@@ -127,10 +124,10 @@ class AirDropClient:
|
||||
|
||||
if http_resp.status != 200:
|
||||
status = False
|
||||
logger.debug("{} request failed: {}".format(url, http_resp.status))
|
||||
logger.debug(f"{url} request failed: {http_resp.status}")
|
||||
else:
|
||||
status = True
|
||||
logger.debug("{} request successful".format(url))
|
||||
logger.debug(f"{url} request successful")
|
||||
return status, response_bytes
|
||||
|
||||
def send_discover(self):
|
||||
@@ -251,7 +248,7 @@ class HTTPSConnectionAWDL(HTTPSConnection):
|
||||
*,
|
||||
context=None,
|
||||
check_hostname=None,
|
||||
interface_name=None
|
||||
interface_name=None,
|
||||
):
|
||||
|
||||
if interface_name is not None:
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ class AirDropConfig:
|
||||
logger.debug("No Apple ID Validation Record found")
|
||||
|
||||
def create_default_key(self):
|
||||
logger.info("Create new self-signed certificate in {}".format(self.key_dir))
|
||||
logger.info(f"Create new self-signed certificate in {self.key_dir}")
|
||||
if not os.path.exists(self.key_dir):
|
||||
os.makedirs(self.key_dir)
|
||||
subprocess.run(
|
||||
|
||||
+8
-14
@@ -92,9 +92,7 @@ class AirDropServer:
|
||||
|
||||
def start_service(self):
|
||||
logger.info(
|
||||
"Announcing service: host {}, address {}, port {}".format(
|
||||
self.config.host_name, self.ip_addr, self.config.port
|
||||
)
|
||||
f"Announcing service: host {self.config.host_name}, address {self.ip_addr}, port {self.config.port}"
|
||||
)
|
||||
self.zeroconf.register_service(self.service_info)
|
||||
|
||||
@@ -162,7 +160,7 @@ class AirDropServerHandler(BaseHTTPRequestHandler):
|
||||
"""
|
||||
Answer get requests
|
||||
"""
|
||||
logger.debug("GET request at {}".format(self.path))
|
||||
logger.debug(f"GET request at {self.path}")
|
||||
body = "\n".encode("utf-8")
|
||||
self._set_response(len(body))
|
||||
self.wfile.write(body)
|
||||
@@ -250,7 +248,7 @@ class AirDropServerHandler(BaseHTTPRequestHandler):
|
||||
def handle_upload(self):
|
||||
if self.headers.get("content-type", "").lower() != "application/x-cpio":
|
||||
logger.warning(
|
||||
"Unsupported content-type: {}".format(self.headers.get("content-type"))
|
||||
f"Unsupported content-type: {self.headers.get('content-type')}"
|
||||
)
|
||||
self.send_response(406) # Unprocessable Entity
|
||||
self.send_header("Content-Type", "application/x-cpio")
|
||||
@@ -311,9 +309,7 @@ class AirDropServerHandler(BaseHTTPRequestHandler):
|
||||
transferred = reader.total / 1024.0 / 1024.0
|
||||
speed = transferred / (time.time() - start)
|
||||
logger.info(
|
||||
"File(s) received (size {:.02f} MB, speed {:.02f} MB/s)".format(
|
||||
transferred, speed
|
||||
)
|
||||
f"File(s) received (size {transferred:.02f} MB, speed {speed:.02f} MB/s)"
|
||||
)
|
||||
|
||||
self.send_response(200)
|
||||
@@ -326,8 +322,8 @@ class AirDropServerHandler(BaseHTTPRequestHandler):
|
||||
Handle post requests
|
||||
"""
|
||||
|
||||
logger.debug("POST request at {}".format(self.path))
|
||||
logger.debug("Headers\n{}".format(self.headers))
|
||||
logger.debug(f"POST request at {self.path}")
|
||||
logger.debug(f"Headers\n{self.headers}")
|
||||
|
||||
if self.path == "/Discover":
|
||||
self.handle_discover()
|
||||
@@ -336,14 +332,12 @@ class AirDropServerHandler(BaseHTTPRequestHandler):
|
||||
elif self.path == "/Upload":
|
||||
self.handle_upload()
|
||||
else:
|
||||
logger.debug("POST request at {}".format(self.path))
|
||||
logger.debug(f"POST request at {self.path}")
|
||||
self.send_response(400)
|
||||
self.send_header("Content-Length", 0)
|
||||
self.end_headers()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
logger.debug(
|
||||
"{} - - [{}] {}".format(
|
||||
self.client_address[0], self.log_date_time_string(), format % args
|
||||
)
|
||||
f"{self.client_address[0]} - - [{self.log_date_time_string()}] {format % args}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user