Ejemplo n.º 1
0
    def expand(*cmds):
        for command in cmds:
            parts = Split.split_words(command)
            name = parts.pop(0)
            alias = aliases.get_prefix(command)
            if alias:
                cmd, alias_commands = alias
                if (cmd == command
                        or name != Registry.registry().entry(name).name):
                    assert cmd not in stack
                    stack.add(cmd)
                    expand(*alias_commands)
                    stack.remove(cmd)
                    continue

            result.append([Registry.registry().function(name), parts])
Ejemplo n.º 2
0
def _help(_, *parts):
    if not parts:
        LOGGER.info(HELP, Registry.registry().join_keys(command_only=False))
    else:
        cmd, parts = parts[0], parts[1:]
        if not parts:
            help_text = Registry.registry().get_help(cmd)
            LOGGER.info(help_text or ('No help text available for "%s"' % cmd))
        elif cmd == 'show':
            sub = parts[0]
            help_text = Show.SHOW_REGISTRY.get_help(sub)
            LOGGER.info('\nshow %s:', sub)
            LOGGER.info(help_text
                        or ('No help text available for "show %s"' % sub))
        else:
            raise Exception("Command '%s' doesn't take any arguments.")
Ejemplo n.º 3
0
def usage():
    result = ['Valid commands are:', Registry.registry().join_keys()]
    aliases = Aliases.instance()
    if aliases:
        result.append('\nand aliases are:')
        result.append(Join.join_words(aliases))
    return ' '.join(result)
Ejemplo n.º 4
0
from echomesh.command import Help

# pylint: enable=W0611
# TODO: use the late loading from echomesh.element

from echomesh.util import Log
from echomesh.util.string import FindComment
from echomesh.util.string import Split

LOGGER = Log.logger(__name__)

COMMENT_HELP = """
Comment lines start with a # - everything after that is ignored.
"""

Registry.registry().register(lambda e: None, '#', COMMENT_HELP)
Registry.registry().register(None, 'sample', 'This is a sample with just help')


def _fix_exception_message(m, name):
    loc = m.find(')')
    if loc >= 0:
        m = m[loc + 1:]
    m = (m.replace('1', '0').replace('2', '1').replace('3', '2').replace(
        '4', '3').replace('1 arguments', '1 argument'))
    return name + m


def usage():
    result = ['Valid commands are:', Registry.registry().join_keys()]
    aliases = Aliases.instance()
Ejemplo n.º 5
0
            parts = i.split('.')
            try:
                value = Settings.get(*parts)
            except:
                failures.append(i)
            else:
                successes.append([i, value])
    else:
        assignments = Settings.assignments().items()
        successes = [('.'.join(s), v) for s, v in assignments]

    if successes or failures:
        for value, result in successes:
            LOGGER.info('%s=%s', value, result)
        if failures:
            LOGGER.error('Didn\'t understand %s', Join.join_words(failures))
        LOGGER.info('')
    else:
        LOGGER.info('No settings variables have been set.\n')


GET_HELP = """
  Prints one or more settings variables.

Examples:
  settings.get speed
  settings.get audio.input.enabled audio.output.enabled
"""

Registry.registry().register(get_settings, 'get', GET_HELP)
Ejemplo n.º 6
0
from echomesh.command import Registry
from echomesh.util import Log

LOGGER = Log.logger(__name__)


def set_settings(_, *values):
    if values:
        assignment = Leafs.leafs(Settings.assign(values))
        for address, value in six.iteritems(assignment):
            LOGGER.info('Set %s=%s', '.'.join(address), value)
        Settings.update_clients()
    elif Settings.MERGE_SETTINGS.has_changes():
        LOGGER.info(
            Yaml.encode_one(dict(Settings.MERGE_SETTINGS.get_changes())))
    else:
        LOGGER.info('You have made no changes.')


SET_HELP = """
  Sets one or more settings variables.  These changes are only present in
  memory and will be lost when the program ends - you need to use settings save
  to make them permanent.

Examples:
  set speed=50%
  set speed=10% light.period=40ms
"""

Registry.registry().register(set_settings, 'set', SET_HELP)
Ejemplo n.º 7
0
def _register():
    for cmd, help_text, see_also in COMMANDS:
        name = cmd.__name__.strip('_')
        Registry.registry().register(_local(cmd, name), name, help_text,
                                     see_also)
        RemoteRegistry.register(_remote(cmd), name)
Ejemplo n.º 8
0
        elif cmd == 'show':
            sub = parts[0]
            help_text = Show.SHOW_REGISTRY.get_help(sub)
            LOGGER.info('\nshow %s:', sub)
            LOGGER.info(help_text
                        or ('No help text available for "show %s"' % sub))
        else:
            raise Exception("Command '%s' doesn't take any arguments.")


HELP_HELP = """
"help" gives you information about how echomesh commands work.
You can use "?" as a shortcut.

For example, type "help shutdown" or "? quit" to get information about
these commands.

You can also use unambiguous abbreviations like "he shut" or "? q".

For a list of topics, type "help".
For a list of commands, type "help commands".
"""

COMMANDS_HELP = """
Echomesh has the following commands:

  """

Registry.registry().register(None, 'commands', COMMANDS_HELP, ['help'])
Registry.registry().register(_help, 'help', HELP_HELP)