Пример #1
0
def login_handler(msg):
    user = msg.body
    id = vertx.config()['user-prefix'] + str(uuid.uuid4())
    users.add(user)
    EventBus.register_handler(id, 
                              handler=lambda msg: command_handler(user, msg))
    EventBus.publish(vertx.config()['users-address'], user)
    msg.reply({'id': id, 'users': list(users)})
 def __init__(self, db_path, address, eventBus, base):
     #remote_debugger.breakpoint()
     self.db_path = db_path
     self.address = address
     self.eventBus = eventBus
     self.base = base
     self.page_len = 30
     self.metadata = base.metadata
     print(File(vertx.config()["model-path"]).getAbsolutePath())
     for py_file in File(vertx.config()["model-path"]).listFiles():
         print (py_file.getAbsolutePath().lower())
         if str(py_file.getAbsolutePath()).lower().endswith(".py"):
             module=imp.load_source(py_file.getName(), py_file.getAbsolutePath())
             if hasattr(module,"init"):
                 clazz = module.init(Base)
                 print("load %s in %s" % (clazz,clazz.__name__) )
                 setattr(self,clazz.__name__, clazz)
Пример #3
0
def command_handler(user, msg):
    body = msg.body
    status = 'unknown-command'
    if (body['command'] == 'say'):
        EventBus.publish(vertx.config()['messages-address'], 
                         {'user': user, 
                          'message': body['payload']})
        status = 'ok'
    msg.reply({'status': status})
Пример #4
0
def build_route():
    router=RouteMatcher()

    cfg = vertx.config()
    config=JsonObject(cfg).getObject("router")

    for route in config.getArray("routes"):
        controller_description = route.getString("controller")



        def controller_name(): return str(controller_description).split(".")[0]

        if not route.getString("get") is None:
            print("get:"+str(route))
            router.get( route.getString("get"),controller_renderer(config.getString("controller-path"),controller_name(),route.getString("view"),renderer(route,controller_description),cfg["session-dir"]))
        elif not route.getString("post") is None:
            print("post:"+str(route))
            router.post( route.getString("post"),controller_renderer(config.getString("controller-path"),controller_name(),route.getString("view"),renderer(route,controller_description),cfg["session-dir"]))
        elif not route.getString("static") is None:
            print("static:"+str(route))
            router.get(route.getString("static"),static_files_renderer(route.getString("folder")) )
    return router
Пример #5
0
import vertx # this must be at the top of the file.
from hbdriver import init_controller, init_autostart, init_credmgr, init_test_setup

config = vertx.config()

init_credmgr(config)
init_controller(config)
init_test_setup(config)
init_autostart(config)
print "hi"
Пример #6
0
from org.vertx.testtools import VertxAssert
import vertx_tests
from core.event_bus import EventBus
import vertx

type = vertx.config()['type']

if type == 'fail':
    VertxAssert.fail('failed')
elif type == 'assert_fail':
    VertxAssert.assertEquals('foo', 'bar')
elif type == 'assert_ok':
    VertxAssert.assertEquals('foo', 'foo')
    VertxAssert.testComplete()


Пример #7
0
import vertx
from core.event_bus import EventBus
from core.file_system import FileSystem
from core.http import RouteMatcher 

from server import upload
from server import file_service
#inicialize
server = vertx.create_http_server()

route_matcher = RouteMatcher()
logger = vertx.logger()
fs = vertx.file_system()
app_config = vertx.config()

#set global
path_web = app_config['paths']['web']
path_public = app_config['paths']['path_public']
path_symlink = app_config['paths']['path_symlink']

#cros module variable
##TODO
upload.path_public = path_public
file_service.path_public = path_public
file_service.path_private = app_config['paths']['path_private']
upload.path_symlink = path_symlink
upload.path_upload = app_config['paths']['path_private']
upload.path_temp = app_config['paths']['path_temp']

def index_handler(req):    
    req.response.send_file( "%sindex.html"% path_web)
Пример #8
0
# Copyright 2011-2012 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import vertx
from test_utils import TestUtils
from core.event_bus import EventBus

tu = TestUtils()

config = vertx.config()
tu.azzert(config['foo'] == 'bar')

EventBus.send("test-handler", "started")


def vertx_stop():
    EventBus.send("test-handler", "stopped")
Пример #9
0
def start_tests(locs) :
    method_name = vertx.config()['methodName']
    locs[method_name]()
Пример #10
0
    print ">> %s" % message.body
    print message

def vertx_stop():
    print 'doing some cleanup'
    import sys
    sys.modules.clear()

def get_subclasses(c):
    subclasses = c.__subclasses__()
    for d in list(subclasses):
        subclasses.extend(get_subclasses(d))
    return subclasses

if __name__ == '__main__':
    conf = vertx.config()
    logger = vertx.logger()

    #EventBus.register_handler('auth.github.login', False, log_event)

    rm = RouteMatcher()
    for cls in get_subclasses(mw.Middleware):
        logger.debug("init " + cls.__name__)
        if issubclass(cls, mw.Controller):
            cls().register(rm)
        elif issubclass(cls, mw.EventHandler):
            cls().register()
        else:
            cls().register()

    def msg_handler(message):
Пример #11
0
import uuid
import vertx
from core.event_bus import EventBus

# message format: {'command': 'say', 'payload': 'ahoyhoy'}
def command_handler(user, msg):
    body = msg.body
    status = 'unknown-command'
    if (body['command'] == 'say'):
        EventBus.publish(vertx.config()['messages-address'], 
                         {'user': user, 
                          'message': body['payload']})
        status = 'ok'
    msg.reply({'status': status})

users = set()

# message format: 'username'
def login_handler(msg):
    user = msg.body
    id = vertx.config()['user-prefix'] + str(uuid.uuid4())
    users.add(user)
    EventBus.register_handler(id, 
                              handler=lambda msg: command_handler(user, msg))
    EventBus.publish(vertx.config()['users-address'], user)
    msg.reply({'id': id, 'users': list(users)})

EventBus.register_handler(vertx.config()['login-address'], 
                          handler=login_handler)