Source

JungleDisk Desktop / man / txt2man.py

Full commit
#! /usr/bin/env python
# encoding: utf-8
# Erik Southworth, 2009, 2010 (s6v)

"""
Waf Tool used by wscripts to build manual pages.
Txt2man will convert text manual pages to groff format using gawk.

Requires:
    txt2man-1.5.7 <http://bitbucket.org/superstition/txt2man/downloads/>

Use filename extensions .man{1,2,3,4,5,6,7,8} section numbers:

Section 1: Commands
Section 2: System calls
Section 3: Library calls
Section 4: Special files (devices)
Section 5: File formats and conventions
Section 6: Games
Section 7: Conventions and misc
Section 8: System management commands

EXAMPLES
    def configure(conf):
        conf.check_tool('txt2man', tooldir='.')

    def build(bld):
        bld.new_task_gen(source='filename.man1p') or
        bld.new_task_gen(source='filename.txt', ext='.1')
"""

from Configure import conftest
from TaskGen import extension
import Task
import Utils

def detect(conf):
    conf.find_txt2man()
    conf.find_gawk()

@conftest
def find_txt2man(conf):
    txt2man = conf.find_program('txt2man', var='TXT2MAN', mandatory=True)
    txt2man = conf.cmd_to_list(txt2man)
    conf.env['TXT2MAN'] = txt2man

@conftest
def find_gawk(conf):
    gawk = conf.find_program('gawk', var='GAWK', mandatory=True)
    gawk = conf.cmd_to_list(gawk)
    conf.env['GAWK'] = gawk

@extension('.man .man0p .man1 .man1p .man2 .man3 .man3p .man4 .man5 .man6 .man7 .man8 .mann')
def process_txt2man(self, node):
    # """use e.g., ext='.1' or if None then the
    # extension is determined by slicing [man:x]."""

    # get srcfile extension
    source = self.source
    k = source.rfind('.')
    if k >= 0:
        ext = source[k:]

    # set new extension and
    # set man section number
    if not hasattr(self, "ext"):
        self.ext = '.' + ext[4:]
        section = ext[4:]
    else:
        section = self.ext[1:]

    name = Utils.g_module.NAME
    version = Utils.g_module.VERSION

    task = self.create_task('txt2man')
    task.env['PACKAGE_STRING'] = name + ' ' + version
    task.env['SECTION'] = section
    task.inputs = [node]
    task.outputs = [node.change_ext(self.ext)]

LINE = '${TXT2MAN} -p -r "${PACKAGE_STRING}" -s ${SECTION} ${SRC} >${TGT}'
Task.simple_task_type('txt2man', LINE, 'BLUE')