Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic configuration #26

Merged
merged 3 commits into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ bower install

## Running the app

First configure the app based on the environment you're running it in. If you are developing, you must set the `FLASK_ENVIRONMENT` environment variable to `development`.

```
export FLASK_ENVIRONMENT=development
```

To start the app simply run the following from the top level directory:

```
Expand All @@ -35,4 +41,4 @@ gunicorn app:app

## Contributing

See [CONTRIBUTING.md](https://github.com/BinghamtonCoRE/bikeshare/blob/develop/CONTRIBUTING.md)
See [CONTRIBUTING.md](https://github.com/BinghamtonCoRE/bikeshare/blob/develop/CONTRIBUTING.md)
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Helper to run the app"""
from bikeshare_app import app
# Dont call app.run(). Uwsgi will do this for us

if __name__ == "__main__":
app.run()
6 changes: 2 additions & 4 deletions bikeshare_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask.ext.bower import Bower
from bikeshare_app.config import configure_app

app = Flask(__name__)
configure_app(app)
Bower(app)
app.config['MONGODB_SETTINGS'] = {
'db': 'bikeshare'
}
app.debug = True
db = MongoEngine(app)

import bikeshare_app.views
36 changes: 36 additions & 0 deletions bikeshare_app/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Module containing configurations for the flask server"""
from os import getenv
# TODO: Setup a logging environment

# pylint: disable=too-few-public-methods
class BaseConfig(object):
"""The base configuration that should be used in production"""
DEBUG = False
TESTING = False
MONGODB_SETTINGS = {'db': 'bikeshare'}

class TestingConfig(BaseConfig):
"""Configuration for running unit tests"""
DEBUG = False
TESTING = True
MONGODB_SETTINGS = {'db': 'bikeshare-test'}

class DevelopmentConfig(BaseConfig):
"""The configuration that should be run during development"""
DEBUG = True
TESTING = True
MONGODB_SETTINGS = {'db': 'bikeshare-test'}

CONFIG = {
"development": "bikeshare_app.config.DevelopmentConfig",
"testing": "bikeshare_app.config.TestingConfig",
"default": "bikeshare_app.config.BaseConfig"
}

def configure_app(app):
"""Configure the app based on where it is deployed. First check for the
FLASK_ENVIRONMENT environment variable, fallback to the default
BaseConfig"""
config_name = getenv("FLASK_ENVIRONMENT", "default")
print(config_name)
app.config.from_object(CONFIG[config_name])
5 changes: 3 additions & 2 deletions scripts/testDBData.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
import sys
from pymongo import MongoClient
from random import randint
Expand All @@ -19,8 +20,8 @@

client = MongoClient()

db = client.bikeshare
print("Created database: 'bikeshare'")
db = client['bikeshare-test']
print("Created database: 'bikeshare-test'")
db.user.drop()
db.activeshare.drop()

Expand Down