示例#1
0
def bind_api(app):
    boards = Cache.instance().get(CONST.SYSTEM_DB_BOARD)
    rider = Rider.instance()

    for board in boards:

        action = board['action']
        api = board['api']
        class_name = board['class']
        class_folder = board['path']
        method = board['type']
        print('>>>> ', api, class_name, action, METHODS[method])

        # try lookup controllers class
        path = light.helper.project_path('controllers', class_folder)
        clazz = light.helper.resolve(name=class_name, path=path)
        if clazz:
            if hasattr(clazz, action):
                add_api_rule(app, api, clazz, action, method)
                continue

        # try lookup system class
        path = light.helper.core_path('model')
        clazz = light.helper.resolve(name=class_name, path=path)
        if clazz:
            if hasattr(clazz, action):
                add_api_rule(app, api, clazz, action, method)
                continue

        # try lookup data rider
        if hasattr(rider, class_name):
            clazz = getattr(rider, class_name)
            if hasattr(clazz, action):
                add_api_rule(app, api, clazz, action, method)
                continue
示例#2
0
    def setUpClass():
        os.environ[CONST.ENV_LIGHT_DB_HOST] = '127.0.0.1'
        os.environ[CONST.ENV_LIGHT_DB_PORT] = '57017'
        os.environ[CONST.ENV_LIGHT_DB_USER] = 'light'
        os.environ[CONST.ENV_LIGHT_DB_PASS] = '2e35501c2b7e'

        Cache(CONST.SYSTEM_DB).init()
示例#3
0
def initialize(app=None, domain=None):
    # logging
    Log.init()

    # flask
    if not app:
        app = flask.Flask(__name__)

    if not domain:
        domain = os.getenv(CONST.ENV_LIGHT_APP_DOMAIN)

    # cache
    db = Cache(domain).init()

    # rider
    Rider.instance()

    # TODO: job
    Schedule().start()

    # setup flask
    eio = setup_flask(app, db)

    # If you set the environment variable websocket to off, then eio = null
    if eio:
        return engineio.Middleware(eio, app)
    return app
示例#4
0
def bind_route(app):
    routes = Cache.instance().get(CONST.SYSTEM_DB_ROUTE)
    urls = []

    for route in routes:

        # Do not repeat binding
        url = route['url']
        if url in urls:
            continue

        action = route['action']
        class_name = route['class']
        template = route['template']
        print('>>>> ', url, template, action)

        # try lookup controllers class
        path = light.helper.project_path('controllers')
        clazz = light.helper.resolve(name=class_name, path=path)
        if clazz:
            if hasattr(clazz, action):
                add_html_rule(app, url, clazz, action, template)
                continue

        # render html
        urls.append(url)
        add_html_rule(app, url, None, None, template)
示例#5
0
def bind_api(app):
    boards = Cache.instance().get(CONST.SYSTEM_DB_BOARD)
    rider = Rider.instance()

    for board in boards:

        action = board['action']
        api = board['api']
        class_name = board['class']
        class_folder = board['path']
        method = board['type']
        print('>>>> ', api, class_name, action, METHODS[method])

        # try lookup controllers class
        path = light.helper.project_path('controllers', class_folder)
        clazz = light.helper.resolve(name=class_name, path=path)
        if clazz:
            if hasattr(clazz, action):
                add_api_rule(app, api, clazz, action, method)
                continue

        # try lookup system class
        path = light.helper.core_path('model')
        clazz = light.helper.resolve(name=class_name, path=path)
        if clazz:
            if hasattr(clazz, action):
                add_api_rule(app, api, clazz, action, method)
                continue

        # try lookup data rider
        if hasattr(rider, class_name):
            clazz = getattr(rider, class_name)
            if hasattr(clazz, action):
                add_api_rule(app, api, clazz, action, method)
                continue
