manage.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 import create_test_data
  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. dbfile = os.path.join(Config._basedir, "flaskbb.sqlite")
  43. if os.path.exists(dbfile):
  44. os.remove(dbfile)
  45. db.create_all()
  46. create_test_data()
  47. if __name__ == "__main__":
  48. manager.run()