mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
now pause behaves like v1 pause
This commit is contained in:
parent
f7707d8850
commit
dc80bc8929
1 changed files with 22 additions and 20 deletions
|
@ -110,32 +110,35 @@ class ActionModule(ActionBase):
|
||||||
tty.setraw(fd)
|
tty.setraw(fd)
|
||||||
|
|
||||||
# flush the buffer to make sure no previous key presses
|
# flush the buffer to make sure no previous key presses
|
||||||
# are read in below
|
# are read in below
|
||||||
termios.tcflush(self._connection._new_stdin, termios.TCIFLUSH)
|
termios.tcflush(self._connection._new_stdin, termios.TCIFLUSH)
|
||||||
|
|
||||||
# read key presses and act accordingly
|
|
||||||
while True:
|
while True:
|
||||||
key_pressed = self._connection._new_stdin.read(1)
|
try:
|
||||||
if pause_type in ('minutes', 'seconds'):
|
if seconds:
|
||||||
if key_pressed == '\x03':
|
|
||||||
key_pressed = self._connection._new_stdin.read(1)
|
key_pressed = self._connection._new_stdin.read(1)
|
||||||
if key_pressed == 'a':
|
if key_pressed == '\x03':
|
||||||
raise KeyboardInterrupt
|
raise KeyboardInterrupt
|
||||||
elif key_pressed == 'c':
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
if key_pressed == '\x03':
|
|
||||||
raise KeyboardInterrupt
|
|
||||||
elif key_pressed == '\r':
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
result['user_input'] += key_pressed
|
# read key presses and act accordingly
|
||||||
|
key_pressed = self._connection._new_stdin.read(1)
|
||||||
|
if key_pressed == '\x03':
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
elif key_pressed == '\r':
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
result['user_input'] += key_pressed
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
if seconds is not None:
|
||||||
|
signal.alarm(0)
|
||||||
|
self._display.display("Press 'C' to continue the play or 'A' to abort \r"),
|
||||||
|
key_pressed = self._connection._new_stdin.read(1)
|
||||||
|
if key_pressed.lower() == 'a':
|
||||||
|
raise AnsibleError('user requested abort!')
|
||||||
|
elif key_pressed.lower() == 'c':
|
||||||
|
break
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
# cancel the previously set alarm signal
|
|
||||||
if seconds is not None:
|
|
||||||
signal.alarm(0)
|
|
||||||
raise AnsibleError('user requested abort!')
|
|
||||||
except AnsibleTimeoutExceeded:
|
except AnsibleTimeoutExceeded:
|
||||||
# this is the exception we expect when the alarm signal
|
# this is the exception we expect when the alarm signal
|
||||||
# fires, so we simply ignore it to move into the cleanup
|
# fires, so we simply ignore it to move into the cleanup
|
||||||
|
@ -153,7 +156,6 @@ class ActionModule(ActionBase):
|
||||||
duration = round(duration / 60.0, 2)
|
duration = round(duration / 60.0, 2)
|
||||||
else:
|
else:
|
||||||
duration = round(duration, 2)
|
duration = round(duration, 2)
|
||||||
|
|
||||||
result['stdout'] = "Paused for %s %s" % (duration, duration_unit)
|
result['stdout'] = "Paused for %s %s" % (duration, duration_unit)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue