Example #1
0
def startVesperInstance(port, queue):
    try:
        import coverage, sys, signal, atexit
        coverage.process_startup()        
        
        def safeterminate(num, frame):
            #coverage registers an atexit function
            #so have atexit functions called when terminating            
            atexit._run_exitfuncs() #for some reason sys.exit isn't calling this
            sys.exit()
        
        signal.signal(signal.SIGTERM, safeterminate)
    except ImportError:
        pass
        
    @app.Action
    def sendServerStartAction(kw, retVal):
        # print "startReplication callback!"
        queue.put('server ready')
    
    @Route('testresult')#, REQUEST_METHOD='POST')
    def handleTestresult(kw, retval):
        queue.put(json.loads(kw._postContent))
        kw._responseHeaders['Content-Type'] = 'application/json'
        return '"OK"'
    
    tmpdir = tempfile.gettempdir()
    print "creating vesper instance on port %d" % (port),'tmp at', tmpdir
    app.createApp(__name__, 'vesper.web.admin', port=port, storage_url="mem://", 
        static_path='browser', 
        actions = {'load-model':[sendServerStartAction]},
        template_path='browser/templates',
        mako_module_dir = os.path.join(tmpdir, 'browserTest_makomodules')
        ,logconfig=logconfig
    ).run()
Example #2
0
def startVesperInstance(trunk_id, nodeId, port, queueHost, queuePort, channel):
    try:
        import coverage, sys, signal, atexit

        coverage.process_startup()

        def safeterminate(num, frame):
            # coverage registers an atexit function
            # so have atexit functions called when terminating
            atexit._run_exitfuncs()  # for some reason sys.exit isn't calling this
            sys.exit()

        signal.signal(signal.SIGTERM, safeterminate)
    except ImportError:
        pass

    print "creating vesper instance:%s (%s:%d)" % (nodeId, queueHost, port)
    # assume remote queue implements message ack
    sendAck = True
    if startQueue is startMorbidQueue:
        # morbid doesn't support stomp ack
        sendAck = False

    conf = {
        "storage_url": "mem://",
        "save_history": True,
        "trunk_id": trunk_id,
        "branch_id": nodeId,
        "replication_hosts": [(queueHost, queuePort)],
        "replication_channel": channel,
        "send_stomp_ack": sendAck,
        "actions": {"http-request": route.gensequence},
    }

    app.createApp(baseapp="miniserver.py", model_uri="test:", port=port, **conf).run()
Example #3
0
    return json.dumps(response, indent=4)
    
try:
    import mako

    @Action
    def displayError(kw, retVal):
        kw._responseHeaders._status = 500
        kw._responseHeaders['content-type'] = 'text/html'
        type = kw._errorInfo.type
        value = kw._errorInfo.value
        tb = kw._errorInfo.traceback
        try:
            #work-around bug in mako.exceptions.html_error_template
            raise type, value, tb         
        except:
            return mako.exceptions.html_error_template().render()#traceback=(type,value,tb))
    
    actions['http-request-error'] = [sendJsonRpcError, displayError]
except ImportError:
    actions['http-request-error'] = [sendJsonRpcError]

app = createApp(
    static_path=['static'],
    default_page_name = 'index.html',
    actions = actions
)

if __name__ == "__main__":
    app.run()
Example #4
0
            dir, path = os.path.split(path)
            assert dir
            static_path.append(dir)

        path = os.path.join('/static', path.lstrip(os.sep))
        if os.sep != '/':
            path = path.replace(os.sep,'/')        
        return path

    config['playbackScripts'] = [(path2url(name), url) for name, url in pages]
    config['testplayback'] = True

app = createApp(__name__, 'vesper.web.baseapp'
              ,static_path=['static']
              ,template_path=['templates']
              ,beforeConfigHook=beforeConfigHook
              ,storeDefaults = dict(
                model_options=dict(serializeOptions=dict(indent=2))
               )
)



#add routes after createApp if you want them to run after base app's routes
Route(r'{path:.+\.html}')(servetemplate)

# entry point from setuptools console_scripts, called with no args
def console_main():
    app.run()

if __name__ == "__main__":
    console_main()
Example #5
0
# from vesper.web.route import Route, servetemplate
from vesper.app import createApp

app = createApp(
    __name__,
    "vesper.web.admin",
    static_path=["static"],  # put static file in "static" sub-directory
    template_path=["templates"],  # put mako template file in "templates" sub-directory
    storage_path="helloworld.json",
    save_history="split",  # turn on separate version store
)

if __name__ == "__main__":
    from vesper.web.baseapp import parseCmdLine

    parseCmdLine()
    app.run()
Example #6
0
            # print "target object:"
            # print target

            for k in updates.keys():
                # print "updating attribute:", k
                target[k] = updates[k]
                
            # print "updated target:"
            # print target
            
            changed = data_store.update(target) # returns statements modified; not so useful
            out['count'] = len(changed)
            
        elif action == 'add':
            data = load_data(params['data'])
            stmts = data_store.add(data)
            out['count'] = len(stmts)
        elif action == 'delete':
            print "XXX delete action not supported!"
            pass
            
        out['success'] = True
    except Exception, e:
        out['success'] = False
        out['error'] = str(e)

    # print out
    return json.dumps(out,sort_keys=True, indent=4)

createApp(__name__)