#!/usr/bin/env python
from flask.ext.script import Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand

from helpers import generate_ship
from kcsrv import app
import db


manager = Manager(app)
manager.add_command('runserver', Server(host='0.0.0.0', use_reloader=True))

migrate = Migrate(app, db)

manager.add_command('db', MigrateCommand)

from commands.user import manager as user_manager

manager.add_command('user', user_manager)

import commands.kcdownloader2

@manager.command
def setup():
    print("Installing default roles...")
    db.db.session.add(db.Role(name="admin", description="Allowed to access the admin panel"))
    db.db.session.add(db.Role(name="staff", description="Allowed to see restricted information"))
    db.db.session.commit()

@manager.command
def dlassets():
    commands.kcdownloader2.run()

@manager.command
def cheat_addship(id, admiral_id):
    ship = generate_ship.generate_new_ship(id)
    admiral = db.Admiral.query.filter_by(id=admiral_id)[0]
    if admiral:
        admiral.admiral_ships.append(ship)
    db.db.session.merge(admiral)
    db.db.session.commit()
    print("Added ship {}".format(ship.ship.name))

if __name__ == '__main__':
    manager.run()

@@ -175,17 +175,24 @@
 app%0A
+from db 
 import 
-db
+*
 %0A%0A%0Am
@@ -557,27 +557,24 @@
 es...%22)%0A    
-db.
 db.session.a
@@ -644,35 +644,32 @@
 in panel%22))%0A    
-db.
 db.session.add(d
@@ -743,27 +743,24 @@
 tion%22))%0A    
-db.
 db.session.c
@@ -948,19 +948,16 @@
 miral = 
-db.
 Admiral.
@@ -1049,27 +1049,24 @@
 d(ship)%0A    
-db.
 db.session.m
@@ -1083,19 +1083,16 @@
 al)%0A    
-db.
 db.sessi

fix migration, closes #15