manage.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """
  2. flaskbb.manage
  3. ~~~~~~~~~~~~~~~~~~~~
  4. This script provides some easy to use commands for
  5. creating the database with or without some sample content.
  6. You can also run the development server with it.
  7. Just type `python manage.py` to see the full list of commands.
  8. :copyright: (c) 2013 by the FlaskBB Team.
  9. :license: BSD, see LICENSE for more details.
  10. """
  11. from flask import current_app
  12. from flask.ext.script import Manager, Shell, Server
  13. from flaskbb import create_app
  14. from flaskbb.extensions import db
  15. from flaskbb.utils.populate import (create_test_data, create_admin_user,
  16. create_welcome_forum, create_default_groups)
  17. # Use the development configuration if available
  18. try:
  19. from flaskbb.configs.development import DevelopmentConfig as Config
  20. except ImportError:
  21. from flaskbb.configs.default import DefaultConfig as Config
  22. app = create_app(Config)
  23. manager = Manager(app)
  24. # Run local server
  25. manager.add_command("runserver", Server("localhost", port=8080))
  26. # Add interactive project shell
  27. def make_shell_context():
  28. return dict(app=current_app, db=db)
  29. manager.add_command("shell", Shell(make_context=make_shell_context))
  30. @manager.command
  31. def initdb():
  32. """
  33. Creates the database.
  34. """
  35. db.create_all()
  36. @manager.command
  37. def createall():
  38. """
  39. Creates the database with some example content.
  40. """
  41. # Just for testing purposes
  42. db.drop_all()
  43. db.create_all()
  44. create_test_data()
  45. @manager.command
  46. def create_admin():
  47. """
  48. Creates the admin user
  49. """
  50. db.create_all()
  51. create_admin_user()
  52. @manager.command
  53. def create_default_data():
  54. """
  55. This should be created by every flaskbb installation
  56. """
  57. db.create_all()
  58. create_default_groups()
  59. create_welcome_forum()
  60. if __name__ == "__main__":
  61. manager.run()