Python bottle.app() Examples

The following are 15 code examples of bottle.app(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bottle , or try the search function .
Example #1
Source File: sm_ansible_server.py    From contrail-server-manager with Apache License 2.0 6 votes vote down vote up
def __init__(self, args_str=None):
        try:
            self._smgr_log = ServerMgrlogger()
        except:
            print "Error Creating logger object"

        self._smgr_log.log(self._smgr_log.INFO, "Starting SM Ansible Server")
        if not args_str:
            args_str = sys.argv[1:]
        self._parse_args(args_str)
        self.joinq  = Queue.Queue()
        self.joiner = Joiner(self.joinq)
        self.joiner.start()
        self._smgr_log.log(self._smgr_log.INFO,  'Initializing Bottle App')
        self.app = bottle.app()
        bottle.route('/run_ansible_playbooks', 'POST',
                self.start_ansible_playbooks) 
Example #2
Source File: sm_ansible_server.py    From contrail-server-manager with Apache License 2.0 6 votes vote down vote up
def main(args_str=None):
    '''
    Spawn the webserver for Ansible operations
    '''
    sm_pid = os.getpid()
    pid_file = \
    "/var/run/contrail-server-manager/contrail-server-manager-ansible.pid"
    dir = os.path.dirname(pid_file)
    if not os.path.exists(dir):
        os.mkdir(dir)
    f = open(pid_file, "w")
    f.write(str(sm_pid))
    f.close()

    try:
        srvr = SMAnsibleServer(args_str)
        bottle.run(app=srvr.app, host=srvr._args.ansible_srvr_ip,
            port=srvr._args.ansible_srvr_port, debug=True, server='paste')
    except Exception as e:
        print "Container server was not started successfully" 
Example #3
Source File: dispatcher.py    From eavatar-me with Apache License 2.0 6 votes vote down vote up
def __call__(self, wsgi_env, start_response):
        script = wsgi_env.get(b'PATH_INFO', b'')
        # logger.debug("initial script: %s", script)
        path_info = b''
        while b'/' in script:
            if script in self.mounts:
                app = self.mounts[script]
                break
            script, last_item = script.rsplit(b'/', 1)
            # last_item = unicode(last_item, 'utf-8')
            path_info = b'/{0}{1}'.format(last_item, path_info)
        else:
            # logger.debug("Selected script: %s", script)
            app = self.mounts.get(script, self.app)
        original_script_name = wsgi_env.get(b'SCRIPT_NAME', b'')
        wsgi_env[b'SCRIPT_NAME'] = original_script_name + script
        wsgi_env[b'PATH_INFO'] = path_info
        return app(wsgi_env, start_response) 
Example #4
Source File: cli.py    From buttervolume with Apache License 2.0 6 votes vote down vote up
def purge(args, test=False):
    urlpath = '/VolumeDriver.Snapshots.Purge'
    param = {'Name': args.name[0],
             'Pattern': args.pattern[0],
             'Dryrun': args.dryrun}
    if test:
        param['Test'] = True
        resp = TestApp(app).post(urlpath, json.dumps(param))
    else:
        resp = Session().post(
            'http+unix://{}{}'
            .format(urllib.parse.quote_plus(USOCKET), urlpath),
            json.dumps(param))
    res = get_from(resp, '')
    if res:
        print(res)
    return res 
Example #5
Source File: cli.py    From buttervolume with Apache License 2.0 6 votes vote down vote up
def run(args):
    global CURRENTTIMER
    if not os.path.exists(VOLUMES_PATH):
        log.info('Creating %s', VOLUMES_PATH)
        os.makedirs(VOLUMES_PATH, exist_ok=True)
    if not os.path.exists(SNAPSHOTS_PATH):
        log.info('Creating %s', SNAPSHOTS_PATH)
        os.makedirs(SNAPSHOTS_PATH, exist_ok=True)
    # run a thread for the scheduled snapshots
    print('Starting scheduler job every {}s'.format(TIMER))
    CURRENTTIMER = Timer(1, scheduler)
    CURRENTTIMER.start()
    signal.signal(signal.SIGTERM, shutdown)
    # listen to requests
    print('Listening to requests...')
    serve(app, unix_socket=SOCKET, unix_socket_perms='660') 
Example #6
Source File: app.py    From mailchute with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create_app():
    app = bottle.app()
    _route(app, '/emails', ['GET'], resource.get_emails)
    _route(
        app, '/emails/<email_id:int>', ['DELETE'],
        resource.delete_email)
    _route(
        app, '/raw_messages/<raw_message_id>', ['GET'],
        resource.get_raw_message)

    @app.hook('after_request')
    def enable_cors():
        ALLOWED_METHODS = 'PUT, GET, POST, DELETE, OPTIONS'
        ALLOWED_HEADERS = \
            'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Methods'] = ALLOWED_METHODS
        response.headers['Access-Control-Allow-Headers'] = ALLOWED_HEADERS

    return app 
