Exemple #1
0
def doc_module(module_name):
    """generates the documentation page for the specified module"""
    print "doc_module: ", module_name
    try:
        mod = ensure_modpath_installed(module_name)
        testagent.load_modpath(Symbol(module_name))
    except:
        print "Cannot load %s, may be part of another module"%(module_name)
        return
    
    #old: modname = mod.get_modpath().name
    modname = mod.filename
    
    has_actions = False
    has_predicates = False
    has_functions = False
    #old: syminfos = mod.get_sparkl_unit().get_exports().values()
    #new
    decls = getPackageDecls(testagent, mod.filename)
    #old: for syminfo in syminfos:
    for decl in decls:
        if decl is None:
            continue
        sym = decl.asSymbol()
        if sym.modname == modname:
            if decl.optMode(ACTION_DO):
                has_actions = True
            elif decl.optMode(PRED_SOLVE):
                has_predicates = True
            elif decl.optMode(TERM_EVAL):
                has_functions = True
    
    f = get_outputfile(module_name)
    f.write(get_header(module_name))
    f.write('<h2>Listing for module '+module_name+'</h2>'+\
            '<div class="entry">'+\
            '<p>This is auto-generated documentation.</p>'+\
            '<h4>Contents:</h4>'+\
            '<ul>')
    if has_actions:
        f.write('<li><a href="#actions">Actions</a></li>')
    if has_predicates:
        f.write('<li><a href="#predicates">Predicates</a></li>')
    if has_functions:
        f.write('<li><a href="#functions">Functions</a></li>')
        
    f.write('</ul></div>')

    if has_actions:
        f.write('<h3><a name="actions"></a><a href="#actions">Actions</a></h3>')
        doc_symbol(mod, ACTION_DO, f)
    if has_predicates:
        f.write('<h3><a name="predicates"></a><a href="#predicates">Predicates</a></h3>')    
        doc_symbol(mod, PRED_SOLVE, f)
    if has_functions:
        f.write('<h3><a name="functions"></a><a href="#functions">Functions</a></h3>')    
        doc_symbol(mod, TERM_EVAL, f)

    f.write(get_footer(module_name))
    f.close()
def _collect_symbols(agent, usage, collectAll):
    # ensure_default_module_loaded(agent)
    if collectAll:
        syms = agent.getDeclaredSymbols()
        decls = [agent.getDecl(n) for n in syms]
        names = [decl.asSymbol() for decl in decls if decl is not None and decl.optMode(usage)]
    else:
        mod = get_default_module()
        if mod is None:
            raise LowError("Default module is not loaded")
        decls = getPackageDecls(agent, mod.filename)
        names = [decl.asSymbol() for decl in decls if decl is not None and decl.optMode(usage)]
    return names
Exemple #3
0
def _collect_symbols(agent, usage, collectAll):
    #ensure_default_module_loaded(agent)
    if collectAll:  
        syms = agent.getDeclaredSymbols()
        decls = [agent.getDecl(n) for n in syms]
        names = [decl.asSymbol() for decl in decls \
                 if decl is not None and decl.optMode(usage)]
    else:
        mod = get_default_module()
        if mod is None:
            raise LowError("Default module is not loaded")
        decls = getPackageDecls(agent, mod.filename)
        names = [decl.asSymbol() for decl in decls \
                 if decl is not None and decl.optMode(usage)]
    return names
Exemple #4
0
def doc_symbol(mod, usage, f):
    """generates documentation for the specified symbol.  this is a
    subroutine of doc_module"""
    f.write('<div class="entry">')
    f.write('<dl>')
    modname = mod.get_modpath().name
    global all_symbols
    decls = [d for d in getPackageDecls(testagent, mod.filename)]
    decls.sort(decl_cmp)
    for decl in decls:
        sym = decl.asSymbol()

        if sym.modname == modname and decl.optMode(usage):
            all_symbols.append(sym)
            args = ' <span class="args">'
            required = requiredargnames(testagent, sym)
            if required:
                args = args + '$' + ' $'.join(required)
            restargs = restargnames(testagent, sym)
            if restargs:
                args = args + ' <em>rest: ' + ' '.join(restargs) + '</em>'
            args = args + "</span>"

            f.write('<dt><a name="' + anchorName(sym.id) + '"></a><b>' +
                    sym.id + '</b>' + args + '</dt>')

            f.write('<dd>')
            doc = get_fact(testagent, P_Doc, sym)
            if doc:
                f.write(doc + '<br />')

            features = get_fact(testagent, P_Features, sym)
            if features:
                f.write('<b>Features:</b> ' + htmlStr(features) + '<br />')

            properties = get_fact(testagent, P_Properties, sym)
            if properties:
                f.write('<b>Properties:</b> ' + htmlStr(properties) + '<br />')

            f.write('</dd>')

    f.write('</dl>')
    f.write('</div>')
