예제 #1
0
def add_ht (dirpath, filenames):
    # Look for content
    filename, msg = build_util.read_content_file(dirpath)
    if msg is None:
        log('Skipping directory without content: %s', dirpath)
        return

    headers = []
    index_yml, nav_yml = build_util.read_yaml_files(dirpath)
    if nav_yml is not None:
	aux = nav_yml.globals.get('aux')
	aux = fix_indented_list(aux)
	if aux and 'Quick-links' not in msg:
	    print 'Adding quicklinks:', dirpath
	    headers.append(('Quick-links', aux))
	nav = nav_yml.globals.get('nav')
	nav = fix_indented_list(nav)
	if nav and 'Nav' not in msg:
	    print 'Adding nav header:', dirpath
	    headers.append(('Nav', nav))

    log('Writing new content.ht file in %s', dirpath)
    ##dirpath = '/tmp'
    f = open(os.path.join(dirpath, 'content.ht'), 'w')
    for hdr, value in msg.items():
	if hdr.lower() in ('nav', 'quick-links'): 
            value = '\n' + value.lstrip('\n')
	f.write('%s: %s\n' % (hdr.capitalize(), value))
    for hdr, value in headers:
	if hdr.lower() in ('nav', 'quick-links'): 
            value = '\n' + value.lstrip('\n')
	f.write('%s: %s\n' % (hdr.capitalize(), value))
    f.write('\n')
    f.write(msg.get_payload())
    f.close()
예제 #2
0
def add_ht (dirpath, filenames):
    # Already has a file -- nothing to do.
    if 'content.ht' in filenames:
        return

    # Look for content
    filename, msg = build_util.read_content_file(dirpath)
    if msg is None:
        log('Skipping directory without content: %s', dirpath)
        return

    if filename.endswith('/content.rst'):
        index_yml, nav_yml = build_util.read_yaml_files(dirpath)
        headers = [('Content-type', 'text/x-rst')]
        if index_yml is not None:
            for hdr in ('title', 'description', 'keywords'):
                v = (index_yml.globals.get(hdr) or
                     index_yml.locals.get(hdr))
                if isinstance(v, basestring):
                    headers.append((hdr, v))

        if nav_yml is not None:
            aux = nav_yml.globals.get('aux')
            aux = fix_indented_list(aux)
            if aux:
                headers.append(('Quick-links', aux))
            nav = nav_yml.globals.get('nav')
            nav = fix_indented_list(nav)
            if nav:
                headers.append(('Nav', nav))
            
        log('Writing new content.ht file in %s', dirpath)
        ##dirpath = '/tmp'
        f = open(os.path.join(dirpath, 'content.ht'), 'w')
        for hdr, value in headers:
            f.write('%s: %s\n' % (hdr.capitalize(), value))
        f.write('\n')
        f.write(msg.get_payload())
        f.close()
예제 #3
0
def rebuild_directory (dirpath, filenames):
    """Generate content for a single directory.

       'dirpath' is the path to the input data; the output
       directory is calculated.
       'filenames' is the list of files in the directory.
    """

    # Figure out the destination path.
    assert dirpath.startswith(options.data)
    rel_path = dirpath[len(options.data):]
    output_dir = os.path.join(options.out, rel_path)
    output_path = os.path.join(output_dir, 'index.html')

    if options.rebuilddirs:
        skip = True
        for rb_dir in options.rebuilddirs:
            if rel_path == rb_dir or rel_path.startswith(rb_dir + '/'):
                skip = False
        if skip:
            log('Skipping directory %s', dirpath, level=3)
            return

    # Split apart the path portion of the URL (e.g. /about/community/)
    # into its components.
    components = rel_path.strip('/').split('/')
    components = filter(None, components)

    filename, msg = build_util.read_content_file(dirpath)
    if msg is None:
        log('Skipping directory without content: %s', dirpath)
        return

    # Create output directory and check dependencies
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
        any_newer = True
        yml_newer = True
    elif not options.cache:
        any_newer = True
        yml_newer = True
    elif must_rebuild(rel_path):
        any_newer = True
        yml_newer = True
    else:
        any_newer, yml_newer = input_newer(
            *get_input_output_files(rel_path, msg))

    # Whenever yml changes, all sub-pages need to be rebuilt too
    if yml_newer:
        _rebuild_cache[rel_path] = 1

    # Copy non-HTML/YML files if they are newer
    for fn in filenames:
        if fn.endswith('~') or fn.endswith('.swp'):
            continue

        base, ext = os.path.splitext(fn)
        if (ext not in ('.rst', '.ht', '.yml') and
            fn not in ('content.html', 'body.html')):

            src_file = os.path.join(dirpath, fn)
            dest_file = os.path.join(output_dir, fn)

            if is_newer(src_file, dest_file):
                log(' Copying file: %s', fn, level=2)
                shutil.copy(src_file, dest_file)
            else:
                log(' File up to date: %s', fn, level=3)

    if not any_newer:
        return

    log('Rebuilding directory %s', dirpath, level=2)
    log(' Output will be written to %s', output_path, level=3)

    kw = {'random':choose_random, 
          'anchorify':anchorify}

    # Read data from YAML files
    try:
        index_yml, nav_yml = build_util.read_yaml_files(dirpath)
    except Exception, exc:
        print "YAML read error on", dirpath, ":", str(exc)
        return