本文整理汇总了Python中bottle.app方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.app方法的具体用法?Python bottle.app怎么用?Python bottle.app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle
的用法示例。
在下文中一共展示了bottle.app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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)
示例2: main
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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"
示例3: __call__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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)
示例4: purge
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例5: run
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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')
示例6: create_app
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例7: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
def __init__(self, app, mounts=None):
self.app = app
self.mounts = mounts or {}
示例8: mount
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例9: unmount
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例10: edit
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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'])
示例11: api_help
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例12: snapshot
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例13: send
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例14: sync
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
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
示例15: _route
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import app [as 别名]
def _route(app, uri, methods, handler):
app.route(uri, ['OPTIONS'])(lambda *a, **kw: {})
app.route(uri, methods)(handler)