Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except RPCError, e:
results.append(
{'name':process.config.name,
'group':group.config.name,
'status':e.code,
'description':e.text})
else:
results.append(
{'name':process.config.name,
'group':group.config.name,
'status':Faults.SUCCESS,
'description':'OK'}
)
if callbacks:
return NOT_DONE_YET
return results
def handleAction(self):
form = self.context.form
action = form.get('action')
if action:
# trigger deferred action and wait
processname = form.get('processname')
if not self.callback:
self.callback = self.make_callback(processname, action)
return NOT_DONE_YET
# intermediate check
message = self.callback()
if message is NOT_DONE_YET: return NOT_DONE_YET
# post to write message
if message is not None:
location = form['SERVER_URL'] + form['PATH_TRANSLATED'] + '?appli={}&message={}&gravity={}'.format(self.applicationName, urllib.quote(message[1]), message[0])
self.context.response['headers']['Location'] = location
def more(self):
if self.finished:
return ''
try:
response = self.callback()
if response is NOT_DONE_YET:
return NOT_DONE_YET
self.finished = True
return self.sendresponse(response)
except:
tb = traceback.format_exc()
# this should go to the main supervisor log file
self.request.channel.server.logger.log('Web interface error', tb)
self.finished = True
self.request.error(500)
def more (self):
while len(self.producers):
p = self.producers[0]
d = p.more()
if d is NOT_DONE_YET:
return NOT_DONE_YET
if d:
return d
else:
self.producers.pop(0)
else:
return b''
def __call__(self):
body = self.render()
if body is NOT_DONE_YET:
return NOT_DONE_YET
response = self.context.response
headers = response['headers']
headers['Content-Type'] = self.content_type
headers['Pragma'] = 'no-cache'
headers['Cache-Control'] = 'no-cache'
headers['Expires'] = http_date.build_http_date(0)
response['body'] = body
return response
if isinstance(value, types.FunctionType):
callbacks.append(value)
else:
results.append(value)
# we are done when there's no callback and no more calls queued
if callbacks or remaining_calls:
return NOT_DONE_YET
else:
return results
multi.delay = 0.05
# optimization: multi() is called here instead of just returning
# multi in case all calls complete and we can return with no delay.
value = multi()
if value is NOT_DONE_YET:
return multi
else:
return value
@functools.wraps(meth)
def wrapper(*args, **kwargs):
args[0]._log.debug('0RPC: called {}'.format(meth.__name__))
result = meth(*args, **kwargs)
if callable(result):
r = NOT_DONE_YET
while r is NOT_DONE_YET:
sleep(0.1)
r = result()
result = r
return result
return wrapper
def stopall():
if callback() is NOT_DONE_YET:
return NOT_DONE_YET
else:
return 'All stopped at %s' % time.ctime()
stopall.delay = 0.05
def more (self):
if self.producer:
result = self.producer.more()
if result is NOT_DONE_YET:
return NOT_DONE_YET
if not result:
self.producer = None
self.function (self.bytes)
else:
self.bytes += len(result)
return result
else:
return b''
def render(self):
form = self.context.form
response = self.context.response
processname = form.get('processname')
action = form.get('action')
message = form.get('message')
if action:
if not self.callback:
self.callback = self.make_callback(processname, action)
return NOT_DONE_YET
else:
message = self.callback()
if message is NOT_DONE_YET:
return NOT_DONE_YET
if message is not None:
server_url = form['SERVER_URL']
location = server_url + '?message=%s' % urllib.quote(
message)
response['headers']['Location'] = location
supervisord = self.context.supervisord
rpcinterface = RootRPCInterface(
[('supervisor',
SupervisorNamespaceRPCInterface(supervisord))]
)