From abe13f4e73c2e15b26ef9fa3334e88ad97c5a126 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Mon, 8 Mar 2021 21:59:45 +0100 Subject: Move all programs into a single file This means we do not need to keep track of their order out-of-band, and it will allow members to edit them without me whipping up an ad-hoc file-upload dialog on the admin page. --- build-programs.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'build-programs.py') diff --git a/build-programs.py b/build-programs.py index 513abbe..69c7057 100755 --- a/build-programs.py +++ b/build-programs.py @@ -1,28 +1,22 @@ #!/usr/bin/env python3 import html -from pathlib import Path import re from subprocess import run -def read_programs(plist): - with open(plist) as l: - return tuple(Path('programs', p.strip()) for p in l) - - PROGRAM_RE = re.compile('\n'.join(( - 'NOM : (?P.+)', - 'COMPOSITEURS : (?P.+)', + r'NOM : (?P[^\n]+)', + r'COMPOSITEURS : (?P[^\n]+)', 'DESCRIPTION :', - '(?P.+)', + '(?P.+?)', 'MORCEAUX :', - '(?P.+)' + r'(?P(?:- [^\n]+\n)*- [^\n]+)' )), flags=re.DOTALL) -def parse(filename): - with open(filename) as program: - return PROGRAM_RE.match(program.read()).groupdict() +def read_programs(programs): + with open(programs) as f: + return tuple(re.finditer(PROGRAM_RE, f.read())) BLOCK_TEMPLATE = '''\ @@ -45,24 +39,23 @@ def piece(p): return '
  • entracte
  • ' return f'
  • {html.escape(p)}
  • ' -def print_program(filename): - info = parse(filename) - +def print_program(info): info['description'] = run( ('pandoc',), input=info['description'], capture_output=True, text=True, check=True ).stdout info['pieces'] = '\n'.join( - piece(p) for p in info['pieces'].splitlines() + piece(p[2:]) # Assume p.startswith('- '). + for p in info['pieces'].splitlines() ) print(BLOCK_TEMPLATE.format_map(info)) def main(): - for p in read_programs('programs/programs.list'): - print_program(p) + for p in read_programs('programs.in'): + print_program(p.groupdict()) if __name__ == '__main__': -- cgit v1.2.3