Example #7
Source File: dispatcher.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def __init__(self, app, mounts=None):
        self.app = app
        self.mounts = mounts or {} 
Example #8
Source File: dispatcher.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def mount(self, path, app):
        # logger.debug("Mounting app at %s", path)
        if isinstance(path, unicode):
            path = path.encode('utf-8')
        self.mounts[path] = app
        return app 
Example #9
Source File: dispatcher.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def unmount(self, path):
        logger.debug("Unmounting app at %s", path)
        if isinstance(path, unicode):
            path = path.encode('utf-8')
        app = self.mounts.get(path)
        if app is not None:
            del self.mounts[path]
            return app
        return None

# the global web application 
Example #10
Source File: server.py    From steam-buddy with MIT License 5 votes vote down vote up
def edit(platform, name):
    if platform == "flathub":
        application = FLATHUB_HANDLER.get_application(name)
        if application:
            return template('flathub_edit', app=application, platform="flathub", platformName="Flathub",
                            name=name, )
        else:
            abort(404, '{} not found in Flathub'.format(name))
    shortcuts = load_shortcuts(platform)

    matches = [e for e in shortcuts if e['name'] == name and e['cmd'] == platform]
    shortcut = matches[0]

    return template('new.tpl', isEditing=True, platform=platform, platformName=PLATFORMS[platform], name=name,
                    hidden=shortcut['hidden']) 
Example #11
Source File: main.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def api_help():
    endpoints = []
    for route in app.app.routes:
        if '/api/' in route.rule:
            endpoints.append(route.rule)

    return dict(endpoints=endpoints)


# Mute DeprecationWarning 
Example #12
Source File: cli.py    From buttervolume with Apache License 2.0 5 votes vote down vote up
def snapshot(args, test=False):
    urlpath = '/VolumeDriver.Snapshot'
    param = json.dumps({'Name': args.name[0]})
    if test:
        resp = TestApp(app).post(urlpath, param)
    else:
        resp = Session().post(
            'http+unix://{}{}'
            .format(urllib.parse.quote_plus(USOCKET), urlpath),
            param)
    res = get_from(resp, 'Snapshot')
    if res:
        print(res)
    return res 
Example #13
Source File: cli.py    From buttervolume with Apache License 2.0 5 votes vote down vote up
def send(args, test=False):
    urlpath = '/VolumeDriver.Snapshot.Send'
    param = {'Name': args.snapshot[0], 'Host': args.host[0]}
    if test:
        param['Test'] = True
        resp = TestApp(app).post(urlpath, json.dumps(param))
    else:
        resp = Session().post(
            'http+unix://{}{}'
            .format(urllib.parse.quote_plus(USOCKET), urlpath),
            json.dumps(param))
    res = get_from(resp, '')
    if res:
        print(res)
    return res 
Example #14
Source File: cli.py    From buttervolume with Apache License 2.0 5 votes vote down vote up
def sync(args, test=False):
    urlpath = '/VolumeDriver.Volume.Sync'
    param = {'Volumes': args.volumes, 'Hosts': args.hosts}
    if test:
        param['Test'] = True
        resp = TestApp(app).post(urlpath, json.dumps(param))
    else:
        resp = Session().post(
            'http+unix://{}{}'
            .format(urllib.parse.quote_plus(USOCKET), urlpath),
            json.dumps(param))
    res = get_from(resp, '')
    if res:
        print(res)
    return res 
Example #15
Source File: app.py    From mailchute with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _route(app, uri, methods, handler):
    app.route(uri, ['OPTIONS'])(lambda *a, **kw: {})
    app.route(uri, methods)(handler)