fabscript 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- python -*-
  2. #
  3. # Copyright (c) 2016 Stefan Seefeld
  4. # All rights reserved.
  5. #
  6. # Distributed under the Boost Software License, Version 1.0.
  7. # (See accompanying file LICENSE_1_0.txt or copy at
  8. # http://www.boost.org/LICENSE_1_0.txt)
  9. from faber.tools.xslt import xsltflags
  10. from faber.tools.boost import quickbook, boostbook
  11. from faber.artefacts import html
  12. from glob import glob as G
  13. from os import makedirs
  14. from os.path import relpath, dirname, exists
  15. from shutil import copyfile
  16. def glob(pattern):
  17. prefix = srcdir + '/'
  18. p = len(prefix)+1
  19. return [f[p:] for f in G(prefix + pattern)]
  20. class make_html(action):
  21. def __init__(self):
  22. action.__init__(self, 'make_html', self.process)
  23. def map(self, fs):
  24. return boostbook.html.map(fs)
  25. def process(self, target, source):
  26. boostbook.html(target, source[0:1])
  27. for s in source[1:]:
  28. t = target[0]._filename + relpath(s._filename, srcdir)
  29. d = dirname(t)
  30. if not exists(d):
  31. makedirs(d)
  32. copyfile(s._filename, t)
  33. sphinx_build = action('sphinx-build', 'sphinx-build -b html $(>) $(<)')
  34. rst2html = action('rst2html', 'rst2html --trim-footnote-reference-space --footnote-references=superscript --stylesheet=$(>:D)/rst.css $(>) $(<)')
  35. python_bbk = rule(quickbook.process, 'python.bbk', 'python.qbk',
  36. dependencies=['release_notes.qbk',
  37. 'building.qbk',
  38. 'configuration.qbk',
  39. 'suport.qbk',
  40. 'faq.qbk',
  41. 'glossary.qbk'])
  42. tutorial_bbk = rule(quickbook.process, 'tutorial.bbk', 'tutorial.qbk')
  43. reference_bbk = rule(quickbook.process, 'reference.bbk', 'reference.qbk')
  44. python_db = rule(boostbook.db, 'python.db', python_bbk)
  45. tutorial_db = rule(boostbook.db, 'tutorial.db', tutorial_bbk)
  46. reference_db = rule(boostbook.db, 'reference.db', reference_bbk)
  47. python = html.dir(make_html(), 'html', [python_db, 'boostbook.css'] + glob('/images/*.*') + glob('/images/callouts/*.*'),
  48. features=xsltflags('--stringparam generate.toc "library nop; chaper toc; section toc;"',
  49. '--stringparam html.stylesheet boostbook.css',
  50. '--stringparam boost.image.src images/bpl.png',
  51. '--stringparam boost.graphics.root images/',
  52. '--stringparam boost.defaults none',
  53. '--param toc.max.depth 3',
  54. '--param toc.section.depth 2',
  55. '--param chunk.section.depth 1'))
  56. tutorial = html.dir(boostbook.html, 'html/tutorial', tutorial_db, dependencies=[python],
  57. features=xsltflags('--stringparam html.stylesheet ../boostbook.css',
  58. '--stringparam boost.image.src ../images/bpl.png',
  59. '--stringparam boost.graphics.root ../images/'))
  60. reference = html.dir(boostbook.html, 'html/reference', reference_db, dependencies=[python],
  61. features=xsltflags('--stringparam html.stylesheet ../boostbook.css',
  62. '--stringparam boost.image.src ../images/bpl.png',
  63. '--stringparam boost.graphics.root ../images/'))
  64. numpy = rule(sphinx_build, 'html/numpy', 'numpy', attrs=always, dependencies=[python])
  65. article = rule(rst2html, 'html/article.html', 'article.rst')
  66. html = alias('html', [python, tutorial, reference, numpy, article])
  67. default = html