Skip to content

Commit

Permalink
Using configuration module
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud BRETON committed Sep 26, 2013
1 parent fb525b6 commit e577493
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions BufferedSmtpHandler.py
Expand Up @@ -28,10 +28,10 @@
"""
from google.appengine.api import mail
import logging, logging.handlers
from configuration import configuration_dict

class BufferingSMTPHandler(logging.handlers.BufferingHandler):
FROM = 'arnaud@unishared.com'
TO = 'arnaud@unishared.com'
FROM = TO = configuration_dict['admin_email']

def __init__(self, capacity):
logging.handlers.BufferingHandler.__init__(self, capacity)
Expand Down
6 changes: 1 addition & 5 deletions app.yaml
Expand Up @@ -48,8 +48,4 @@ builtins:

libraries:
- name: jinja2
version: latest

env_variables:
SEGMENTIO_PRODUCTION: '7i4twht1o5'
SEGMENTIO_STAGING: 'p1iuc2hebz'
version: latest
17 changes: 17 additions & 0 deletions configuration.py
@@ -0,0 +1,17 @@
# Copyright (C) 2013 UniShared Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
__author__ = 'arnaud'

import json
from base_handlers import BaseHandler

environment = 'production' if BaseHandler.is_production() else 'staging'
config_filename = 'config_{0}.json'.format(environment)
config_file = open(config_filename)
configuration_dict = json.load(config_file)
config_file.close()
7 changes: 3 additions & 4 deletions evernote_handlers.py
Expand Up @@ -22,15 +22,14 @@
from evernote.edam.error.ttypes import EDAMUserException
from oauth2client.appengine import StorageByKeyName
from models import EvernoteCredentials
from configuration import configuration_dict
import logging

class BaseEvernoteHandler(BaseHandler):
"""Base request handler for Evernote applications.
Adds Authorization support for Evernote.
"""
EN_CONSUMER_KEY = 'videonotes'
EN_CONSUMER_SECRET = 'c0a52fafb28eba20'

def handle_exception(self, exception, debug):
# If the exception is a HTTPException with 401/403 status code use its error code.
Expand All @@ -48,8 +47,8 @@ def get_session_credentials(self):

def get_client(self):
return EvernoteClient(
consumer_key=BaseEvernoteHandler.EN_CONSUMER_KEY,
consumer_secret=BaseEvernoteHandler.EN_CONSUMER_SECRET,
consumer_key=configuration_dict['evernote_consumer_key'],
consumer_secret=configuration_dict['evernote_consumer_secret'],
sandbox=False
)

Expand Down
13 changes: 6 additions & 7 deletions main.py
Expand Up @@ -39,7 +39,7 @@
from oauth2client.appengine import simplejson as json
import logging
from utils import SibPath

from configuration import configuration_dict

# Configure error logger
logger = logging.getLogger("error")
Expand Down Expand Up @@ -442,7 +442,7 @@ def get(self):
production = BaseHandler.is_production()

logging.debug('Get configuration, production %s', production)
segment_io_account = [os.environ.get('SEGMENTIO_STAGING'), os.environ.get('SEGMENTIO_PRODUCTION')][production]
segment_io_account = configuration_dict['segmentio']
logging.debug('Segment IO account %s', segment_io_account)
app_id = flow_from_clientsecrets('client_secrets_{0}.json'.format(self.get_version()), scope='').client_id.split('.')[0].split('-')[0]
logging.debug('App id %s', app_id)
Expand Down Expand Up @@ -521,11 +521,10 @@ def getbytes(self, begin, length):
return self._body[begin:begin + length]

# Create an WSGI application suitable for running on App Engine
config = {}
config['webapp2_extras.sessions'] = {
app_config = {}
app_config['webapp2_extras.sessions'] = {
'secret_key': SESSION_SECRET,
}

app = webapp2.WSGIApplication(
[
webapp2.Route(r'/', HomePage, 'home'),
Expand All @@ -540,5 +539,5 @@ def getbytes(self, begin, length):
webapp2.Route(r'/export/evernote/<:[A-Za-z0-9\-_]*>', ExportEvernoteHandler),
],
# XXX Set to False in production.
debug=not BaseHandler.is_production(), config=config
)
debug=not BaseHandler.is_production(), config=app_config
)

0 comments on commit e577493

Please sign in to comment.