예제 #1
0
def register_manager(manager):
    """
    Register all manager plugins and default commands with the manager.
    """
    from urlparse import urlparse
    from flask.ext.script.commands import Shell, Server, ShowUrls  # , Clean
    #from invenio.errorlib import register_exception
    from invenio.config import CFG_SITE_URL
    from invenio.importutils import autodiscover_modules

    # Call add_command() in inveniomanage module to register managers.
    modules = autodiscover_modules(['invenio'], '.+_manager\.py')
    for m in modules:
        name = m.__name__[len('invenio.'):-len('_manager')]
        if 'manager' in dir(m):
            candidate = getattr(m, 'manager')
            if isinstance(candidate, FlaskExtManager):
                manager.add_command(name, candidate)

    #FIXME clean command is broken
    #manager.add_command("clean", Clean())
    manager.add_command("show-urls", ShowUrls())
    manager.add_command("shell", Shell())
    parsed_url = urlparse(CFG_SITE_URL)
    port = parsed_url.port or 80
    host = parsed_url.hostname or '127.0.0.1'
    manager.add_command("runserver", Server(host=host, port=port))
예제 #2
0
파일: manage.py 프로젝트: nyimbi/flask-xxl
def main(auto=False):
    if not auto:
        sys.argv.insert(1, 'mrbob')
    flaskxxl.test_request_context().push()
    manager.add_command('mrbob', mrbob_manager)
    manager.add_command('clean', Clean())
    manager.add_command('urls', ShowUrls())
    default_cmd = 'mrbob'
    if len(sys.argv) > 2:
        default_cmd = 'clean'
    manager.run(default_command=default_cmd)
예제 #3
0
파일: manage.py 프로젝트: jasimmk/coaster
def init_manager(app, db, init_for, **kwargs):
    """
    Initialise Manager

    :param app: Flask app object
    :parm db: db instance
    :param init_for: init_for function which is normally present in __init__.py of hgapp.
    """
    manager.app, manager.db, manager.init_for = app, db, init_for
    manager.add_command("db", database)
    manager.add_command("clean", Clean())
    manager.add_command("showurls", ShowUrls())
    manager.add_command("migrate", InitedMigrations())
    return manager
예제 #4
0
def init_manager(app, db, init_for, **kwargs):
    """
    Initialise Manager

    :param app: Flask app object
    :parm db: db instance
    :param init_for: init_for function which is normally present in __init__.py of hgapp
    :param kwargs: Additional keyword arguments to be made available as shell context
    """
    manager.app, manager.db, manager.init_for = app, db, init_for
    manager.context = kwargs
    manager.add_command("db", database)
    manager.add_command("clean", Clean())
    manager.add_command("showurls", ShowUrls())
    manager.add_command("migrate", InitedMigrations())
    return manager
예제 #5
0
def register_commands(manager):
    '''Register all core commands'''
    manager.add_command('clean', Clean())
    manager.add_command('urls', ShowUrls())

    settings = os.environ.get('UDATA_SETTINGS', join(os.getcwd(), 'udata.cfg'))
    manager.add_command(
        'serve',
        Server(port=7000,
               use_debugger=True,
               use_reloader=True,
               threaded=True,
               extra_files=[settings]))

    # Load all commands submodule
    for filename in iglob(join(dirname(__file__), '[!_]*.py')):
        module = splitext(basename(filename))[0]
        try:
            __import__('udata.commands.{0}'.format(module))
        except Exception as e:
            log.error('Unable to import %s: %s', module, e)

    # Load all core modules commands
    import udata.core.metrics.commands
    import udata.core.user.commands
    import udata.core.dataset.commands
    import udata.core.organization.commands
    import udata.core.search.commands
    import udata.core.spatial.commands
    import udata.core.jobs.commands
    import udata.core.badges.commands
    import udata.api.commands

    # Dynamic module commands loading
    for plugin in manager.app.config['PLUGINS']:
        name = 'udata.ext.{0}.commands'.format(plugin)
        try:
            __import__(name)
        except ImportError:
            pass
        except Exception as e:
            log.error('Error importing %s: %s', name, e)
예제 #6
0
import os

from flask.ext.script import Manager, Server
from flask.ext.script.commands import ShowUrls, Clean
from rpivideo import create_app
from rpivideo.models import db, User, Video

# default to dev config because no one should use this in
# production anyway
env = os.environ.get('APPNAME_ENV', 'dev')
app = create_app('rpivideo.settings.%sConfig' % env.capitalize(), env=env)

manager = Manager(app)
manager.add_command("server", Server())
manager.add_command("show-urls", ShowUrls())
manager.add_command("clean", Clean())


@manager.shell
def make_shell_context():
    """ Creates a python REPL with several default imports
        in the context of the app
    """

    return dict(app=app, db=db, User=User, Video=Video)


@manager.command
def createdb():
    """ Creates a database with all of the tables defined in
예제 #7
0
파일: manage.py 프로젝트: nuaays/flask-ide
                    email='*****@*****.**',
                    password='******')
    user.save()


class DB(object):
    Model = Model
    metadata = Model.metadata
    sq = squ
    app.test_request_context().push()
    engine = Model._engine


if __name__ == '__main__':
    manager.add_command('clean', Clean())
    manager.add_command('urls', ShowUrls())
    manager.add_command('db', alembic_manager)
    app.test_request_context().push()
    #conn = Model._engine.raw_connection()
    #conn.connection.text_factory = str
    #manager.add_command('shell', Shell(make_context=lambda:{'app': app, 'db': DB()}))
    app.extensions = app.extensions or {}

    class O(object):
        pass

    db = O()
    db.db = DB()
    app.extensions['sqlalchemy'] = db
    manager.run()
예제 #8
0
def main():
    flaskxxl.test_request_context().push() 
    manager.add_command('mrbob',mrbob_manager)
    manager.add_command('clean',Clean())
    manager.add_command('urls',ShowUrls())
    manager.run(default_command='mrbob')
예제 #9
0
# coding: utf-8

from flask import current_app
from flask.ext.script import Server, Manager
from flask.ext.script.commands import Clean, ShowUrls
from flask.ext.assets import ManageAssets
from flask.ext.migrate import MigrateCommand

from containers import app, collect, db
from auth.models import User

manager = Manager(app)
manager.add_command('clean', Clean())
manager.add_command('routes', ShowUrls())
manager.add_command('runserver', Server())
manager.add_command('assets', ManageAssets())
manager.add_command('db', MigrateCommand)
collect.init_script(manager)


@manager.command
def syncdb(console=True):
    db.create_all()
    db.session.commit()


@manager.command
def create_admin(console=True):
    email = raw_input('Email: ')
    password = raw_input('Password: ')
    User.create(email=email, is_admin=True, password=password)