manager.py 940 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. import os
  3. from app import create_app, db
  4. from app.models import User, Role, Resource, ResourceType, Organization
  5. from flask_script import Manager, Shell
  6. from flask_migrate import Migrate, MigrateCommand
  7. from flask import g, render_template
  8. app = create_app(os.getenv('FLASK_CONFIG') or 'default')
  9. manager = Manager(app)
  10. migrate = Migrate(app, db)
  11. @app.errorhandler(404)
  12. def page_not_found(e):
  13. return render_template('errors/404.html'), 404
  14. with app.app_context():
  15. g.contextPath = ''
  16. def make_shell_context():
  17. return dict(app=app, db=db, User=User, Role=Role, Resource=Resource,
  18. ResourceType=ResourceType, Organization=Organization)
  19. manager.add_command("shell", Shell(make_context=make_shell_context))
  20. manager.add_command('db', MigrateCommand)
  21. @manager.command
  22. def myprint():
  23. print('hello world')
  24. if __name__ == '__main__':
  25. manager.run()