2020-04-22 18:56:05 +02:00
|
|
|
#! /usr/bin/python3 -B
|
|
|
|
|
|
|
|
import os
|
2020-04-27 04:25:41 +02:00
|
|
|
import shutil
|
2020-04-22 18:56:05 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
DOCUMENTS = [
|
|
|
|
'document',
|
|
|
|
'présentation',
|
|
|
|
]
|
2020-04-27 04:25:41 +02:00
|
|
|
TMP = 'tmp'
|
2020-04-22 18:56:05 +02:00
|
|
|
|
|
|
|
|
2020-05-01 19:24:37 +02:00
|
|
|
def run(command):
|
|
|
|
subprocess.call(command)
|
|
|
|
|
|
|
|
|
|
|
|
def errun(command):
|
|
|
|
return subprocess.check_output(
|
|
|
|
command, stderr=subprocess.STDOUT)
|
2020-04-27 00:39:49 +02:00
|
|
|
|
|
|
|
|
2020-04-27 04:25:41 +02:00
|
|
|
def build():
|
2020-04-22 18:56:05 +02:00
|
|
|
for document in DOCUMENTS:
|
2020-04-27 04:25:41 +02:00
|
|
|
command = ['xelatex',
|
|
|
|
'-output-directory', TMP,
|
|
|
|
document,
|
|
|
|
]
|
|
|
|
run(command)
|
|
|
|
run(['makeglossaries',
|
|
|
|
'-d', TMP,
|
|
|
|
document,
|
|
|
|
])
|
2020-04-27 22:52:32 +02:00
|
|
|
run(['biber',
|
|
|
|
'--input-directory', TMP,
|
|
|
|
'--output-directory', TMP,
|
|
|
|
document,
|
|
|
|
])
|
2020-04-27 04:25:41 +02:00
|
|
|
run(command)
|
2020-04-28 01:39:51 +02:00
|
|
|
run(command)
|
2020-04-27 04:25:41 +02:00
|
|
|
pdf = f'{document}.pdf'
|
2020-05-01 16:40:56 +02:00
|
|
|
run(['gpg',
|
|
|
|
'--armor',
|
2020-05-01 17:02:46 +02:00
|
|
|
'--detach-sign',
|
|
|
|
os.path.join(TMP, pdf),
|
2020-05-01 16:40:56 +02:00
|
|
|
])
|
2020-05-01 16:55:42 +02:00
|
|
|
signature = f'{pdf}.asc'
|
|
|
|
for f in [pdf, signature]:
|
|
|
|
os.rename(os.path.join(TMP, f), f)
|
2020-05-01 19:37:12 +02:00
|
|
|
lines = errun(['gpg',
|
2020-05-01 19:24:37 +02:00
|
|
|
'--verify', signature, pdf,
|
2020-05-01 19:37:12 +02:00
|
|
|
]).decode('u8').splitlines()
|
2020-05-01 19:44:17 +02:00
|
|
|
using = lines[1].index('using')
|
2020-05-01 20:29:48 +02:00
|
|
|
id = lines[2].index('"')
|
|
|
|
lines = [
|
|
|
|
lines[0][:using] + lines[1][using:],
|
|
|
|
lines[2][:id] + lines[4][id:]
|
|
|
|
.replace('@', ' @ ')
|
|
|
|
.replace('.', ' ⋅ ')
|
|
|
|
] + lines[5:]
|
2020-05-01 19:37:12 +02:00
|
|
|
buffer = os.linesep.join(lines).encode('u8')
|
2020-05-01 19:24:37 +02:00
|
|
|
with open(f'{pdf}.vrf', 'bw') as f:
|
|
|
|
f.write(buffer)
|
2020-04-22 18:56:05 +02:00
|
|
|
|
|
|
|
|
2020-04-27 04:25:41 +02:00
|
|
|
def clean():
|
|
|
|
shutil.rmtree(TMP, ignore_errors=True)
|
2020-04-22 18:56:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
file = os.path.realpath(__file__)
|
|
|
|
directory = os.path.dirname(file)
|
2020-04-27 04:25:41 +02:00
|
|
|
os.chdir(directory)
|
|
|
|
clean()
|
|
|
|
os.makedirs(TMP)
|
|
|
|
build()
|
|
|
|
clean()
|
2020-04-22 18:56:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|