Autoformat with black

This commit is contained in:
Christoph Stahl 2023-03-23 15:16:36 +01:00
parent 5ca9b3f9e9
commit 03b46d2bd5
2 changed files with 15 additions and 7 deletions

View file

@ -722,7 +722,7 @@ async def handle_search(sid: str, data: dict[str, Any]) -> None:
async def cleanup() -> None: async def cleanup() -> None:
""" Clean up the unused playback clients """Clean up the unused playback clients
This runs every hour, and removes every client, that did not requested a song for four hours This runs every hour, and removes every client, that did not requested a song for four hours
""" """
@ -731,7 +731,10 @@ async def cleanup() -> None:
to_remove: list[str] = [] to_remove: list[str] = []
for sid, state in clients.items(): for sid, state in clients.items():
logger.info("Client %s, last seen: %s", sid, str(state.last_seen)) logger.info("Client %s, last seen: %s", sid, str(state.last_seen))
if state.last_seen + datetime.timedelta(hours=4) < datetime.datetime.now(): if (
state.last_seen + datetime.timedelta(hours=4)
< datetime.datetime.now()
):
logger.info("No activity for 4 hours, removing %s", sid) logger.info("No activity for 4 hours, removing %s", sid)
to_remove.append(sid) to_remove.append(sid)
for sid in to_remove: for sid in to_remove:
@ -739,7 +742,6 @@ async def cleanup() -> None:
del clients[sid] del clients[sid]
logger.info("End Cleanup") logger.info("End Cleanup")
# The internal loop counter does not use a regular timestamp, so we need to convert between # The internal loop counter does not use a regular timestamp, so we need to convert between
# regular datetime and the async loop time # regular datetime and the async loop time
now = datetime.datetime.now() now = datetime.datetime.now()
@ -751,10 +753,15 @@ async def cleanup() -> None:
loop_next = asyncio.get_event_loop().time() + offset loop_next = asyncio.get_event_loop().time() + offset
logger.info("Next Cleanup at %s", str(next)) logger.info("Next Cleanup at %s", str(next))
asyncio.get_event_loop().call_at(loop_next, lambda: asyncio.create_task(cleanup())) asyncio.get_event_loop().call_at(
loop_next, lambda: asyncio.create_task(cleanup())
)
async def background_tasks(iapp: web.Application) -> AsyncGenerator[None, None]:
""" Create all the background tasks async def background_tasks(
iapp: web.Application,
) -> AsyncGenerator[None, None]:
"""Create all the background tasks
For now, this is only the cleanup task For now, this is only the cleanup task
""" """
@ -766,6 +773,7 @@ async def background_tasks(iapp: web.Application) -> AsyncGenerator[None, None]:
iapp["repeated_cleanup"].cancel() iapp["repeated_cleanup"].cancel()
await iapp["repeated_cleanup"] await iapp["repeated_cleanup"]
def main() -> None: def main() -> None:
""" """
Configure and start the server. Configure and start the server.

View file

@ -35,7 +35,7 @@ class FilesSource(Source):
for file in files: for file in files:
if file.endswith(".cdg"): if file.endswith(".cdg"):
file_list.append( file_list.append(
os.path.join(path, file)[len(self.dir):] os.path.join(path, file)[len(self.dir) :]
) )
return file_list return file_list