build/sign

This commit is contained in:
Marc Beninca 2020-05-02 03:25:03 +02:00
parent 6e92d619fa
commit d505187624

View file

@ -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()