Source

SCons_ReST / __init__.py

Full commit
import SCons.Builder

from docutils.core import publish_file
from docutils.frontend import Values

def rst2something(target, source, env, validOptions, writer):
    # Find variables that can be passed to docutils.
    settings = dict([item for item in env.items() if item[0] in validOptions])

    # stylesheet and stylesheet_path are mutually exclusive
    if 'stylesheet' in settings:
        settings['stylesheet_path'] = None

    for i in range(len(source)):
        publish_file(source_path=source[i].path,
                     destination_path=target[i].path,
                     writer_name=writer,
                     settings_overrides=settings)


def rst2latex(target, source, env):
    options = ['stylesheet', 'embed_stylesheet']
    rst2something(target, source, env, options, 'latex')
    return None

rst2latexBldr = SCons.Builder.Builder(
    action = rst2latex,
    suffix = '.tex',
    src_suffix = '.rst'
)

def rst2html(target, source, env):
    options = ['stylesheet', 'embed_stylesheet']
    rst2something(target, source, env, options, 'html4css1')
    return None

rst2htmlBldr = SCons.Builder.Builder(
    action = rst2html,
    suffix = '.html',
    src_suffix = '.rst'
)

def generate(env):
    env['BUILDERS']['Rst2Latex'] = rst2latexBldr
    env['BUILDERS']['Rst2Html'] = rst2htmlBldr


def exists(env):
    return env.Detect('rst2latex') or env.Detect('rst2html')