diff --git a/cnam/travaux/mémoire/build.py b/cnam/travaux/mémoire/build.py index b11e0b1..9e89442 100755 --- a/cnam/travaux/mémoire/build.py +++ b/cnam/travaux/mémoire/build.py @@ -5,13 +5,14 @@ import shutil import subprocess import sys -ENGLISH='en' -FRENCH='fr' +ENGLISH = 'en' +FRENCH = 'fr' LANGUAGES = [ENGLISH, FRENCH] DOCUMENTS = [ {ENGLISH: 'thesis', FRENCH: 'mémoire'}, - # {ENGLISH: 'presentation', FRENCH: 'présentation'}, + {ENGLISH: 'presentation', FRENCH: 'présentation'}, ] +MAIN = 'main' TMP = 'tmp' @@ -24,37 +25,69 @@ def errun(command): command, stderr=subprocess.STDOUT) -def build(sign): +def build(directory, sign): + # temporary directory + tmp = os.path.join(directory, TMP) + # for each language for language in LANGUAGES: + # for each document for document in DOCUMENTS: - command = ['xelatex', '-output-directory', TMP, document[ENGLISH]] - if document['en'] == 'thesis': + # clean + os.chdir(directory) + wipe(tmp) + os.makedirs(tmp) + # move into document directory + os.chdir(document[ENGLISH]) + # prepare build command + command = ['xelatex', + '-output-directory', tmp, + MAIN, + ] + # if it's the main document + if document[ENGLISH] == 'thesis': + # pre build run(command) - run(['makeglossaries', '-d', TMP, document[ENGLISH]]) + # build glossaries + run(['makeglossaries', '-d', tmp, document[ENGLISH]]) + # build references run(['biber', - '--input-directory', TMP, - '--output-directory', TMP, - document['en'], - ]) + '--input-directory', tmp, + '--output-directory', tmp, + MAIN, + ]) + # re build run(command) + # final build run(command) - pdf = f'{document[FRENCH]}.pdf' - os.rename(os.path.join(TMP, f'{document[ENGLISH]}.pdf'), - os.path.join(TMP, pdf)) + # rename the document + pdf = f'{document[language]}.pdf' + os.rename(os.path.join(tmp, f'{MAIN}.pdf'), + os.path.join(tmp, pdf), + ) + # if signature is disabled if not sign: - os.rename(os.path.join(TMP, pdf), pdf) + # fetch the document from temporary directory + os.rename(os.path.join(tmp, pdf), + os.path.join(directory, pdf), + ) + # if signature is enabled else: + # sign the document run(['gpg', - '--armor', - '--detach-sign', - os.path.join(TMP, pdf), - ]) + '--armor', + '--detach-sign', + os.path.join(tmp, pdf), + ]) signature = f'{pdf}.asc' + # fetch the document and signature from temporary directory for f in [pdf, signature]: - os.rename(os.path.join(TMP, f), f) + os.rename(os.path.join(tmp, f), + os.path.join(directory, f), + ) + # verify the document signature lines = errun(['gpg', - '--verify', signature, pdf, - ]).decode('u8').splitlines() + '--verify', signature, pdf, + ]).decode('u8').splitlines() id = lines[2].index('"') lines = [ lines[0], @@ -63,23 +96,22 @@ def build(sign): .replace('@', ' @ ') .replace('.', ' ⋅ ') ] + lines[5:] + # write verification file buffer = os.linesep.join(lines).encode('u8') - with open(f'{pdf}.vrf', 'bw') as f: + with open(os.path.join(directory, f'{pdf}.vrf'), 'bw') as f: f.write(buffer) + # clean + wipe(tmp) -def clean(): - shutil.rmtree(TMP, ignore_errors=True) +def wipe(directory): + shutil.rmtree(directory, ignore_errors=True) def main(): file = os.path.realpath(__file__) directory = os.path.dirname(file) - os.chdir(directory) - clean() - os.makedirs(TMP) - build(len(sys.argv) == 1) - clean() + build(directory, len(sys.argv) == 1) if __name__ == '__main__': diff --git a/cnam/travaux/mémoire/presentation/main.tex b/cnam/travaux/mémoire/presentation/main.tex new file mode 100644 index 0000000..eaacd90 --- /dev/null +++ b/cnam/travaux/mémoire/presentation/main.tex @@ -0,0 +1,7 @@ +\input{settings} + +\begin{document} + +… + +\end{document} diff --git a/cnam/travaux/mémoire/presentation/settings.tex b/cnam/travaux/mémoire/presentation/settings.tex new file mode 100644 index 0000000..cb1a5cf --- /dev/null +++ b/cnam/travaux/mémoire/presentation/settings.tex @@ -0,0 +1 @@ +\documentclass[12pt]{extarticle} diff --git a/cnam/travaux/mémoire/thesis.tex b/cnam/travaux/mémoire/thesis.tex deleted file mode 100644 index 69075b7..0000000 --- a/cnam/travaux/mémoire/thesis.tex +++ /dev/null @@ -1,9 +0,0 @@ -\newcommand{\import}[1]{\input{thesis/#1}} - -\import{settings} - -\begin{document} - -… - -\end{document} diff --git a/cnam/travaux/mémoire/thesis/main.tex b/cnam/travaux/mémoire/thesis/main.tex new file mode 100644 index 0000000..eaacd90 --- /dev/null +++ b/cnam/travaux/mémoire/thesis/main.tex @@ -0,0 +1,7 @@ +\input{settings} + +\begin{document} + +… + +\end{document}