12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- """
- flaskbb.manage
- ~~~~~~~~~~~~~~~~~~~~
- This script provides some easy to use commands for
- creating the database with or without some sample content.
- You can also run the development server with it.
- Just type `python manage.py` to see the full list of commands.
- :copyright: (c) 2013 by the FlaskBB Team.
- :license: BSD, see LICENSE for more details.
- """
- import os
- from flask import current_app
- from flask.ext.script import Manager, Shell, Server
- from flaskbb import create_app
- from flaskbb.extensions import db
- from flaskbb.utils import create_test_data
- try:
- from flaskbb.configs.development import DevelopmentConfig as Config
- except ImportError:
- from flaskbb.configs.default import DefaultConfig as Config
- app = create_app(Config)
- manager = Manager(app)
- manager.add_command("runserver", Server("localhost", port=8080))
- def make_shell_context():
- return dict(app=current_app, db=db)
- manager.add_command("shell", Shell(make_context=make_shell_context))
- @manager.command
- def initdb():
- """
- Creates the database.
- """
- db.create_all()
- @manager.command
- def createall():
- """
- Creates the database with some example content.
- """
-
- dbfile = os.path.join(Config._basedir, "flaskbb.sqlite")
- if os.path.exists(dbfile):
- os.remove(dbfile)
- db.create_all()
- create_test_data()
- if __name__ == "__main__":
- manager.run()
|