我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用flask_script.Manager()。
def run(): """Run the CLI manager for the web application .. todo:: allow extension add options & commands, separate create and run part of function command for checking config """ manager = flask_script.Manager(create_app) manager.add_option('-c', '--config', dest='cfg_files', required=False, action='append', default=['DEFAULT']) manager.add_option('-v', '--version', action='version', version='{} v{}'.format(PROG_NAME, VERSION)) manager.add_command('db', flask_migrate.MigrateCommand) manager.add_command('db-create', DbCreateCommand) manager.add_command('repocheck', RepocheckCommand) manager.add_command('assign-role', AssignRoleCommand) manager.add_command('check-config', CheckConfigCommand) manager.run()
def __call__(self, app=None, **kwargs): """ ???Manager????Options will be ignored.??? ???flask-script?Manager??app?????????? ??????? """ if app is None: app = self.app if app is None: raise Exception("There is no app here. This is unlikely to work.") if isinstance(app, Flask): return app app = app(**kwargs) self.app = app return app
def manager(self): return Manager(self.flask_app)
def main(): import sys from flask_script import Manager from superdesk import COMMANDS from superdesk.ws import create_server if len(sys.argv) == 2 and sys.argv[1] == 'ws': create_server(application.config) else: manager = Manager(application) manager.run(COMMANDS)
def manager(self): """Integrate a Flask-Script.""" from flask_script import Manager, Command manager = Manager(usage="Migrate database.") manager.add_command('create', Command(self.cmd_create)) manager.add_command('migrate', Command(self.cmd_migrate)) manager.add_command('rollback', Command(self.cmd_rollback)) manager.add_command('list', Command(self.cmd_list)) manager.add_command('merge', Command(self.cmd_merge)) return manager
def test_with_default_commands(self): manager = Manager(self.app) manager.set_defaults() assert 'runserver' in manager._commands assert 'shell' in manager._commands