Exemple #1
0
def ListCommands():
    """List all available commands.

    Example:

    >>> ListCommands()
    """
    session.log.info('Available commands:')
    items = []
    for name, obj in session.getExportedObjects():
        if getattr(obj, 'is_usercommand', False):
            real_func = getattr(obj, 'real_func', obj)
            if getattr(real_func, 'is_hidden', False):
                continue
            if real_func.__name__ != name:
                # it's an alias, don't show it again
                continue
            if hasattr(real_func, 'help_arglist'):
                argspec = '(%s)' % real_func.help_arglist
            else:
                argspec = formatArgs(real_func)
            docstring = real_func.__doc__ or ' '
            signature = real_func.__name__ + argspec
            if len(signature) > 50:
                signature = signature[:47] + '...'
            if not real_func.__name__.startswith('_'):
                items.append((signature, docstring.splitlines()[0]))
    items.sort()
    printTable(('name', 'description'), items, session.log.info)
Exemple #2
0
    def gen_helpindex(self):
        ret = [
            '<p class="menu">'
            '<a href="#commands">Commands</a>&nbsp;&nbsp;|&nbsp;&nbsp;'
            '<a href="#devices">Devices</a>&nbsp;&nbsp;|&nbsp;&nbsp;'
            '<a href="#setups">Setups</a></p>'
        ]
        ret.append('<p>Welcome to the NICOS interactive help!</p>')
        cmds = []
        for name, obj in session.getExportedObjects():
            if not hasattr(obj, 'is_usercommand'):
                continue
            real_func = getattr(obj, 'real_func', obj)
            if real_func.__name__.startswith('_'):
                continue
            if getattr(real_func, 'is_hidden', False):
                continue
            if real_func.__name__ != name:
                # it's an alias, don't show it again
                continue
            if hasattr(real_func, 'help_arglist'):
                argspec = '(%s)' % real_func.help_arglist
            else:
                argspec = formatArgs(real_func)
            signature = '<tt><a href="cmd:%s">%s</a></tt><small>' % \
                ((real_func.__name__,)*2) + escape_html(argspec) + '</small>'
            docstring = escape_html(real_func.__doc__ or ' ').splitlines()[0]
            cmds.append('<tr><td>%s</td><td>%s</td></tr>' %
                        (signature, docstring))
        cmds.sort()
        ret.append(self.gen_heading('NICOS commands', 'commands'))
        ret.append('<p>These commands are currently available.</p>')
        ret.append('<table width="100%">'
                   '<tr><th>Name</th><th>Short description</th></tr>')
        ret.extend(cmds)
        ret.append('</table>')
        ret.append(self.gen_heading('Devices', 'devices'))
        ret.append(
            '<p>These are the currently loaded high-level devices.  Use '
            '<a href="cmd:AddSetup">AddSetup()</a> or the "Setup" '
            'window to add more devices.</p>')
        ret.append('<table width="100%"><tr><th>Name</th><th>Type</th>'
                   '<th>From setup</th><th>Description</th></tr>')
        setupinfo = session.getSetupInfo()
        devsetups = {}
        for sname, info in iteritems(setupinfo):
            if info is None:
                continue
            for devname in info['devices']:
                devsetups[devname] = sname
        for devname in sorted(session.explicit_devices, key=lower):
            dev = session.devices[devname]
            ret.append(
                '<tr><td><tt><a href="dev:%s">%s</a></tt></td>'
                '<td>%s</td><td>%s</td><td>%s</td>' %
                (dev, dev, dev.__class__.__name__, devsetups.get(
                    devname, ''), escape_html(dev.description)))
        ret.append('</table>')
        ret.append(self.gen_heading('Setups', 'setups'))
        ret.append('<p>These are the available setups.  Use '
                   '<a href="cmd:AddSetup">AddSetup()</a> to load an '
                   'additional setup or <a href="cmd:NewSetup">NewSetup()</a>'
                   ' to load one or more completely new ones.</p>')

        def devlink(devname):
            if devname in session.devices:
                return '<a href="dev:%s">%s</a>' % (escape_html(devname),
                                                    escape_html(devname))
            return escape_html(devname)

        def listsetups(group):
            setups = []
            for setupname, info in sorted(iteritems(session.getSetupInfo())):
                if info is None or info['group'] != group:
                    continue
                setups.append(
                    '<tr><td><tt>%s</tt></td><td>%s</td>'
                    '<td>%s</td><td>%s</td></tr>' %
                    (setupname, setupname in session.loaded_setups and 'yes'
                     or '', escape_html(info['description']), ', '.join(
                         map(devlink, sorted(info['devices'], key=lower)))))
            ret.append('<table width="100%"><tr><th>Name</th><th>Loaded</th>'
                       '<th>Description</th><th>Devices</th></tr>')
            ret.extend(setups)
            ret.append('</table>')

        ret.append('<h4>Basic instrument setups</h4>')
        listsetups('basic')
        ret.append('<h4>Optional setups</h4>')
        listsetups('optional')
        ret.append('<h4>Plug-and-play setups</h4>')
        listsetups('plugplay')
        return ''.join(ret)