Exemple #5
0
def doc_symbol(mod, usage, f):
    """generates documentation for the specified symbol.  this is a
    subroutine of doc_module"""
    f.write('<div class="entry">')
    f.write('<dl>')
    modname = mod.get_modpath().name
    global all_symbols
    decls = [d for d in getPackageDecls(testagent, mod.filename)]
    decls.sort(decl_cmp)
    for decl in decls:
        sym = decl.asSymbol()

        if sym.modname == modname and decl.optMode(usage):
            all_symbols.append(sym)
            args = ' <span class="args">'
            required = requiredargnames(testagent, sym)
            if required:
                args = args + '$' + ' $'.join(required)
            restargs = restargnames(testagent, sym)
            if restargs:
                args = args+' <em>rest: '+ ' '.join(restargs)+'</em>'
            args = args + "</span>"
            
            f.write('<dt><a name="'+anchorName(sym.id)+'"></a><b>'+sym.id+'</b>'+args+'</dt>')

            f.write('<dd>')
            doc = get_fact(testagent, P_Doc, sym)
            if doc:
                f.write(doc+'<br />')

            features = get_fact(testagent, P_Features, sym)
            if features:
                f.write('<b>Features:</b> '+htmlStr(features)+'<br />')

            properties = get_fact(testagent, P_Properties, sym)
            if properties:
                f.write('<b>Properties:</b> '+htmlStr(properties)+'<br />')

            f.write('</dd>')
                        
    f.write('</dl>')
    f.write('</div>')
Exemple #6
0
def doc_module(module_name):
    """generates the documentation page for the specified module"""
    print "doc_module: ", module_name
    try:
        mod = ensure_modpath_installed(module_name)
        testagent.load_modpath(Symbol(module_name))
    except:
        print "Cannot load %s, may be part of another module" % (module_name)
        return

    #old: modname = mod.get_modpath().name
    modname = mod.filename

    has_actions = False
    has_predicates = False
    has_functions = False
    #old: syminfos = mod.get_sparkl_unit().get_exports().values()
    #new
    decls = getPackageDecls(testagent, mod.filename)
    #old: for syminfo in syminfos:
    for decl in decls:
        if decl is None:
            continue
        sym = decl.asSymbol()
        if sym.modname == modname:
            if decl.optMode(ACTION_DO):
                has_actions = True
            elif decl.optMode(PRED_SOLVE):
                has_predicates = True
            elif decl.optMode(TERM_EVAL):
                has_functions = True

    f = get_outputfile(module_name)
    f.write(get_header(module_name))
    f.write('<h2>Listing for module '+module_name+'</h2>'+\
            '<div class="entry">'+\
            '<p>This is auto-generated documentation.</p>'+\
            '<h4>Contents:</h4>'+\
            '<ul>')
    if has_actions:
        f.write('<li><a href="#actions">Actions</a></li>')
    if has_predicates:
        f.write('<li><a href="#predicates">Predicates</a></li>')
    if has_functions:
        f.write('<li><a href="#functions">Functions</a></li>')

    f.write('</ul></div>')

    if has_actions:
        f.write(
            '<h3><a name="actions"></a><a href="#actions">Actions</a></h3>')
        doc_symbol(mod, ACTION_DO, f)
    if has_predicates:
        f.write(
            '<h3><a name="predicates"></a><a href="#predicates">Predicates</a></h3>'
        )
        doc_symbol(mod, PRED_SOLVE, f)
    if has_functions:
        f.write(
            '<h3><a name="functions"></a><a href="#functions">Functions</a></h3>'
        )
        doc_symbol(mod, TERM_EVAL, f)

    f.write(get_footer(module_name))
    f.close()