use local dir for config by default
This commit is contained in:
parent
ce60f96137
commit
ca4b81866a
10
README.rst
10
README.rst
@ -32,4 +32,14 @@ This is our documentation for how we get this set up::
|
||||
# gunicorn:
|
||||
gunicorn refstack.web:app
|
||||
|
||||
# To actually configure this winner, check out the config section and
|
||||
# crack open refstack.cfg in vim.
|
||||
# `vim refstack.cfg`
|
||||
|
||||
# Now browse to http://localhost:8000
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
Coming soon!
|
||||
|
@ -18,7 +18,7 @@ sqlalchemy.url = driver://user:pass@localhost/dbname
|
||||
# path to migration scripts
|
||||
script_location = alembic
|
||||
|
||||
sqlalchemy.url = sqlite:///refstack.db
|
||||
sqlalchemy.url = sqlite:///db.sqlite
|
||||
|
||||
|
||||
# Logging configuration
|
||||
|
@ -15,7 +15,11 @@ from .config import DefaultConfig
|
||||
#from .admin import admin
|
||||
#from .extensions import db, mail, cache, login_manager, oid
|
||||
from .extensions import db, mail, login_manager, oid
|
||||
from .utils import INSTANCE_FOLDER_PATH
|
||||
|
||||
from refstack import utils
|
||||
|
||||
|
||||
INSTANCE_FOLDER_PATH = utils.INSTANCE_FOLDER_PATH
|
||||
|
||||
|
||||
# For import *
|
||||
@ -38,9 +42,17 @@ def create_app(config=None, app_name=None, blueprints=None):
|
||||
if blueprints is None:
|
||||
blueprints = DEFAULT_BLUEPRINTS
|
||||
|
||||
# NOTE(termie): Flask has this new instance_path stuff that allows
|
||||
# you to keep config and such in different places, but I don't really
|
||||
# see how that is going to be very helpful, so we're going to stick
|
||||
# to using config relative to the root unless we explicitly set such
|
||||
# a path in the INSTANCE_FOLDER_PATH environment variable.
|
||||
app = Flask(app_name,
|
||||
instance_path=INSTANCE_FOLDER_PATH,
|
||||
instance_relative_config=True)
|
||||
|
||||
|
||||
|
||||
configure_app(app, config)
|
||||
configure_hook(app)
|
||||
configure_blueprints(app, blueprints)
|
||||
@ -50,6 +62,9 @@ def create_app(config=None, app_name=None, blueprints=None):
|
||||
configure_template_filters(app)
|
||||
configure_error_handlers(app)
|
||||
|
||||
if app.debug:
|
||||
print utils.dump_config(app)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@ -59,8 +74,10 @@ def configure_app(app, config=None):
|
||||
# http://flask.pocoo.org/docs/api/#configuration
|
||||
app.config.from_object(DefaultConfig)
|
||||
|
||||
# http://flask.pocoo.org/docs/config/#instance-folders
|
||||
app.config.from_pyfile('production.cfg', silent=True)
|
||||
# If we've set the INSTANCE_FOLDER_PATH environment var, this may be
|
||||
# loaded from an instance folder, otherwise relative to flask.root_path.
|
||||
# http://flask.pocoo.org/docs/config/#instance-folders
|
||||
app.config.from_pyfile('refstack.cfg', silent=True)
|
||||
|
||||
if config:
|
||||
app.config.from_object(config)
|
||||
@ -128,7 +145,7 @@ def configure_logging(app):
|
||||
import logging
|
||||
from logging.handlers import SMTPHandler
|
||||
|
||||
# Set info level on logger, which might be overwritten by handers.
|
||||
# Set info level on logger, which might be overwritten by handlers.
|
||||
# Suppress DEBUG messages.
|
||||
app.logger.setLevel(logging.INFO)
|
||||
|
||||
|
@ -4,16 +4,15 @@
|
||||
|
||||
import os
|
||||
|
||||
from utils import make_dir, INSTANCE_FOLDER_PATH
|
||||
from utils import make_dir, INSTANCE_FOLDER_PATH, PROJECT_ROOT
|
||||
|
||||
|
||||
class BaseConfig(object):
|
||||
|
||||
PROJECT = "fbone"
|
||||
PROJECT = "refstack"
|
||||
|
||||
# Get app root path, also can use flask.root_path.
|
||||
# ../../config.py
|
||||
PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
# The app root path, also can use flask.root_path.
|
||||
PROJECT_ROOT = PROJECT_ROOT
|
||||
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
|
@ -6,15 +6,17 @@
|
||||
Utils has nothing to do with models and views.
|
||||
"""
|
||||
|
||||
import string
|
||||
import random
|
||||
import os
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import os
|
||||
import pprint
|
||||
import random
|
||||
import string
|
||||
|
||||
|
||||
# Instance folder path, make it independent.
|
||||
INSTANCE_FOLDER_PATH = os.path.join('/tmp', 'instance')
|
||||
# Instance folder path, if set, otherwise project root.
|
||||
PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
INSTANCE_FOLDER_PATH = os.environ.get('INSTANCE_FOLDER_PATH', PROJECT_ROOT)
|
||||
|
||||
ALLOWED_AVATAR_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
|
||||
|
||||
@ -104,3 +106,11 @@ def make_dir(dir_path):
|
||||
os.mkdir(dir_path)
|
||||
except Exception, e:
|
||||
raise e
|
||||
|
||||
|
||||
### Begin Non-Fbone stuff
|
||||
|
||||
|
||||
def dump_config(app):
|
||||
"""Useful to dump app config for debug purposes."""
|
||||
return pprint.pformat(dict(app.config.iteritems()))
|
||||
|
@ -33,9 +33,6 @@ from refstack import utils
|
||||
from refstack.models import *
|
||||
|
||||
|
||||
# TODO(termie): temporary hack for first-run experience
|
||||
utils.make_dir(utils.INSTANCE_FOLDER_PATH)
|
||||
|
||||
# TODO(termie): transition all the routes below to blueprints
|
||||
# TODO(termie): use extensions setup from the create_app() call
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user