示例#6
0
    def __init__(self):
        boards = Cache.instance().get(CONST.SYSTEM_DB_BOARD)
        structures = Cache.instance().get(CONST.SYSTEM_DB_STRUCTURE)

        # Add default schema instance
        for structure in structures:
            schema = structure['schema']
            if not hasattr(self, schema):
                setattr(self, schema, Schema(structure=structure))

        # Use action of board to replace the schema instance method
        for board in boards:
            schema = board['class']
            action = board['action']
            type = board['type']
            if hasattr(self, schema):
                data = Data(board)
                setattr(getattr(self, schema), action, getattr(data, METHODS[type]))
示例#7
0
    def setUpClass():
        os.environ[CONST.ENV_LIGHT_DB_HOST] = '127.0.0.1'
        os.environ[CONST.ENV_LIGHT_DB_PORT] = '57017'
        os.environ[CONST.ENV_LIGHT_DB_USER] = 'light'
        os.environ[CONST.ENV_LIGHT_DB_PASS] = '2e35501c2b7e'

        Cache(CONST.SYSTEM_DB).init()

        # change work dir
        os.chdir(os.path.abspath('../..'))
示例#8
0
    def __init__(self):
        boards = Cache.instance().get(CONST.SYSTEM_DB_BOARD)
        structures = Cache.instance().get(CONST.SYSTEM_DB_STRUCTURE)

        # Add default schema instance
        for structure in structures:
            schema = structure['schema']
            if not hasattr(self, schema):
                setattr(self, schema, Schema(structure=structure))

        # Use action of board to replace the schema instance method
        for board in boards:
            schema = board['class']
            action = board['action']
            type = board['type']
            if hasattr(self, schema):
                data = Data(board)
                setattr(getattr(self, schema), action,
                        getattr(data, METHODS[type]))
示例#9
0
    def __init__(self):

        self.dictionary = {}
        config = Cache.instance().get(CONST.SYSTEM_DB_CONFIG)

        for item in config:
            key = item['type']
            if hasattr(self, key):
                getattr(self, key).add_children(item)
            else:
                attr = Item()
                attr.add_children(item)
                setattr(self, key, attr)
示例#10
0
    def __init__(self):

        self.dictionary = {}
        config = Cache.instance().get(CONST.SYSTEM_DB_CONFIG)

        for item in config:
            key = item['type']
            if hasattr(self, key):
                getattr(self, key).add_children(item)
            else:
                attr = Item()
                attr.add_children(item)
                setattr(self, key, attr)
示例#11
0
def bind_route(app):
    routes = Cache.instance().get(CONST.SYSTEM_DB_ROUTE)

    for route in routes:
        action = route['action']
        url = route['url']
        class_name = route['class']
        template = route['template']
        print('>>>> ', url, action, template)

        # try lookup controllers class
        path = light.helper.project_path('controllers')
        clazz = light.helper.resolve(name=class_name, path=path)
        if clazz:
            if hasattr(clazz, action):
                add_html_rule(app, url, clazz, action, template)
                continue

        # render html
        add_html_rule(app, url, None, None, template)
示例#12
0
 def __init__(self):
     self.catalog = Cache.instance().get(CONST.SYSTEM_DB_I18N)
     self._lang = 'zh'
示例#13
0
 def test_init(self):
     Cache(CONST.SYSTEM_DB).init()
     self.assertIsNotNone(Cache.instance().get(CONST.SYSTEM_DB_CONFIG))
示例#14
0
 def setUp(self):
     os.environ[CONST.ENV_LIGHT_DB_HOST] = 'db.alphabets.cn'
     os.environ[CONST.ENV_LIGHT_DB_PORT] = '57017'
     os.environ[CONST.ENV_LIGHT_DB_USER] = 'light'
     os.environ[CONST.ENV_LIGHT_DB_PASS] = '2e35501c2b7e'
     Cache(CONST.SYSTEM_DB).init()
示例#15
0
    def __init__(self):
        structures = Cache.instance().get(CONST.SYSTEM_DB_STRUCTURE)

        for structure in structures:
            setattr(self, structure['schema'], structure)