mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-07-19 04:49:19 +00:00
Add typist simulator
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -14,6 +15,7 @@ logging.basicConfig(level=os.environ.get("LOG_LEVEL", "INFO"))
|
||||
TIMEOUT = 60 # 1 minute
|
||||
|
||||
|
||||
|
||||
def hrule():
|
||||
return "="*int(subprocess.check_output(["tput", "cols"]))
|
||||
|
||||
@@ -99,6 +101,8 @@ def wait_for_prompt():
|
||||
|
||||
|
||||
def check_exit_status():
|
||||
if not verify_status:
|
||||
return
|
||||
token = uuid.uuid4().hex
|
||||
data = "echo {} $?\n".format(token)
|
||||
logging.debug("Sending {!r} to get exit status.".format(data))
|
||||
@@ -155,7 +159,14 @@ for slide in slides:
|
||||
|
||||
|
||||
def send_keys(data):
|
||||
subprocess.check_call(["tmux", "send-keys", data])
|
||||
if simulate_type and data[0] != '^':
|
||||
for key in data:
|
||||
if key == ";":
|
||||
key = "\\;"
|
||||
subprocess.check_call(["tmux", "send-keys", key])
|
||||
time.sleep(0.1*random.random())
|
||||
else:
|
||||
subprocess.check_call(["tmux", "send-keys", data])
|
||||
|
||||
def capture_pane():
|
||||
return subprocess.check_output(["tmux", "capture-pane", "-p"])
|
||||
@@ -172,6 +183,8 @@ except Exception as e:
|
||||
i = 0
|
||||
|
||||
interactive = True
|
||||
verify_status = False
|
||||
simulate_type = True
|
||||
|
||||
while i < len(actions):
|
||||
with open("nextstep", "w") as f:
|
||||
|
||||
Reference in New Issue
Block a user