예제 #1
0
def load_url_map(path, package, log=None):
    log = log or logging.getLogger(__name__)
    url_map = []
    our_dir = path[0]
    for dirpath, dirnames, filenames in os.walk(our_dir):
        for fname in filenames:
            root, ext = os.path.splitext(fname)
            if ext != '.py' or root == '__init__':
                continue
            class_path = os.path.join(dirpath, fname)
            handle_class = imp.load_source(fname, class_path)
            _url_map = getattr(handle_class, 'url_map', {})
            if _url_map:
                for _url, _handler in _url_map.items():
                    url_map.append((_url, getattr(handle_class, _handler)))
    log.info('url map:\n' + '\n'.join(['%20s\t%s' % (_url_map[0], _url_map[1]) \
                                       for _url_map in url_map]))
    return url_map
예제 #2
0
"""Session Handling for SQLAlchemy backend."""

import time
import json
import datetime

import sqlalchemy.interfaces
import sqlalchemy.orm
from sqlalchemy.exc import DisconnectionError, OperationalError
from sqlalchemy.pool import NullPool, StaticPool
from ops_nd import log as logging

LOG = logging.getLogger(__name__)

from ops_nd import exception

from ops_nd.options import get_options

db_options = [
    {
        "name": 'sql_idle_timeout',
        "default": 3600,
        "help": 'timeout before idle sql connections are reaped',
        "type": int,
    },
    {
        "name": 'sql_connection_debug',
        "default": 0,
        "help": 'Verbosity of SQL debugging information. 0=None, '
        '100=Everything',
        "type": int,
예제 #3
0
from ops_nd import log as logging

from ops_nd.service import db as service_db

auth_opts = [
    {
        "name": "policy",
        "default": "ops_nd.api.auth.policy",
        "help": "",
        "type": str,
    },
]

options = get_options(auth_opts, 'auth')

LOG = logging.getLogger()


def load_policy():
    option_split = options.policy.split(".")
    mod = option_split[0]
    fun = options.policy[options.policy.rfind('.') + 1:]
    fn_, modpath, desc = imp.find_module(mod)
    fn_, path, desc = imp.find_module(
        fun, [os.path.join(modpath, "/".join(option_split[1:-1]))])
    return imp.load_module(fun, fn_, path, desc)


class BaseAuth(tornado.web.RequestHandler):
    def __init__(self, application, request, **kwargs):
        super(BaseAuth, self).__init__(application, request, **kwargs)
예제 #4
0
#coding=utf8

from ops_nd.api.utils import load_url_map
from ops_nd import log as logging

LOG = logging.getLogger('api')

url_map = load_url_map(__path__, __package__, log=LOG)