示例#1
0
 def __bind_commands(self):
     if not self.parallel:
         for attr in ['complete_kill', 'do_kill', 'do_status']:
             delattr(FrameworkConsole, attr)
     for name, func in get_commands():
         longname = 'do_{}'.format(name)
         # set the behavior of the console command (multi-processed or not)
         # setattr(Console, longname, MethodType(FrameworkConsole.start_process_template(func) \
         #                                   if self.parallel and func.behavior.is_multiprocessed else func, self))
         setattr(Console, longname, MethodType(func, self))
         # retrieve parts of function's docstring to make console command's docstring
         parts = func.__doc__.split(':param ')
         description = parts[0].strip()
         arguments = [" ".join([l.strip() for l in x.split(":")[-1].split('\n')]) for x in parts[1:]]
         docstring = COMMAND_DOCSTRING["description"].format(description)
         if len(arguments) > 0:
             arg_descrs = [' - {}:\t{}'.format(n, d or "[no description]") \
                           for n, d in list(zip_longest(signature(func).parameters.keys(), arguments or []))]
             docstring += COMMAND_DOCSTRING["arguments"].format('\n'.join(arg_descrs))
         if hasattr(func, 'examples') and isinstance(func.examples, list):
             args_examples = [' >>> {} {}'.format(name, e) for e in func.examples]
             docstring += COMMAND_DOCSTRING["examples"].format('\n'.join(args_examples))
         setattr(getattr(getattr(Console, longname), '__func__'), '__doc__', docstring)
         # set the autocomplete list of values (can be lazy by using lambda) if relevant
         if hasattr(func, 'autocomplete'):
             setattr(Console, 'complete_{}'.format(name),
                     MethodType(FrameworkConsole.complete_template(func.autocomplete), self))
         if hasattr(func, 'reexec_on_emptyline') and func.reexec_on_emptyline:
             self.reexec.append(name)
示例#2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.api import local, settings, task

from core.commands import get_commands


@task
def console():
    """ Open framework's console. """
    with settings(remote_interrupt=False):
        local('python main.py')


for name, func in get_commands(exclude=['list']):
    globals()[name] = task(func)