Skip to content

Commit

Permalink
Make init_for call implicit
Browse files Browse the repository at this point in the history
Fixes #10
  • Loading branch information
vidya-ram authored and jace committed May 4, 2017
1 parent 511e4b0 commit 733c362
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 43 deletions.
19 changes: 9 additions & 10 deletions hasmail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@


# Configure the app
def init_for(env):
coaster.app.init_app(app, env)
db.init_app(app)
db.app = app
RQ(app) # Pick up RQ configuration from the app
baseframe.init_app(app, requires=['hasmail'],
ext_requires=['bootstrap3-editable', 'codemirror-markdown', 'codemirror-css', 'fontawesome', 'baseframe-bs3'])
mail.init_app(app)
lastuser.init_app(app)
lastuser.init_usermanager(UserManager(db, models.User))
coaster.app.init_app(app)
db.init_app(app)
db.app = app
RQ(app) # Pick up RQ configuration from the app
baseframe.init_app(app, requires=['hasmail'],
ext_requires=['bootstrap3-editable', 'codemirror-markdown', 'codemirror-css', 'fontawesome', 'baseframe-bs3'])
mail.init_app(app)
lastuser.init_app(app)
lastuser.init_usermanager(UserManager(db, models.User))
11 changes: 2 additions & 9 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask_alembic import ManageMigrations, FlaskAlembicConfig
from alembic import command

from hasmail import app, init_for
from hasmail import app
from hasmail import models
from hasmail.models import db

Expand All @@ -21,35 +21,29 @@ def get_options(self):
)

def handle(self, *args, **kwargs):
if 'env' in kwargs:
init_for(kwargs.pop('env'))
super(InitedServer, self).handle(*args, **kwargs)


class InitedMigrations(ManageMigrations):
def run(self, args):
if len(args) and not args[0].startswith('-'):
init_for(args[0])
super(InitedMigrations, self).run(args[1:])


@manager.shell
def _make_context():
return dict(app=app, db=db, models=models, init_for=init_for)
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"
init_for(env)
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"
init_for(env)
db.create_all()
config = FlaskAlembicConfig("alembic.ini")
command.stamp(config, "head")
Expand All @@ -61,7 +55,6 @@ def setversion(env):
Manually set the alembic version of the
database to the provided value.
'''
init_for(env)
config = FlaskAlembicConfig("alembic.ini")
version = raw_input("Enter the alembic version to be set:")
command.stamp(config, version)
Expand Down
2 changes: 1 addition & 1 deletion rq.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

rqworker -c rqdev hasmail
rqworker -c rqinit hasmail
16 changes: 0 additions & 16 deletions rqdev.py

This file was deleted.

4 changes: 2 additions & 2 deletions rqinit.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from urlparse import urlparse

from hasmail import init_for, app
from hasmail import app


init_for('production')
REDIS_URL = app.config.get('REDIS_URL', 'redis://localhost:6379/0')

# REDIS_URL is not taken by setup_default_arguments function of rq/scripts/__init__.py
Expand Down
5 changes: 2 additions & 3 deletions runserver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python
import sys
from hasmail import app, init_for
init_for('dev')
from hasmail import app

try:
port = int(sys.argv[1])
except (IndexError, ValueError):
port = 7890
app.run('0.0.0.0', port=port, debug=True)
app.run('0.0.0.0', port=port)
3 changes: 1 addition & 2 deletions website.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import os.path
sys.path.insert(0, os.path.dirname(__file__))
from hasmail import app as application, init_for
init_for('production')
from hasmail import app as application

0 comments on commit 733c362

Please sign in to comment.