From d505187624bdf780446315e19b12bc2c91b9878f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 2 May 2020 03:25:03 +0200 Subject: [PATCH] build/sign --- cnam/travaux/blanc/build.py | 52 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/cnam/travaux/blanc/build.py b/cnam/travaux/blanc/build.py index 465b924..2f924e2 100755 --- a/cnam/travaux/blanc/build.py +++ b/cnam/travaux/blanc/build.py @@ -3,6 +3,7 @@ import os import shutil import subprocess +import sys DOCUMENTS = [ ('document', 'mémoire'), @@ -20,7 +21,7 @@ def errun(command): command, stderr=subprocess.STDOUT) -def build(): +def build(sign): for en, fr in DOCUMENTS: command = ['xelatex', '-output-directory', TMP, @@ -40,29 +41,30 @@ def build(): run(command) os.rename(os.path.join(TMP, f'{en}.pdf'), os.path.join(TMP, f'{fr}.pdf')) - pdf = f'{fr}.pdf' - run(['gpg', - '--armor', - '--detach-sign', - os.path.join(TMP, pdf), - ]) - signature = f'{pdf}.asc' - for f in [pdf, signature]: - os.rename(os.path.join(TMP, f), f) - lines = errun(['gpg', - '--verify', signature, pdf, - ]).decode('u8').splitlines() - using = lines[1].index('using') - id = lines[2].index('"') - lines = [ - lines[0][:using] + lines[1][using:], - lines[2][:id] + lines[4][id:] - .replace('@', ' @ ') - .replace('.', ' ⋅ ') - ] + lines[5:] - buffer = os.linesep.join(lines).encode('u8') - with open(f'{pdf}.vrf', 'bw') as f: - f.write(buffer) + if sign: + pdf = f'{fr}.pdf' + run(['gpg', + '--armor', + '--detach-sign', + os.path.join(TMP, pdf), + ]) + signature = f'{pdf}.asc' + for f in [pdf, signature]: + os.rename(os.path.join(TMP, f), f) + lines = errun(['gpg', + '--verify', signature, pdf, + ]).decode('u8').splitlines() + using = lines[1].index('using') + id = lines[2].index('"') + lines = [ + lines[0][:using] + lines[1][using:], + lines[2][:id] + lines[4][id:] + .replace('@', ' @ ') + .replace('.', ' ⋅ ') + ] + lines[5:] + buffer = os.linesep.join(lines).encode('u8') + with open(f'{pdf}.vrf', 'bw') as f: + f.write(buffer) def clean(): @@ -75,7 +77,7 @@ def main(): os.chdir(directory) clean() os.makedirs(TMP) - build() + build(len(sys.argv) == 1) clean()