Пример #1
0
 def run(self):
     try:
         wolf.logger.debug('Listening on %s:%s' %
                           (wolf.config.webaddr, wolf.config.webport))
         run(host=wolf.config.webaddr,
             port=wolf.config.webport,
             quiet=True,
             app=AccessLog(app()))
         wolf.logger.debug('Proxying /net to %s' % wolf.config.netslave)
         mount('/net', HostProxy(wolf.config.netslave))
     except OSError as e:
         wolf.logger.error('Cannot start %s: %s' % (self.name, str(e)))
Пример #2
0
		def servicio_Rest():
			# creamos el servicio  
			servicio = ControladorWS(webpath = WEBPATH)

			servicio.addprotocol(PROTOCOL)

			bottle.mount(WEBPATH, servicio.wsgiapp())

			logging.basicConfig(level=logging.DEBUG)

			database2 = SqliteDatabase(DATABASE, threadlocals=True)

			# Arrancamos el servcio web para la aplicacion
			bottle.run(host=DIRECCION_WS, port=PUERTO_WS)
Пример #3
0
            resposta['servico'] = provider
            resposta['codigo'] = track
            resposta['historico'] = result

            return format_result(resposta)

        except AttributeError:
            message = "404 Pacote %s nao encontrado" % track
            logger.exception(message)
    else:
        message = '404 Servico %s nao encontrado' % provider
        logger.warning(message)
    return make_error(message)

bottle.mount('/v1', app_v1)


@route('/crossdomain.xml')
def crossdomain():
    response.content_type = 'application/xml'
    return template('crossdomain')


def _standalone(port=9876):
    run(host='0.0.0.0', port=port)


if __name__ == "__main__":
    _standalone()
Пример #4
0
from bottle import run
from bottle import mount
from bottle import debug

from controllers import *
from apps.uploader import uploader

mount('/uploader', uploader, name='uploader')

if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--host",
                        default='localhost',
                        dest='host',
                        help="Host name to listen to")
    parser.add_argument("--port",
                        default='8000',
                        type=int,
                        dest='port',
                        help='Port to listen to'),
    parser.add_argument("--server",
                        default='wsgiref',
                        dest='server',
                        help='Server adapter to use'),
    parser.add_argument("--debug",
                        action='store_true',
                        help='Enable dubug mode'),
    parser.add_argument("--reload",
                        action="store_true",
                        help="auto-reload on file changes."),
Пример #5
0
import metadata_webtool.app

if __name__ == "__main__":
    import bottle

    @bottle.route("/static/<path:path>")
    def static(path):
        return bottle.static_file(path, "static")
    bottle.mount("/metadata-webtool/", metadata_webtool.app.app)
    bottle.run()
Пример #6
0
        p.lastname = u('Green')
        r.append(p)
        print r
        return r

    @expose(Person)
    @validate(Person)
    def setperson(self, person):
        return person

    @expose([Person])
    @validate([Person])
    def setpersons(self, persons):
        print persons
        return persons


root = DemoRoot(webpath='/ws')

root.addprotocol('soap',
                 tns='http://example.com/demo',
                 typenamespace='http://example.com/demo/types',
                 baseURL='http://127.0.0.1:8080/ws/')

root.addprotocol('restjson')

bottle.mount('/ws/', root.wsgiapp())

logging.basicConfig(level=logging.DEBUG)
bottle.run()
Пример #7
0
from bottle import run
from bottle import mount
from bottle import debug

from controllers import *
from apps.uploader import uploader

mount("/uploader", uploader, name="uploader")


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument("--host", default="localhost", dest="host", help="Host name to listen to")
    parser.add_argument("--port", default="8000", type=int, dest="port", help="Port to listen to"),
    parser.add_argument("--server", default="wsgiref", dest="server", help="Server adapter to use"),
    parser.add_argument("--debug", action="store_true", help="Enable dubug mode"),
    parser.add_argument("--reload", action="store_true", help="auto-reload on file changes."),
    args = parser.parse_args()

    debug(args.debug)
    run(host=args.host, port=args.port, server=args.server, reloader=args.reload)
