manage.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import os
  12. from flask import current_app
  13. from flask.ext.script import Manager, Shell, Server
  14. from flaskbb import create_app
  15. from flaskbb.extensions import db
  16. from flaskbb.utils.populate import (create_test_data, create_admin_user,
  17. create_welcome_forum, create_default_groups)
  18. # Use the development configuration if available
  19. try:
  20. from flaskbb.configs.development import DevelopmentConfig as Config
  21. except ImportError:
  22. from flaskbb.configs.default import DefaultConfig as Config
  23. app = create_app(Config)
  24. manager = Manager(app)
  25. # Run local server
  26. manager.add_command("runserver", Server("localhost", port=8080))
  27. # Add interactive project shell
  28. def make_shell_context():
  29. return dict(app=current_app, db=db)
  30. manager.add_command("shell", Shell(make_context=make_shell_context))
  31. @manager.command
  32. def initdb():
  33. """
  34. Creates the database.
  35. """
  36. db.create_all()
  37. @manager.command
  38. def createall():
  39. """
  40. Creates the database with some example content.
  41. """
  42. # Just for testing purposes
  43. dbfile = os.path.join(Config._basedir, "flaskbb.sqlite")
  44. if os.path.exists(dbfile):
  45. os.remove(dbfile)
  46. db.create_all()
  47. create_test_data()
  48. @manager.command
  49. def create_admin():
  50. """
  51. Creates the admin user
  52. """
  53. db.create_all()
  54. create_admin_user()
  55. @manager.command
  56. def create_default_data():
  57. """
  58. This should be created by every flaskbb installation
  59. """
  60. db.create_all()
  61. create_default_groups()
  62. create_welcome_forum()
  63. if __name__ == "__main__":
  64. manager.run()