From bf2d556e4b3a1527bfdbaa2431b3ea56ebdadc0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 12 Aug 2013 14:36:28 +0200 Subject: [PATCH] add rough pdf transformation --- publish.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/publish.py b/publish.py index bd081f1..b07489f 100755 --- a/publish.py +++ b/publish.py @@ -2,8 +2,10 @@ import json import os +import shutil import subprocess import tarfile +import tempfile import urllib2 import urlparse @@ -74,6 +76,42 @@ def publish_mallard(module, branch, directory): if html_files: os.symlink(html_files[0], index_html) + if not os.path.exists('../mal2latex'): + return + + temp_dir = tempfile.mkdtemp() + cache_file = os.path.join(temp_dir, '%s.cache' % module) + cmd = ['jhbuild', '-f', jhbuildrc, 'run', 'yelp-build', 'cache', '-o', cache_file] + cmd.extend([os.path.join(help_dir, x) for x in os.listdir(help_dir) if x.endswith('.page')]) + subprocess.call(cmd, **kws) + + if os.path.exists(cache_file): + latex_file = os.path.join(temp_dir, 'doc-%s.tex' % module) + cmd = ['xsltproc', '-o', latex_file, '../mal2latex/mal2latex.xsl', + cache_file] + subprocess.call(cmd, **kws) + for subdir in ('media', 'figures'): + os.symlink(os.path.join(checkout_dir, 'help', 'fr', subdir), + os.path.join(temp_dir, subdir)) + for admon_file in os.listdir('../mal2latex/admon'): + if not admon_file.endswith('.pdf'): + continue + os.symlink(os.path.join(os.path.abspath('../mal2latex'), 'admon', admon_file), + os.path.join(temp_dir, admon_file)) + + for i in range(3): + cmd = ['pdflatex', '--interaction=nonstopmode', + '-output-directory', temp_dir, latex_file] + subprocess.call(cmd, cwd=temp_dir, **kws) + if not os.path.exists(os.path.join(temp_dir, 'doc-%s.pdf' % module)): + print 'failed to produce pdf for', module + break + else: + fd = file(os.path.join(output_dir, 'doc-%s.pdf' % module), 'w') + fd.write(file(os.path.join(temp_dir, 'doc-%s.pdf' % module)).read()) + fd.close() + + shutil.rmtree(temp_dir) def publish_tarball(module): output_dir = os.path.join(web_directory, module.get('name'), 'stable')