builds
This commit is contained in:
parent
641fc45fe0
commit
e0bfb62203
5 changed files with 77 additions and 39 deletions
|
@ -5,13 +5,14 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
ENGLISH='en'
|
ENGLISH = 'en'
|
||||||
FRENCH='fr'
|
FRENCH = 'fr'
|
||||||
LANGUAGES = [ENGLISH, FRENCH]
|
LANGUAGES = [ENGLISH, FRENCH]
|
||||||
DOCUMENTS = [
|
DOCUMENTS = [
|
||||||
{ENGLISH: 'thesis', FRENCH: 'mémoire'},
|
{ENGLISH: 'thesis', FRENCH: 'mémoire'},
|
||||||
# {ENGLISH: 'presentation', FRENCH: 'présentation'},
|
{ENGLISH: 'presentation', FRENCH: 'présentation'},
|
||||||
]
|
]
|
||||||
|
MAIN = 'main'
|
||||||
TMP = 'tmp'
|
TMP = 'tmp'
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,37 +25,69 @@ def errun(command):
|
||||||
command, stderr=subprocess.STDOUT)
|
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 language in LANGUAGES:
|
||||||
|
# for each document
|
||||||
for document in DOCUMENTS:
|
for document in DOCUMENTS:
|
||||||
command = ['xelatex', '-output-directory', TMP, document[ENGLISH]]
|
# clean
|
||||||
if document['en'] == 'thesis':
|
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(command)
|
||||||
run(['makeglossaries', '-d', TMP, document[ENGLISH]])
|
# build glossaries
|
||||||
|
run(['makeglossaries', '-d', tmp, document[ENGLISH]])
|
||||||
|
# build references
|
||||||
run(['biber',
|
run(['biber',
|
||||||
'--input-directory', TMP,
|
'--input-directory', tmp,
|
||||||
'--output-directory', TMP,
|
'--output-directory', tmp,
|
||||||
document['en'],
|
MAIN,
|
||||||
])
|
])
|
||||||
|
# re build
|
||||||
run(command)
|
run(command)
|
||||||
|
# final build
|
||||||
run(command)
|
run(command)
|
||||||
pdf = f'{document[FRENCH]}.pdf'
|
# rename the document
|
||||||
os.rename(os.path.join(TMP, f'{document[ENGLISH]}.pdf'),
|
pdf = f'{document[language]}.pdf'
|
||||||
os.path.join(TMP, pdf))
|
os.rename(os.path.join(tmp, f'{MAIN}.pdf'),
|
||||||
|
os.path.join(tmp, pdf),
|
||||||
|
)
|
||||||
|
# if signature is disabled
|
||||||
if not sign:
|
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:
|
else:
|
||||||
|
# sign the document
|
||||||
run(['gpg',
|
run(['gpg',
|
||||||
'--armor',
|
'--armor',
|
||||||
'--detach-sign',
|
'--detach-sign',
|
||||||
os.path.join(TMP, pdf),
|
os.path.join(tmp, pdf),
|
||||||
])
|
])
|
||||||
signature = f'{pdf}.asc'
|
signature = f'{pdf}.asc'
|
||||||
|
# fetch the document and signature from temporary directory
|
||||||
for f in [pdf, signature]:
|
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',
|
lines = errun(['gpg',
|
||||||
'--verify', signature, pdf,
|
'--verify', signature, pdf,
|
||||||
]).decode('u8').splitlines()
|
]).decode('u8').splitlines()
|
||||||
id = lines[2].index('"')
|
id = lines[2].index('"')
|
||||||
lines = [
|
lines = [
|
||||||
lines[0],
|
lines[0],
|
||||||
|
@ -63,23 +96,22 @@ def build(sign):
|
||||||
.replace('@', ' @ ')
|
.replace('@', ' @ ')
|
||||||
.replace('.', ' ⋅ ')
|
.replace('.', ' ⋅ ')
|
||||||
] + lines[5:]
|
] + lines[5:]
|
||||||
|
# write verification file
|
||||||
buffer = os.linesep.join(lines).encode('u8')
|
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)
|
f.write(buffer)
|
||||||
|
# clean
|
||||||
|
wipe(tmp)
|
||||||
|
|
||||||
|
|
||||||
def clean():
|
def wipe(directory):
|
||||||
shutil.rmtree(TMP, ignore_errors=True)
|
shutil.rmtree(directory, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
file = os.path.realpath(__file__)
|
file = os.path.realpath(__file__)
|
||||||
directory = os.path.dirname(file)
|
directory = os.path.dirname(file)
|
||||||
os.chdir(directory)
|
build(directory, len(sys.argv) == 1)
|
||||||
clean()
|
|
||||||
os.makedirs(TMP)
|
|
||||||
build(len(sys.argv) == 1)
|
|
||||||
clean()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
7
cnam/travaux/mémoire/presentation/main.tex
Normal file
7
cnam/travaux/mémoire/presentation/main.tex
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
\input{settings}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
…
|
||||||
|
|
||||||
|
\end{document}
|
1
cnam/travaux/mémoire/presentation/settings.tex
Normal file
1
cnam/travaux/mémoire/presentation/settings.tex
Normal file
|
@ -0,0 +1 @@
|
||||||
|
\documentclass[12pt]{extarticle}
|
|
@ -1,9 +0,0 @@
|
||||||
\newcommand{\import}[1]{\input{thesis/#1}}
|
|
||||||
|
|
||||||
\import{settings}
|
|
||||||
|
|
||||||
\begin{document}
|
|
||||||
|
|
||||||
…
|
|
||||||
|
|
||||||
\end{document}
|
|
7
cnam/travaux/mémoire/thesis/main.tex
Normal file
7
cnam/travaux/mémoire/thesis/main.tex
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
\input{settings}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
…
|
||||||
|
|
||||||
|
\end{document}
|
Loading…
Add table
Add a link
Reference in a new issue