From a939e6503c2106003a65aae59138993429fa6c4e Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Sat, 6 Aug 2022 21:56:41 +0200 Subject: [PATCH] rebuild only files that need re-building we compare the mtimes of src and dst --- blag/blag.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/blag/blag.py b/blag/blag.py index e84bc2b..c47fc2b 100644 --- a/blag/blag.py +++ b/blag/blag.py @@ -293,6 +293,18 @@ def process_markdown(convertibles, input_dir, output_dir, for src, dst in convertibles: logger.debug(f'Processing {src}') + # see first if the dst actually needs re-building. for that we compare + # the mtimes and assume mtime_dst > mtime_src means that it needs not + # to be rebuilt + if os.path.exists(f'{output_dir}/{dst}'): + mtime_src = os.stat(f'{input_dir}/{src}').st_mtime + mtime_dst = os.stat(f'{output_dir}/{dst}').st_mtime + if mtime_dst >= mtime_src: + logger.debug( + 'Skipping, as target exists and is newer than source.' + ) + continue + with open(f'{input_dir}/{src}', 'r') as fh: body = fh.read()