From a9fa608e85e889069957a9d73328a282773032bd Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 7 Jul 2019 11:03:08 +0000 Subject: [PATCH] logging cache invalidation operations --- lib/config.py | 1 + lib/fetch.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/config.py b/lib/config.py index d2e2db0..85abcb8 100644 --- a/lib/config.py +++ b/lib/config.py @@ -105,6 +105,7 @@ _CONFIG = { "path.internal.vim": os.path.join(_MYDIR, "share/vim"), "path.log.main": "log/main.log", "path.log.queries": "log/queries.log", + "path.log.fetch": "log/fetch.log", "path.repositories": "upstream", "path.spool": "spool", "path.workdir": _WORKDIR, diff --git a/lib/fetch.py b/lib/fetch.py index cb4ebfb..686205b 100644 --- a/lib/fetch.py +++ b/lib/fetch.py @@ -4,9 +4,14 @@ Repositories fetch and update Ths module makes real network and OS interaction, and the adapters only say how exctly this interaction should be done. + +Configuration parameters: + + * path.log.fetch """ import sys +import logging import os import subprocess import textwrap @@ -15,8 +20,16 @@ from globals import fatal import adapter import cache -def _log(message): - sys.stdout.write(message) +from config import CONFIG + +def _log(*message): + logging.info(*message) + if len(message) > 1: + message = message[0].rstrip("\n") % tuple(message[1:]) + else: + message = message[0].rstrip("\n") + + sys.stdout.write(message+"\n") def _run_cmd(cmd): shell = isinstance(cmd, str) @@ -123,10 +136,16 @@ def _update_adapter(adptr): updates = output.splitlines() entries = adptr.get_updates_list(updates) + if entries: + _log("%s Entries to be updated: %s", adptr, len(entries)) + for entry in entries: - print "ivalidating ", entry + _log("+ ivalidating %s", entry) cache.delete(entry) + if entries: + _log("Done") + adptr.save_state(state) return True @@ -175,6 +194,11 @@ def main(args): _show_usage() sys.exit(0) + logging.basicConfig( + filename=CONFIG["path.log.fetch"], + level=logging.DEBUG, + format='%(asctime)s %(message)s') + if args[0] == 'fetch-all': fetch_all() elif args[0] == 'update':