else:
    # Change working directory so relative paths (and template lookup) work again
    import os
    import os.path

    os.chdir(os.path.dirname(__file__))

    from bottle import app
Пример #8
0
def get_sender():
    return request.get_header("uniqys-sender")


@app.route('/hello')
def hello():
    return 'Hello Uniqys!'


@app.route('/set', method='POST')
def set():
    sender = get_sender()
    if sender is None:
        return ('error', 400)

    value = request.json.get('value')
    print(value, flush=True)
    db.set('value', str(value))


@app.route('/get')
def get():
    return db.get('value')

mount('/api', app)

run(host='0.0.0.0',
    port=56080,
    debug=True,
    reloader=True)
Пример #9
0
@route("/fail/<report>/<graph>")
def show_fragment(report, graph):
  abort(404, "This page does not exist") 

@route("/static/<filepath:path>")
def static(filepath):
  return static_file(filepath, root="./static/")


###############################
#
# Mount API on /api/ 
#
###############################
from jsonapi import app as api_app
mount("/api/", api_app)


###############################
#
# Handle Errors 
#
###############################
@error(404)
def error404(error):
  return renderfile("404")


#
# Main. To run in developer mode simply pass --run
# 
Пример #10
0
def main(debug=False, reloader=False, host="0.0.0.0"):
    bottle.debug(debug)
    bottle.mount(bottle.app(), "/mips")
    bottle.run(reloader=reloader, host=host)
Пример #11
0
from bottle import mount, route, run, static_file, redirect

import sushi
import gari
from util import get_config

config = get_config()
static_dir_path = '/static'


@route('/')
def index():
    return static_file('index.html', root=static_dir_path)


@route('/<path:path>')
def file_path(path):
    return static_file(path, root=static_dir_path)


mount('/sushi', sushi.app)
mount('/gari', gari.app)

run(server=config['SERVER'],
    workers=config['WORKER_NUM'],
    host=config['HOST'],
    port=config['PORT'],
    debug=config['DEBUG'],
    reloader=config['AUTO_RELOAD'])
Пример #12
0
# -*- coding: utf-8 -*-

from prism_controller import FrontController
import bottle
import logging
import prism_config as config

logging.basicConfig(format='%(asctime)s %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S %p',
                    filename='/tmp/prism.log',
                    level=logging.DEBUG)

root = FrontController(webpath='/prism')

root.addprotocol(
    'soap',
    tns='http://example.com/demo',
    typenamespace='http://example.com/demo/types',
    baseURL='http://' + config.bind_address + ':' + str(config.bind_port) +
    '/prism/',
)

root.addprotocol('restjson')

bottle.mount('/prism/', root.wsgiapp())

logging.basicConfig(level=logging.DEBUG)
#bottle.run()
logging.info("PRISM Starting...")
bottle.run(host=config.bind_address, port=config.bind_port)
Пример #13
0
def _mount(name):
    mount(name, import_module('.' + name, __name__).app)
Пример #14
0
    ws_ms_old = ''
    while 1:
        try:
            if ws_ms != ws_ms_old or first_time:
                wsock.send(ws_ms)
                ws_ms_old = ws_ms
            if first_time:
                first_time = False
            sleep(ws_maker_sleep)
        except WebSocketError:
            #wsock.close()
            break


mount('/seekbar/', app)

# This creates a queue object for every request.

@app.route('/websocket')
def handle_websocket():
    worker_success = 0
    while worker_success == 0:
        try:
            body = queue.Queue()
            worker = ws_maker()
            worker.on_data(body.put)
            worker.on_finish(lambda: body.put(StopIteration))
            worker.start()
            worker_success = 1
            return body
