Exemplo n.º 1
0
def model_type(name):
    for plugin in plugins.values():
        try:
            return plugin.models[name.lower()]
        except KeyError:
            pass
    raise TypeError
Exemplo n.º 2
0
Arquivo: repl.py Projeto: natano/tiget
 def complete(self, text, state):
     cmds = set(aliases.keys())
     for plugin in plugins.values():
         cmds.update(plugin.cmds.keys())
     options = list(sorted(cmd for cmd in cmds if cmd.startswith(text)))
     if state < len(options):
         return options[state] + ' '
     return None
Exemplo n.º 3
0
def get_command(name):
    for plugin in plugins.values():
        try:
            cmd = plugin.cmds[name]
            break
        except KeyError:
            pass
    else:
        raise KeyError(name)
    return cmd
Exemplo n.º 4
0
def cmd_exec(line):
    if not line or line.startswith('#'):
        pass
    elif line.startswith('!'):
        status = os.system(line[1:])
        if status:
            raise CmdError(
                'shell returned with exit status {}'.format(status % 255))
    elif line.startswith('%'):
        ns = {}
        for plugin in plugins.values():
            models = plugin.models
            ns.update({model.__name__: model for model in models.values()})
        code = compile(line[1:], '<exec>', 'single')
        exec(code, ns)
    else:
        try:
            line = shlex.split(line)
        except ValueError as e:
            raise CmdError(e)
        cmd_execv(line)