Skip to content

Commit

Permalink
Additional fixes for #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed May 4, 2017
1 parent d407c1d commit c68b44b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 68 deletions.
73 changes: 9 additions & 64 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,16 @@
#!/usr/bin/env python

from flask_script import Manager, Server, Option, prompt_bool
from flask_script.commands import Clean, ShowUrls
from flask_alembic import ManageMigrations, FlaskAlembicConfig
from alembic import command
from coaster.manage import init_manager

from hasmail import app
from hasmail import models
import hasmail
import hasmail.models as models
import hasmail.forms as forms
import hasmail.views as views
from hasmail.models import db
from hasmail import app


manager = Manager(app)
database = Manager(usage="Perform database operations")


class InitedServer(Server):
def get_options(self):
return super(InitedServer, self).get_options() + (
Option('-e', dest='env', default='dev', help="run server for this environment [default 'dev']"),
)

def handle(self, *args, **kwargs):
super(InitedServer, self).handle(*args, **kwargs)


class InitedMigrations(ManageMigrations):
def run(self, args):
super(InitedMigrations, self).run(args[1:])


@manager.shell
def _make_context():
return dict(app=app, db=db, models=models)


@database.option('-e', '--env', default='dev', help="runtime environment [default 'dev']")
def drop(env):
"Drops database tables"
if prompt_bool("Are you sure you want to lose all your data?"):
db.drop_all()


@database.option('-e', '--env', default='dev', help="runtime environment [default 'dev']")
def create(env):
"Creates database tables from sqlalchemy models"
db.create_all()
config = FlaskAlembicConfig("alembic.ini")
command.stamp(config, "head")


@database.option('-e', '--env', default='dev', help="runtime environment [default 'dev']")
def setversion(env):
'''
Manually set the alembic version of the
database to the provided value.
'''
config = FlaskAlembicConfig("alembic.ini")
version = raw_input("Enter the alembic version to be set:")
command.stamp(config, version)


manager.add_command("db", database)
manager.add_command("runserver", InitedServer())
manager.add_command("clean", Clean())
manager.add_command("showurls", ShowUrls())
manager.add_command("migrate", InitedMigrations())


if __name__ == "__main__":
if __name__ == '__main__':
db.init_app(app)
manager = init_manager(app, db, hasmail=hasmail, models=models, forms=forms, views=views)
manager.run()
4 changes: 0 additions & 4 deletions runtests.py

This file was deleted.

4 changes: 4 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
export FLASK_ENV="TESTING"
coverage run `which nosetests`
coverage report

0 comments on commit c68b44b

Please sign in to comment.