From 0aa8955b4a04f78c1bd6559f6548cd7d05ec2a51 Mon Sep 17 00:00:00 2001 From: retoor Date: Sun, 1 Dec 2024 08:50:26 +0100 Subject: [PATCH] Formatted. --- src/zhurnal/app.py | 51 +++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/zhurnal/app.py b/src/zhurnal/app.py index 9504d2d..801ac8d 100644 --- a/src/zhurnal/app.py +++ b/src/zhurnal/app.py @@ -1,12 +1,13 @@ -from aiohttp import web -from typing import List -import shlex import asyncio import json -from datetime import datetime -from zhurnal import log +import shlex import time +from datetime import datetime +from typing import List +from aiohttp import web + +from zhurnal import log index_html = """ @@ -244,7 +245,7 @@ class Zhurnal(web.Application): stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) - log.info("Running process {}: {}".format(process_name, command)) + log.info(f"Running process {process_name}: {command}") async def read_output(app, name, process, f): time_previous = 0 @@ -259,42 +260,36 @@ class Zhurnal(web.Application): for client in app.clients: await client.send_str( json.dumps( - dict( - elapsed=time_elapsed, - timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - line=decoded_line, - name=name, - command=command, - ) + { + "elapsed": time_elapsed, + "timestamp": datetime.now().strftime( + "%Y-%m-%d %H:%M:%S" + ), + "line": decoded_line, + "name": name, + "command": command, + } ) ) time_previous = time.time() await asyncio.gather( - read_output( - self, "{}:stdout".format(process_name), command, process.stdout - ), - read_output( - self, "{}:stderr".format(process_name), process, process.stderr - ), + read_output(self, f"{process_name}:stdout", command, process.stdout), + read_output(self, f"{process_name}:stderr", process, process.stderr), ) if process.returncode == 0: log.info( - "Process {}:{} exited with {}.".format( - process_name, command, process.returncode - ) + f"Process {process_name}:{command} exited with {process.returncode}." ) else: log.error( - "Process {}:{} exited with {}.".format( - process_name, command, process.returncode - ) + f"Process {process_name}:{command} exited with {process.returncode}." ) async def start_processes(self, app): for x, command in enumerate(self.commands): self.processes[command] = asyncio.create_task( - self.run_process("process-{}".format(x), command) + self.run_process(f"process-{x}", command) ) # asyncio.create_task(asyncio.gather(*self.processes.values())) @@ -324,6 +319,6 @@ def cli(): args = parse_args() app = Zhurnal(commands=args.commands) for command in args.commands: - log.info("Preparing execution of {}.".format(command)) - log.info("Host: {} Port: {}".format(args.host, args.port)) + log.info(f"Preparing execution of {command}.") + log.info(f"Host: {args.host} Port: {args.port}") web.run_app(app, host=args.host, port=args.port)