Beispiel #1
0
def get_title(path):
    toc,title = checktoc(os.path.join(path,get_master_doc(path)+'.rst'))
    return title
Beispiel #2
0
def build(path, config, target = 'html',subdoc=None):
    pop_if_exists(os.environ,'XMOSLATEX')
    if target == 'html':
        builder = 'html'
    elif target == 'gh-pages':
        builder = 'html'
    elif target == 'pdf':
        builder = 'xlatex'
    elif target == 'xmospdf':
        builder = 'xlatex'
        os.environ['XMOSLATEX'] = '1'
    elif target == 'xref':
        builder = 'xmos_xref'
        os.environ['XMOSLATEX'] = '1'
    elif target == 'xmoshtml':
        builder = 'xdehtml'
        os.environ['USE_XDEONLY_HTML'] = "0"
    elif target == 'xdehtml':
        builder = 'xdehtml'
        os.environ['USE_XDEONLY_HTML'] = "1"
    elif target == 'xdetutorial':
        builder = 'xdehtml'
        os.environ['USE_XDEONLY_HTML'] = "1"
        os.environ['XDETUTORIAL_HTML'] = "1"
    elif target == 'text':
        builder = 'text'
    elif target == 'xmostext':
        builder = 'xmostext'
    else:
        sys.stderr.write("xdoc: Unknown target %s\n"%target)
        exit(1)

    toc,title = checktoc(config['SPHINX_MASTER_DOC']+".rst",
                         config['OTHER_DOC_DIRS'],
                         path=path)

    if toc == []:
        os.environ['XMOSCOMPACTPDF']='1'
        os.environ['XMOSMANUALPDF']='0'
    else:
        os.environ['XMOSCOMPACTPDF']='0'
        os.environ['XMOSMANUALPDF']='1'

    os.environ['SPHINX_PROJECT_NAME'] = title

    config['TOC'] = toc

    os.environ['COLLECTION'] = ' '.join([x + '__0' for x in toc])



    os.environ['CURRENT_BUILDER'] = builder

    os.environ['OTHER_DOC_DIRS_ABS'] = ' '.join([os.path.abspath(x) for x in config['OTHER_DOC_DIRS']])

    if subdoc:
        os.environ['_SPHINX_MASTER_DOC'] = subdoc
        os.environ['COLLECTION'] = ''
        os.environ['XMOSCOMPACTPDF'] = '1'
    else:
        os.environ['_SPHINX_MASTER_DOC'] = config['SPHINX_MASTER_DOC']

    build_dir = os.path.join(path,"_build",builder)
    if os.path.exists(build_dir):
        shutil.rmtree(build_dir)


    if 'XDEHTML_UNPAGED_OUTPUT' in config:
        os.environ['XDEHTML_UNPAGED_OUTPUT'] = config['XDEHTML_UNPAGED_OUTPUT']
    else:
        os.environ['XDEHTML_UNPAGED_OUTPUT'] = '0'

    if 'SOURCE_SUFFIX' in config:
        os.environ['SOURCE_SUFFIX'] = config['SOURCE_SUFFIX']
    else:
        os.environ['SOURCE_SUFFIX'] = '.rst'

    os.makedirs(build_dir)

    if target == 'xref':
        print "Getting xref info"
    else:
        print "Running Sphinx"

    filt = XSphinxFilter(sys.stdout, sys.stderr, os.path.join(build_dir,'sphinx.output'))
    sys.stdout = filt
    sys.stderr = filt

    sphinx.main(['sphinx-build',
                 '-c',os.path.join(config['XDOC_DIR'],'xsphinx'),
                 '-b',builder,
                 path,
                 os.path.join(path,"_build",builder)])
    sys.stdout, sys.stderr = filt.finish()

    if builder == 'xlatex':
        doLatex(path,
                os.path.join(path,"_build",builder),
                config,
                config['SPHINX_MASTER_DOC'],
                xmoslatex = target in xmos_targets)

    if target in ['xdehtml','xmoshtml','html']:
        print "Removing excess files"
        build_path = os.path.join(path,"_build",builder)
        refs = set()
        fs = [os.path.join(build_path, f) for f in os.listdir(build_path)]
        static_path = os.path.join(build_path,"_static")
        fs += [os.path.join(static_path, f) for f in os.listdir(static_path)]

        html_files = [f for f in fs if f.endswith("html")]
        css_files = [f for f in fs if f.endswith("css")]

        refs = refimage.get_references(html_files, css_files)

        if refs:
            refs.add('list.png')
            image_dir = os.path.join(build_dir,'_static','images')
            static_dir = os.path.join(build_dir,'_static')
            fs = []
            if os.path.exists(image_dir):
                fs +=  [os.path.join(image_dir,f) for f in os.listdir(image_dir)]
            if os.path.exists(static_dir):
                fs += [os.path.join(static_dir,f) for f in os.listdir(static_dir)]
            for f in fs:
                if os.path.isfile(f) and not os.path.basename(f) in refs:
                    os.remove(f)

    if target != 'xref':
        print "Build Complete"