You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cookie-api/wsgi.py

53 lines
1.2 KiB
Python

import os
import sys
from cookie_api import JSONRenderer, Base, application_factory
settings = {
'DATABASE': {
'URL': 'postgresql://apistar:local@localhost/apistar',
'METADATA': Base.metadata
},
'RENDERERS': [JSONRenderer()],
'JWT': {
'SECRET': 'thisisasecret'
},
'LOGGING': {
"LOG_FILE": 'mylogfile.log',
"LEVEL": "DEBUG"
}
}
def prepare_import(path):
"""Given a filename this will try to calculate the python path, add it
to the search path and return the actual module name that is expected.
"""
path = os.path.realpath(path)
if os.path.splitext(path)[1] == '.py':
path = os.path.splitext(path)[0]
if os.path.basename(path) == '__init__':
path = os.path.dirname(path)
module_name = []
# move up until outside package structure (no __init__.py)
while True:
path, name = os.path.split(path)
module_name.append(name)
if not os.path.exists(os.path.join(path, '__init__.py')):
break
if sys.path[0] != path:
sys.path.insert(0, path)
return '.'.join(module_name[::-1])
app = application_factory(settings)
if __name__ == "__main__":
app.main()