Skip to content

Commit

Permalink
refactor: ran pyupgrade --py38-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Aug 12, 2022
1 parent 1c7c618 commit f47ad75
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions aw_server/__about__.py
Expand Up @@ -102,14 +102,14 @@ def detect_version():
def assign_static_version():
"""Self-modifies the current script to lock in version"""
version = detect_version()
with open(__file__, "r") as f:
versionline = '\n__version__ = "{}"'.format(version)
with open(__file__) as f:
versionline = f'\n__version__ = "{version}"'
data = re.sub(r"\n__version__ = [^\n;]+", versionline, f.read())

with open(__file__, "w") as f:
f.write(data)

print("Set versionline: {}".format(versionline.strip()))
print(f"Set versionline: {versionline.strip()}")


if __name__ == "__main__":
Expand Down
16 changes: 8 additions & 8 deletions aw_server/api.py
Expand Up @@ -26,7 +26,7 @@
def get_device_id() -> str:
path = Path(get_data_dir("aw-server")) / "device_id"
if path.exists():
with open(path, "r") as f:
with open(path) as f:
return f.read()
else:
uuid = str(uuid4())
Expand All @@ -40,7 +40,7 @@ def check_bucket_exists(f):
def g(self, bucket_id, *args, **kwargs):
if bucket_id not in self.db.buckets():
raise NotFound(
"NoSuchBucket", "There's no bucket named {}".format(bucket_id)
"NoSuchBucket", f"There's no bucket named {bucket_id}"
)
return f(self, bucket_id, *args, **kwargs)

Expand Down Expand Up @@ -102,7 +102,7 @@ def export_all(self) -> Dict[str, Any]:

def import_bucket(self, bucket_data: Any):
bucket_id = bucket_data["id"]
logger.info("Importing bucket {}".format(bucket_id))
logger.info(f"Importing bucket {bucket_id}")

# TODO: Check that bucket doesn't already exist
self.db.create_bucket(
Expand Down Expand Up @@ -161,7 +161,7 @@ def create_bucket(
def delete_bucket(self, bucket_id: str) -> None:
"""Delete a bucket"""
self.db.delete_bucket(bucket_id)
logger.debug("Deleted bucket '{}'".format(bucket_id))
logger.debug(f"Deleted bucket '{bucket_id}'")
return None

@check_bucket_exists
Expand All @@ -186,7 +186,7 @@ def get_events(
end: datetime = None,
) -> List[Event]:
"""Get events from a bucket"""
logger.debug("Received get request for events in bucket '{}'".format(bucket_id))
logger.debug(f"Received get request for events in bucket '{bucket_id}'")
if limit is None: # Let limit = None also mean "no limit"
limit = -1
events = [
Expand All @@ -207,7 +207,7 @@ def get_eventcount(
) -> int:
"""Get eventcount from a bucket"""
logger.debug(
"Received get request for eventcount in bucket '{}'".format(bucket_id)
f"Received get request for eventcount in bucket '{bucket_id}'"
)
return self.db[bucket_id].get_eventcount(start, end)

Expand Down Expand Up @@ -310,15 +310,15 @@ def query2(self, name, query, timeperiods, cache):
] # iso8601 timeperiods are separated by a slash
starttime = iso8601.parse_date(period[0])
endtime = iso8601.parse_date(period[1])
query = str().join(query)
query = ''.join(query)
result.append(query2.query(name, query, starttime, endtime, self.db))
return result

# TODO: Right now the log format on disk has to be JSON, this is hard to read by humans...
def get_log(self):
"""Get the server log in json format"""
payload = []
with open(get_log_file_path(), "r") as log_file:
with open(get_log_file_path()) as log_file:
for line in log_file.readlines()[::-1]:
payload.append(json.loads(line))
return payload, 200
2 changes: 1 addition & 1 deletion aw_server/log.py
Expand Up @@ -22,4 +22,4 @@ def log(self, levelname, message, *args):
levelno = logging.DEBUG
else:
raise Exception("Unknown level " + type)
self.logger.log(levelno, "{} ({}): {}".format(code, self.address_string(), msg))
self.logger.log(levelno, f"{code} ({self.address_string()}): {msg}")
2 changes: 1 addition & 1 deletion aw_server/main.py
Expand Up @@ -30,7 +30,7 @@ def main():
log_file_json=False,
)

logger.info("Using storage method: {}".format(settings.storage))
logger.info(f"Using storage method: {settings.storage}")

if settings.testing:
logger.info("Will run in testing mode")
Expand Down

0 comments on commit f47ad75

Please sign in to comment.