summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2021-11-21 17:01:16 +0100
committeremkael <emkael@tlen.pl>2021-11-21 17:01:16 +0100
commit6bb67afa794f6d377657be11b48db7c7b0c4ea8e (patch)
treed28402a0616a64b423a157c1eaf7c48a95071b71
parentfb020853caf99d085340c7efeae046eb8a9beb7c (diff)
Adding PBN/PDF conversion to board WWW generator
-rw-r--r--.envrcbin663 -> 738 bytes
-rw-r--r--boards/.envrcbin37 -> 47 bytes
-rw-r--r--boards/generate.py38
3 files changed, 37 insertions, 1 deletions
diff --git a/.envrc b/.envrc
index 7a7e0e5..561cb19 100644
--- a/.envrc
+++ b/.envrc
Binary files differ
diff --git a/boards/.envrc b/boards/.envrc
index 7750527..4ab70fc 100644
--- a/boards/.envrc
+++ b/boards/.envrc
Binary files differ
diff --git a/boards/generate.py b/boards/generate.py
index 13c7d72..95d5460 100644
--- a/boards/generate.py
+++ b/boards/generate.py
@@ -1,8 +1,42 @@
-import json, sys
+import json, os, re, subprocess, sys
from datetime import datetime
from pathlib import Path
+DEAL_CONVERT_PATH = os.environ.get('LIGA_BOARDS_DEAL_CONVERT_PATH')
+PBN_EVENT_TAG = re.compile('\[Event ".*"\]')
+
+
+def deal_convert(source_file, target_files, params=''):
+ command = 'python2 %s %s %s %s' % (DEAL_CONVERT_PATH, params, source_file, ' '.join(target_files))
+ try:
+ subprocess.check_output(command, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
+ except subprocess.CalledProcessError as ex:
+ print('ERROR: %s' % (ex.output), file=sys.stderr)
+
+
+def ensure_pbn(source_id, config_name, event_name):
+ target_path = Path('output') / config_name / 'files' / (source_id + '.pbn')
+ if target_path.exists():
+ return
+ source_path = Path('pbns') / config_name / (source_id + '.pbn')
+ target_path.parent.mkdir(parents=True, exist_ok=True)
+ deal_convert(str(source_path), [str(target_path)], '--jfr')
+ with open(target_path) as target_file:
+ pbn_content = target_file.read()
+ pbn_content = re.sub(PBN_EVENT_TAG, '[Event "%s"]' % (event_name), pbn_content)
+ with open(target_path, 'w') as target_file:
+ target_file.write(pbn_content)
+
+
+def ensure_pdf(source_id, config_name):
+ target_path = Path('output') / config_name / 'files' / (source_id + '.pdf')
+ if target_path.exists():
+ return
+ source_path = Path('output') / config_name / 'files' / (source_id + '.pbn')
+ deal_convert(str(source_path), [str(target_path)])
+
+
config_dir = Path('config')
for config_path in config_dir.glob('*.json'):
config_name = config_path.stem
@@ -22,6 +56,8 @@ for config_path in config_dir.glob('*.json'):
set_content = '<tr><td class="bdcc1" colspan="3">%s</td></tr>' % (dealset['title'])
for pbn in dealset['files']:
if pbn.get('enabled', 0):
+ ensure_pbn(pbn['path'], config_name, pbn['title'])
+ ensure_pdf(pbn['path'], config_name)
set_enabled = True
set_content += '<tr>'
set_content += '<td class="bd1">%s</td>' % (pbn['name'])