accountant/manage.py

48 lines
987 B
Python
Raw Normal View History

2015-06-05 23:34:04 +02:00
#!/usr/bin/env python
2013-12-03 22:22:25 +01:00
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand, stamp
2013-12-03 22:22:25 +01:00
2015-07-17 19:22:49 +02:00
from accountant import app, db
2013-12-03 22:22:25 +01:00
from accountant.api.models.users import User
2013-12-03 22:22:25 +01:00
manager = Manager(app)
2015-07-17 19:22:49 +02:00
migrate = Migrate(app, db)
2013-12-03 22:22:25 +01:00
manager.add_command('db', MigrateCommand)
@manager.command
def initdb():
""" Create the database ans stamp it. """
tables = db.engine.table_names()
if len(tables) > 1 and 'alembic_version' not in tables:
exit("Database already initialized.")
db.metadata.create_all(bind=db.engine)
stamp()
print("Database created.")
user_manager = Manager(usage="Manage users.")
manager.add_command('user', user_manager)
@user_manager.command
def add(email, password):
""" Add a new user. """
user = User()
user.email = email
user.password = User.hash_password(password)
db.session.add(user)
print("User '%s' successfully added." % email)
2013-12-03 22:22:25 +01:00
if __name__ == "__main__":
manager.run()