mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] don't timeout by default on cli
This commit is contained in:
parent
f99b1e4152
commit
d8313e84aa
5 changed files with 9 additions and 8 deletions
|
@ -109,7 +109,7 @@ def api(namespaces, host='localhost', port=80, routes={},
|
|||
return 0
|
||||
|
||||
def cli(namespaces, args, use_cache=True, output_as=None,
|
||||
password=None, parser_kwargs={}):
|
||||
password=None, timeout=None, parser_kwargs={}):
|
||||
"""Command line interface
|
||||
|
||||
Execute an action with the moulinette from the CLI and print its
|
||||
|
@ -135,7 +135,7 @@ def cli(namespaces, args, use_cache=True, output_as=None,
|
|||
'parser_kwargs': parser_kwargs,
|
||||
},
|
||||
)
|
||||
moulinette.run(args, output_as=output_as, password=password)
|
||||
moulinette.run(args, output_as=output_as, password=password, timeout=timeout)
|
||||
except MoulinetteError as e:
|
||||
import logging
|
||||
logging.getLogger(namespaces[0]).error(e.strerror)
|
||||
|
|
|
@ -425,7 +425,7 @@ class ActionsMap(object):
|
|||
else:
|
||||
return auth()
|
||||
|
||||
def process(self, args, timeout=0, **kwargs):
|
||||
def process(self, args, timeout=None, **kwargs):
|
||||
"""
|
||||
Parse arguments and process the proper action
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ class MoulinetteLock(object):
|
|||
lock
|
||||
|
||||
"""
|
||||
def __init__(self, namespace, timeout=0, interval=.5):
|
||||
def __init__(self, namespace, timeout=None, interval=.5):
|
||||
self.namespace = namespace
|
||||
self.timeout = timeout
|
||||
self.interval = interval
|
||||
|
@ -573,7 +573,7 @@ class MoulinetteLock(object):
|
|||
self._lock()
|
||||
break
|
||||
|
||||
if (time.time() - start_time) > self.timeout:
|
||||
if self.timeout is not None and (time.time() - start_time) > self.timeout:
|
||||
raise MoulinetteError(errno.EBUSY,
|
||||
m18n.g('instance_already_running'))
|
||||
# Wait before checking again
|
||||
|
|
|
@ -377,7 +377,7 @@ class _ActionsMapPlugin(object):
|
|||
|
||||
"""
|
||||
try:
|
||||
ret = self.actionsmap.process(arguments, route=_route)
|
||||
ret = self.actionsmap.process(arguments, timeout=30, route=_route)
|
||||
except MoulinetteError as e:
|
||||
raise error_to_response(e)
|
||||
else:
|
||||
|
|
|
@ -322,7 +322,7 @@ class Interface(BaseInterface):
|
|||
|
||||
self.actionsmap = actionsmap
|
||||
|
||||
def run(self, args, output_as=None, password=None):
|
||||
def run(self, args, output_as=None, password=None, timeout=None):
|
||||
"""Run the moulinette
|
||||
|
||||
Process the action corresponding to the given arguments 'args'
|
||||
|
@ -335,6 +335,7 @@ class Interface(BaseInterface):
|
|||
- plain: return a script-readable output
|
||||
- none: do not output the result
|
||||
- password -- The password to use in case of authentication
|
||||
- timeout -- Number of seconds before this command will timeout because it can't acquire the lock (meaning that another command is currently running), by default there is no timeout and the command will wait until it can get the lock
|
||||
|
||||
"""
|
||||
if output_as and output_as not in ['json', 'plain', 'none']:
|
||||
|
@ -349,7 +350,7 @@ class Interface(BaseInterface):
|
|||
lambda a,h: a(password=password))
|
||||
|
||||
try:
|
||||
ret = self.actionsmap.process(args, timeout=30)
|
||||
ret = self.actionsmap.process(args, timeout=timeout)
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
raise MoulinetteError(errno.EINTR, m18n.g('operation_interrupted'))
|
||||
|
||||
|
|
Loading…
Reference in a new issue