|
|
|
try:
|
|
|
|
import psycopg2
|
|
|
|
except ImportError:
|
|
|
|
# Fall back to psycopg2cffi
|
|
|
|
from psycopg2cffi import compat
|
|
|
|
compat.register()
|
|
|
|
|
|
|
|
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()
|