summaryrefslogtreecommitdiff
path: root/boards
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2022-02-22 13:28:04 +0100
committeremkael <emkael@tlen.pl>2022-02-22 13:30:34 +0100
commit4acf06b16e758e5f201be5ff1bc77c27a906bca8 (patch)
tree57b25d3fa7717b5b6cef5238999c2c8938229d73 /boards
parent7aaa7c674aa92d544416e2d241808de99b67ead9 (diff)
Better up-to-date checks for generating board files
Diffstat (limited to 'boards')
-rw-r--r--boards/generate.py31
1 files 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)