builds
This commit is contained in:
parent
641fc45fe0
commit
e0bfb62203
5 changed files with 77 additions and 39 deletions
|
@ -10,8 +10,9 @@ 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,34 +25,66 @@ 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),
|
||||
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()
|
||||
|
@ -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__':
|
||||
|
|
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