Exemple #1
0
def loadDocumentation(path, name, *apps):

    assert path

    try:

        if public.verbose:
            log_utility.info('Loading documentation "%s"...' % path)

        # Prepare the documentation registrar and namespace wrappers and exec the module
        # The last app passed in is considered the primary one
        appPrimary = apps[-1]

        docRegistrar = doc.Registrar(appPrimary.name)
        wrappers = []
        syms = {}
        for app in apps:
            wrappers.append(NamespaceWrapper(app, name, path, docRegistrar, False))
            syms[app.namespace] = wrappers[-1]
        doc.setStrucTextSymbols(syms)

        # Documentation in non-function-bearing modules is added to the "guide"
        if appPrimary.namespace == public.program.namespace:
            props = {'all': name, 'guide': name}
        else:
            props = {}
        doc.parserStrucText.parse(open(path).read())
        node = doc.parserStrucText.take()
        node.setProp('module', name)
        docRegistrar.add(node)
        docRegistrar.register()

    except Exception, e:
        log_utility._tracebackException('Failed to load "%s"' % path, e, 0, 0, True)
Exemple #2
0
def main(version):
    if public.program.name != public.engine.name and version is not None:
        public.program.version = version
    args = getArgs()
    if public.verbose:
        log_utility.info('args = %s' % args)
    # Load scripts and warn about duplicates
    loadScripts()
    global duplicateFunctions
    if len(duplicateFunctions) > 0:
        duplicateFunctions.sort()
        for dup in duplicateFunctions:
            log_utility.warning('Ignoring duplicate "%s" from "%s"' % (dup.name(), dup.path()))
    # Display the quick start guide if running the base program with no arguments
    if public.engine.name and len(args) == 0:
        execute('help()')
        sys.exit(1)
    for argIn in args:
        try:
            execute(argIn)
        except public.ExcBase, e:
            if e.traceback:
                log_utility._tracebackException(None, e, 0, 0, False)
            else:
                msgs = str(e).split('\n')
                log_utility.error('Command: "%s"' % argIn, *msgs)
        except doc.ExcBase, e:
            msgs = str(e).split('\n')
            log_utility.error('Command: "%s"' % argIn, *msgs)
Exemple #3
0
def loadScript(path, name, isCore, *apps):

    assert path

    try:

        if public.verbose:
            log_utility.info('Loading script "%s"...' % path)

        # Prepare the documentation registrar and namespace wrappers and exec the module
        # The last app passed in is considered the primary one
        appPrimary = apps[-1]

        docRegistrar = doc.Registrar(appPrimary.name)
        wrappers = []
        syms = {}
        for app in apps:
            wrappers.append(NamespaceWrapper(app, name, path, docRegistrar, isCore))
            syms[app.namespace] = wrappers[-1]
        doc.setStrucTextSymbols(syms)
        execfile(path, syms)

        # Warn about classes flagged for export (should be in a type module)
        # Export newly-discovered classes of appropriate ancestry
        namesOrig = [app.namespace for app in apps]
        for nameNew in syms:
            if nameNew not in namesOrig and inspect.isclass(syms[nameNew]):
                for exportedClass in exportedClasses:
                    sym = syms[nameNew]
                    if issubclass(sym, exportedClass):
                        if public.verbose:
                            log_utility.info('Register type "%s.%s"'
                                                % (appPrimary.namespace, nameNew))
                        appPrimary.types[nameNew] = sym

        # Create function objects for empty decorators (invoked without parens).
        # Register all discovered functions and track duplicates.
        if appPrimary.exports.has(name):
            export = appPrimary.exports.get(name)
        else:
            export = appPrimary.exports.add(name, path, None)
        global duplicateFunctions
        for wrapper in wrappers:
            for decorator in wrapper._decoExport:
                if decorator.function is None:
                    func = decorator.args[0]
                    decorator.args = decorator.args[1:]
                    decorator._register(func)
                if decorator.isCore:
                    if public.verbose:
                        log_utility.info('Register core function "%s"'
                                            % decorator.function.nameShort)
                    global symsCore
                    if decorator.function.nameShort not in symsCore:
                        symsCore[decorator.function.nameShort] = decorator.function
                else:
                    if public.verbose:
                        log_utility.info('Register function "%s.%s"'
                                            % (appPrimary.namespace, decorator.function.name))
                if not export.addFunction(decorator.function):
                    duplicateFunctions.append(DuplicateFunction(decorator.function))

        # Register documentation
        if export.countFunctions() > 0:
            # Documentation in function-bearing modules is added to the "reference"
            if appPrimary.namespace == public.program.namespace:
                props = {'all': name, 'reference': name}
            else:
                props = {}
            # For consistent TOC sorting need core to be None, rather than False.
            if isCore:
                nodeModule = docRegistrar.wrap(
                    form    = 'wrapper',
                    heading = 'Module: (%s)' % name,
                    core    = name,
                    **props
                )
            else:
                nodeModule = docRegistrar.wrap(
                    form    = 'wrapper',
                    heading = 'Module: %s' % name,
                    module  = name,
                    toc     = True,
                    **props
                )
            nodesBody = []
            for function in export.iterFunctionsSorted():
                if not function.isInternal:
                    nodesDoc = []
                    if function.doc:
                        nodesDoc.append(function.doc)
                    for wrapper in wrappers:
                        nodesDoc.append(wrapper._nodesFunc.get(function.nameShort, []))
                    nodesBody.append(
                        doc.Node(
                            form     = 'wrapper',
                            heading  = 'Function: %s' % function.getProto(),
                            content  = FunctionNode(function, nodesDoc),
                            function = function.name,
                            toc      = True,
                        )
                    )
            nodeModule.add(doc.Node(content = nodesBody))
        else:
            # Documentation in non-function-bearing modules is added to the "guide"
            if appPrimary.namespace == public.program.namespace:
                props = {'all': name, 'guide': name}
            else:
                props = {}
            if isCore:
                docRegistrar.wrap(form = 'wrapper', core = name, **props)
            else:
                docRegistrar.wrap(form = 'wrapper', module = name, **props)
        docRegistrar.register()

    except public.ExcLoad, e:
        log_utility._tracebackException('Failed to load "%s"' % path, e, 1, 1, False)
Exemple #4
0
            else:
                props = {}
            if isCore:
                docRegistrar.wrap(form = 'wrapper', core = name, **props)
            else:
                docRegistrar.wrap(form = 'wrapper', module = name, **props)
        docRegistrar.register()

    except public.ExcLoad, e:
        log_utility._tracebackException('Failed to load "%s"' % path, e, 1, 1, False)
    except public.ExcBase, e:
        log_utility.error('Failed to load "%s"' % path, str(e))
    except doc.ExcBase, e:
        log_utility.error('Failed to load "%s" due to documentation error' % path, str(e))
    except Exception, e:
        log_utility._tracebackException('Failed to load "%s"' % path, e, 0, 0, True)

#===============================================================================

# Assumes the primary app is the last one
def loadDocumentation(path, name, *apps):

    assert path

    try:

        if public.verbose:
            log_utility.info('Loading documentation "%s"...' % path)

        # Prepare the documentation registrar and namespace wrappers and exec the module
        # The last app passed in is considered the primary one