summaryrefslogtreecommitdiff
path: root/boards/generate.py
diff options
context:
space:
mode:
Diffstat (limited to 'boards/generate.py')
-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)