Browse Source

Using the document makefile instead of hard-coded commands

master
Youen 2 years ago
parent
commit
661cd32f95
  1. 18
      src/data/document.py
  2. 3
      src/templates/admin/document/manage.html

18
src/data/document.py

@ -62,18 +62,13 @@ class Document:
cmd.append(['git', 'pull']) cmd.append(['git', 'pull'])
# build the HTML version # build the HTML version
cmd.append(['sphinx-build', '-M', 'html', self.doc_path + "/repo/source", self.doc_path + "/build"]) cmd.append(['make', 'html', 'BUILDDIR=../build'])
# build the PDF version # build the PDF version
cmd.append(['sphinx-build', '-M', 'weasyprint', self.doc_path + '/repo/source', self.doc_path + '/build']) cmd.append(['make', 'pdf', 'BUILDDIR=../build'])
cmd.append(['weasyprint', self.doc_path + '/build/weasyprint/index.html', self.doc_path + '/build/weasyprint/index.pdf', '-s', self.doc_path + '/repo/source/css/print-theme.css'])
cmd.append(['sh', '-c', current_app.config['DATA_ROOT_DIR'] + '/../pdftoc-to-latex "' + self.doc_path + '/build/weasyprint/index.pdf" > "' + self.doc_path + '/build/weasyprint/toc.tex"'])
cmd.append(['sh', '-c', 'pdflatex -interaction nonstopmode -output-directory="' + self.doc_path + '/build/weasyprint" "' + self.doc_path + '/build/weasyprint/toc.tex" || echo OK'])
cmd.append(['pdftk', 'A=' + self.doc_path + '/build/weasyprint/index.pdf', 'B=' + self.doc_path + '/build/weasyprint/toc.pdf', 'cat', 'A1', 'B', 'A2-end', 'output', self.doc_path + '/build/weasyprint/vheliotech.pdf'])
#cmd.append(['rm', self.doc_path + '/build/weasyprint/index.pdf', self.doc_path + '/build/weasyprint/toc.tex', self.doc_path + '/build/weasyprint/toc.pdf', self.doc_path + '/build/weasyprint/GuidedemontageVheliotech.pdf'])
# Copy the generated PDF file to the HTML directory, so that it is accessible for download by users # Copy the generated PDF file to the HTML directory, so that it is accessible for download by users
cmd.append(['cp', self.doc_path + '/build/weasyprint/vheliotech.pdf', self.doc_path + '/build/html/guide-de-montage-vheliotech.pdf']) cmd.append(['cp', self.doc_path + '/build/weasyprint/vheliotech.pdf', self.doc_path + '/build/html/' + self.doc_name + '.pdf'])
task = ProcessTask(cmd, cwd = self.doc_path + "/repo") task = ProcessTask(cmd, cwd = self.doc_path + "/repo")
task.start() task.start()
@ -98,6 +93,9 @@ class Document:
def get_url(self): def get_url(self):
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html" return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html"
def get_pdf_url(self):
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.doc_name + ".pdf"
def get_api_key(self): def get_api_key(self):
with open(self.doc_path + "/apikey") as f: with open(self.doc_path + "/apikey") as f:
return f.read().replace('\n', '') return f.read().replace('\n', '')
@ -151,8 +149,8 @@ class Document:
cmd = [] cmd = []
cmd.append(['git', 'init', '--initial-branch=' + branch]) cmd.append(['git', 'init', '--initial-branch=' + branch])
cmd.append(['git', 'remote', 'add', '-f', 'origin', repo]) cmd.append(['git', 'remote', 'add', '-f', 'origin', repo])
cmd.append(['git', 'sparse-checkout', 'init']) #cmd.append(['git', 'sparse-checkout', 'init'])
cmd.append(['git', 'sparse-checkout', 'set', source_dir]) #cmd.append(['git', 'sparse-checkout', 'set', source_dir])
cmd.append(['git', 'pull', 'origin', branch]) cmd.append(['git', 'pull', 'origin', branch])
cmd.append(['git', 'branch', '--set-upstream-to=origin/' + branch, branch]) cmd.append(['git', 'branch', '--set-upstream-to=origin/' + branch, branch])

3
src/templates/admin/document/manage.html

@ -5,7 +5,8 @@
{% block content %} {% block content %}
<h1>Gestion de {{ doc.origin }} / {{ doc.doc_name }} / {{ doc.branch }}</h1> <h1>Gestion de {{ doc.origin }} / {{ doc.doc_name }} / {{ doc.branch }}</h1>
<p>URL permettant de déclencher la compilation : {{ url_for('api_document.build', origin = doc.encoded_origin, doc_name = doc.doc_name, branch = doc.branch, apikey = doc.get_api_key(), _external = True) }}</p> <p>URL permettant de déclencher la compilation : {{ url_for('api_document.build', origin = doc.encoded_origin, doc_name = doc.doc_name, branch = doc.branch, apikey = doc.get_api_key(), _external = True) }}</p>
<a href="{{doc.get_url()}}" class="button">Consulter</a><br/> <a href="{{doc.get_url()}}" class="button">Consulter en HTML</a><br/>
<a href="{{doc.get_pdf_url()}}" class="button">Consulter le PDF</a><br/>
<a href="{{ url_for('admin_document.build', origin = doc.encoded_origin, doc_name = doc.doc_name, branch = doc.branch) }}" class="button">Compiler</a><br/> <a href="{{ url_for('admin_document.build', origin = doc.encoded_origin, doc_name = doc.doc_name, branch = doc.branch) }}" class="button">Compiler</a><br/>
<br/> <br/>
<a href="{{ url_for('admin_document.delete', origin = doc.encoded_origin, doc_name = doc.doc_name, branch = doc.branch) }}" class="button danger" data-confirm="Êtes-vous sûr de vouloir supprimer le document {{ doc.doc_name }} / {{ doc.branch }} ?">Supprimer</a> <a href="{{ url_for('admin_document.delete', origin = doc.encoded_origin, doc_name = doc.doc_name, branch = doc.branch) }}" class="button danger" data-confirm="Êtes-vous sûr de vouloir supprimer le document {{ doc.doc_name }} / {{ doc.branch }} ?">Supprimer</a>

Loading…
Cancel
Save