From 75c6f504251dc6c0e8ec31f3fae910be3b705966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Mon, 5 Jul 2021 15:44:44 +0300 Subject: [PATCH] Formatting fixes --- .flake8 | 6 ++++++ .pre-commit-config.yaml | 6 ++++++ logger.py | 5 +++-- tailer.py | 11 ++++++----- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..ff6c948 --- /dev/null +++ b/.flake8 @@ -0,0 +1,6 @@ +[flake8] +inline-quotes = " +multiline-quotes = """ +indent-size = 4 +max-line-length = 160 +ignore = Q003 E128 E704 E731 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aab2253 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + additional_dependencies: [flake8-typing-imports==1.10.0,flake8-quotes==3.2.0] diff --git a/logger.py b/logger.py index c769ea8..f677c65 100755 --- a/logger.py +++ b/logger.py @@ -14,6 +14,7 @@ EXPIRE_AFTER_SECONDS = int(os.getenv("EXPIRE_AFTER_SECONDS", "1209600")) db = AsyncIOMotorClient(MONGO_URI).get_default_database() db.log.create_index("time", expireAfterSeconds=EXPIRE_AFTER_SECONDS) + class Server(object): def __init__(self): self._loop = asyncio.get_event_loop() @@ -35,14 +36,14 @@ class Server(object): tag, time, record, options = obj try: seconds, nanoseconds = struct.unpack(">II", time.data) - record["time"] = datetime.fromtimestamp(seconds).replace(microsecond=int(nanoseconds/1000)) + record["time"] = datetime.fromtimestamp(seconds).replace(microsecond=int(nanoseconds / 1000)) except AttributeError: record["time"] = datetime.fromtimestamp(time) assert not options, "Can't handle options" record.pop("container_id", None) record["host"] = FQDN - result = await db.log.insert_one(record) + await db.log.insert_one(record) async def main(): diff --git a/tailer.py b/tailer.py index 6f29e23..db47d54 100644 --- a/tailer.py +++ b/tailer.py @@ -15,13 +15,14 @@ if not MONGO_URI: db = AsyncIOMotorClient(MONGO_URI).get_default_database() parser = argparse.ArgumentParser() -parser.add_argument('--include-container', action='append', default=[]) -parser.add_argument('--exclude-container', action='append', default=[]) -parser.add_argument('--exclude-host', action='append', default=[]) +parser.add_argument("--include-container", action="append", default=[]) +parser.add_argument("--exclude-container", action="append", default=[]) +parser.add_argument("--exclude-host", action="append", default=[]) args = parser.parse_args() + async def main(): - async with db.log.watch([{'$match': {'operationType': 'insert'}}]) as stream: + async with db.log.watch([{"$match": {"operationType": "insert"}}]) as stream: print("Connected") async for event in stream: doc = event["fullDocument"] @@ -44,7 +45,7 @@ async def main(): m = re.match("time=\".*?\" level=[a-z]+ msg=\"(.*?)\"", msg) if m: msg, = m.groups() - m = re.match("\[\d+.*? \d+\] (.*?)\"", msg) + m = re.match(r"\[\d+.*? \d+\] (.*?)\"", msg) if m: msg, = m.groups() print(doc["time"], colored(doc.get("host", "-"), "blue"), "\t", "% 30s" % colored(container_name, "yellow"), msg)