[enh] don't timeout by default on cli

This commit is contained in:
Laurent Peuch 2016-12-03 00:09:02 +01:00
parent f99b1e4152
commit d8313e84aa
5 changed files with 9 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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'))