Example #1
0
from flask_script import Manager
import flask_security.script as sec
from application import app, db

manager = Manager(app)
manager.add_command('create_user', sec.CreateUserCommand())
manager.add_command('create_role', sec.CreateRoleCommand())
manager.add_command('add_role', sec.AddRoleCommand())
manager.add_command('remove_role', sec.RemoveRoleCommand())


@manager.command
def create_db():
    """Creates database from sqlalchemy schema."""
    db.create_all()


def main():
    manager.run()


if __name__ == '__main__':
    main()
Example #2
0
# coding=utf-8
# Copyright 2013 Janusz Skonieczny
import logging

from main import app
from flask_script import Manager, Command


class InitDatabase(Command):
    """Initialize database"""
    def run(self):
        logging.debug("db.reate_all")
        from website.database import db
        db.create_all()


manager = Manager(app)
manager.add_command('initdb', InitDatabase())

from flask_security import script
manager.add_command('create-user', script.CreateUserCommand())
manager.add_command('create-role', script.CreateRoleCommand())
manager.add_command('add-role', script.AddRoleCommand())
manager.add_command('remove-role', script.RemoveRoleCommand())
manager.add_command('activate-user', script.ActivateUserCommand())
manager.add_command('deactivate-user', script.DeactivateUserCommand())

if __name__ == "__main__":
    manager.run()
Example #3
0
def main(create_app_func=None):
    
    if not create_app_func:
        from shortener_url.wsgi import create_app
        create_app_func = create_app
    
    class ServerWithGevent(Server):
        help = description = 'Runs the Flask development server with Gevent WSGI Server'
    
        def __call__(self, app, host, port, use_debugger, use_reloader,
                   threaded, processes, passthrough_errors, **kwargs):
            
            #print("kwargs : ", kwargs)
            #{'ssl_key': None, 'ssl_crt': None}

            if use_debugger:
                app = DebuggedApplication(app, evalex=True)
    
            server = WSGIServer((host, port), app)
            try:
                print('Listening on http://%s:%s' % (host, port))
                server.serve_forever()
            except KeyboardInterrupt:
                pass
    
    env_config = config_from_env('SHORTURL_SETTINGS', 'shortener_url.settings.Prod')
    
    manager = Manager(create_app_func, 
                      with_default_commands=False)
    
    #TODO: option de config app pour désactiver run counter
    
    manager.add_option('-c', '--config',
                       dest="config",
                       default=env_config)

    manager.add_command("shell", Shell())

    if HAS_GEVENT:
        manager.add_command("server", ServerWithGevent(
                        host = '0.0.0.0',
                        port=8081)
        )
        manager.add_command("debug-server", Server(
                        host = '0.0.0.0',
                        port=8081)
        )
    else:
        manager.add_command("server", Server(
                        host = '0.0.0.0',
                        port=8081)
        )

    manager.add_command("config", ShowConfigCommand())
    manager.add_command("urls", ShowUrlsCommand())
    manager.add_command("assets", ManageAssets())
    
    from flask_security import script
    manager.add_command('auth-create-user', script.CreateUserCommand())
    manager.add_command('auth-create-role', script.CreateRoleCommand())
    manager.add_command('auth-add-role', script.AddRoleCommand())
    manager.add_command('auth-remove-role', script.RemoveRoleCommand())
    manager.add_command('auth-activate-user', script.ActivateUserCommand())
    manager.add_command('auth-deactivate-user', script.DeactivateUserCommand())
    
    manager.run()