Пример #15
0
    def __init__(self, datebase_name, static_file_path=None, data_dir='./data', loggly_token=None):

        cork_dir = os.path.join(data_dir, 'cork')
        beaker_dir = os.path.join(data_dir, 'beaker')
        bottle.TEMPLATE_PATH.insert(0,'webapi/views/')

        #vars which must be visible across all webapi modules
        shared.static_dir = static_file_path
        shared.plug = bottle.ext.mongo.MongoPlugin(uri="localhost", db=datebase_name, json_mongo=True)

        #install mongo plugin for root app
        install(shared_state.plug)

        #check if cork files exists
        cork_files = ['users.json', 'roles.json', 'register.json']
        if not set(cork_files).issubset(set(os.listdir(cork_dir))):
            #if not, create them
            logger.info('Cork authentication files not found, creating new files.')
            shared.auth = self.populate_conf_directory(cork_dir)
        else:
            shared.auth = Cork(cork_dir)

        #admin depends on shared.auth
        import admin

        #import and mount api version 1 (stable)
        from webapi.api.v1 import app as api_v1
        mount('/api/v1/', api_v1.app)

        #import and mount development version (unstable)
        from webapi.api.d import app as api_d
        mount('/api/d/', api_d.app)

        #must be imported AFTER mounts.
        if shared.static_dir is not None:
            import default_routes

        #wrap root app in beaker middleware
        session_opts = {
            'session.type': 'file',
            'session.cookie_expires': False,
            'session.data_dir': beaker_dir,
            'session.auto': True,
            #set secure attribute on cookie
            'session.secure': True
            }

        self.app = bottle.app()
        if loggly_token:
            self.app = Loggly(bottle.app(), loggly_token)
        self.app = SessionMiddleware(self.app, session_opts)
        
        root_app = bottle.app()

        #setup logging hooks
        @root_app.hook('before_request')
        @api_d.app.hook('before_request')
        @api_v1.app.hook('before_request')
        def log_request():
            user_agent = ""
            if 'HTTP_USER_AGENT' in bottle.request.environ:
                user_agent = bottle.request.environ['HTTP_USER_AGENT']
            if 'REMOTE_ADDR' in bottle.request.environ:
                remote_addr = bottle.request.environ['REMOTE_ADDR']
            else:
                remote_addr = ""
            if 'beaker.session' in bottle.request.environ:
                session = bottle.request.environ.get('beaker.session')
                username = session.get('username', None)
            else:
                username = "******"
            logger.info("[{0}/{1}] {2} {3} ({4})".format(remote_addr, username, request.method, request.fullpath, user_agent))

        def return_text(self, e):
            return e.status

        #make sure error pages for API are pure text
        api_d.app.default_error_handler = types.MethodType(return_text, self)
        api_v1.app.default_error_handler = types.MethodType(return_text, self)
Пример #16
0
            resposta = dict()
            result = []

            for status in encomenda.status:
                historico = dict()

                historico['data'] = status.data
                historico['local'] = status.local
                historico['situacao'] = status.situacao
                historico['detalhes'] = status.detalhes

                result.append(historico)

            resposta['servico'] = provider
            resposta['codigo'] = track
            resposta['historico'] = result

            return json.dumps(resposta)

        except AttributeError:
            response.status = '404 O pacote %s informado nao pode ser localizado' % track
    else:
        response.status = '404 O Servico %s nao pode ser encontrado' % provider


bottle.mount('/v1', app_v1)


def _standalone(port=9876):
    run(host='localhost', port=port)
Пример #17
0
        print r
        return r

    @expose(Person)
    @validate(Person)
    def setperson(self, person):
        return person

    @expose([Person])
    @validate([Person])
    def setpersons(self, persons):
        print persons
        return persons


root = DemoRoot(webpath='/ws')

root.addprotocol(
    'soap',
    tns='http://example.com/demo',
    typenamespace='http://example.com/demo/types',
    baseURL='http://127.0.0.1:8080/ws/',
)

root.addprotocol('restjson')

bottle.mount('/ws/', root.wsgiapp())

logging.basicConfig(level=logging.DEBUG)
bottle.run()