From 4acf06b16e758e5f201be5ff1bc77c27a906bca8 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 22 Feb 2022 13:28:04 +0100 Subject: Better up-to-date checks for generating board files --- boards/generate.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/boards/generate.py b/boards/generate.py index 33ae4fd..d4c8ac3 100644 --- a/boards/generate.py +++ b/boards/generate.py @@ -16,13 +16,24 @@ def deal_convert(source_file, target_files, params=''): print('ERROR: %s' % (ex.output), file=sys.stderr) +def check_path(target_path, source_paths): + source_mtime = max([path.stat().st_mtime for path in source_paths]) + if target_path.exists(): + if source_mtime <= target_path.stat().st_mtime: + return True + print('Target path %s older than source, regenerating' % (target_path), file=sys.stderr) + target_path.unlink() + else: + print('Target path %s does not exist, generating' % (target_path), file=sys.stderr) + target_path.parent.mkdir(parents=True, exist_ok=True) + return False + + def ensure_pbn(source_id, config_name, event_name): target_path = Path('output') / config_name / 'files' / (source_id + '.pbn') - if target_path.exists(): - return target_path - print('Target path %s does not exist, generating' % (target_path), file=sys.stderr) source_path = Path('pbns') / config_name / (source_id + '.pbn') - target_path.parent.mkdir(parents=True, exist_ok=True) + if check_path(target_path, [source_path]): + return target_path deal_convert(str(source_path), [str(target_path)], '--jfr') with open(target_path) as target_file: pbn_content = target_file.read() @@ -34,21 +45,19 @@ def ensure_pbn(source_id, config_name, event_name): def ensure_pdf(source_id, config_name): target_path = Path('output') / config_name / 'files' / (source_id + '.pdf') - if target_path.exists(): - return target_path - print('Target path %s does not exist, generating' % (target_path), file=sys.stderr) source_path = Path('output') / config_name / 'files' / (source_id + '.pbn') - target_path.parent.mkdir(parents=True, exist_ok=True) + if check_path(target_path, [source_path]): + return target_path deal_convert(str(source_path), [str(target_path)]) return target_path def ensure_zip(source_id, config_name, source_files): target_path = Path('output') / config_name / 'files' / (source_id + '.zip') - if target_path.exists(): + source_paths = [Path(path) for path in source_files] + if check_path(target_path, source_paths): + # TODO: check if file list haven't changed return target_path - print('Target path %s does not exist, generating' % (target_path), file=sys.stderr) - target_path.parent.mkdir(parents=True, exist_ok=True) with ZipFile(target_path, 'w') as zip_file: for source_file in source_files: zip_file.write(source_file, arcname=source_file.name) -- cgit v1.2.3