Ejemplo n.º 1
0
def main():
    global apps, commands

    project = None
    basename = os.path.basename(sys.argv[0])
    if basename != 'chiki':
        project = basename

    if not project:
        sys.path.append('.')
        project = get_project_name()

    if project:
        __import__(project)

    if 'manager' in apps:
        manager = Manager(apps['manager']['run'])

        for cmd, app in apps.iteritems():
            manager.add_command(cmd, Command(create_command(app)))

        for cmd, command in commands.iteritems():
            manager.add_command(cmd, Command(command))

        def make_shell_context():
            return dict(app=apps['manager']['run'](), db=db, um=um)

        manager.add_command("shell", Shell(make_context=make_shell_context))

        @manager.command
        @manager.option('name')
        def service(name, model='simple'):
            if not run_service(name, model):
                module = '%s.services.%s' % (project, name)
                action = __import__(module)
                for sub in module.split('.')[1:]:
                    action = getattr(action, sub)
                if inspect.getargspec(action.run)[0]:
                    action.run(model)
                else:
                    action.run()
    else:
        manager = Manager(Flask(__name__))

    @manager.command
    @manager.option('template')
    def create_project(template,
                       checkout='',
                       no_input=False,
                       api=False,
                       web=False):
        context = dict(today=datetime.now().strftime('%Y-%m-%d'))
        if api:
            context['has_api'] = True
        if web:
            context['has_web'] = True
        cookiecutter(template, checkout, no_input, extra_context=context)

    manager.run()
Ejemplo n.º 2
0
    def handle(self, _, site, *args, **kwargs):
        with no_pyc():
            site = validate_site(site)
            app = Tango.get_app(site)

            if not app: return

            Command.handle(self, app, *args, **kwargs)
Ejemplo n.º 3
0
 def _register_provider_as_importer(self, provider, services):
     services['tasks'].periodic_task(provider.load, crontab=provider.IMPORT_SCHEDULE)
     command = Command()
     command.__doc__ = provider.__doc__
     command.run = provider.load
     services['cli'].add_command(
         'import_{provider}_{instance_name}'.format(
             provider=provider.IMPORTER_NAME, instance_name=self.instance_name
         ), command
     )
Ejemplo n.º 4
0
    def command(self, func=None, name=None):
        """Variant of @manager.command decorator provided by flask-script.

        Adds `do_something` function as `do-something` command. It is more convenient
        to type a hypen on command-line than an underscre.
        """
        command = Command(func)
        name = func.__name__.replace("_", "-")
        self.add_command(name, command)
        return func
Ejemplo n.º 5
0
 def __init__(self, list_name, *args, **kwargs):
     Command.__init__(self, *args, **kwargs)
     self.list_name = list_name
Ejemplo n.º 6
0
#!/usr/bin/env python

from flask.ext.script import Manager, Command
from flask.ext.migrate import MigrateCommand

from runapp import create_app
from tasks import run_celery
from tests.command import PytestCommand

manager = Manager(create_app)
manager.add_option('-c', '--config', dest='config_file', required=False)
manager.add_command('db', MigrateCommand)
manager.add_command('test', PytestCommand)
manager.add_command('runcelery', Command(run_celery))

if __name__ == '__main__':
    manager.run()