Merge pull request #3129 from vtolstov/wait

builder/qemu: allow to specify time.Duration in special <wait> command
This commit is contained in:
Chris Bednarski 2016-02-04 17:16:07 -08:00
commit 6c35f44104
2 changed files with 17 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net"
"regexp"
"strings"
"time"
"unicode"
@ -154,6 +155,19 @@ func vncSendString(c *vnc.ClientConn, original string) {
continue
}
if strings.HasPrefix(original, "<wait") && strings.HasSuffix(original, ">") {
re := regexp.MustCompile(`<wait([0-9hms]+)>$`)
dstr := re.FindStringSubmatch(original)
if len(dstr) > 1 {
log.Printf("Special code %s found, sleeping", dstr[0])
if dt, err := time.ParseDuration(dstr[1]); err == nil {
time.Sleep(dt)
original = original[len(dstr[0]):]
continue
}
}
}
for specialCode, specialValue := range special {
if strings.HasPrefix(original, specialCode) {
log.Printf("Special code '%s' found, replacing with: %d", specialCode, specialValue)

View File

@ -314,6 +314,9 @@ by the proper key:
sending any additional keys. This is useful if you have to generally wait
for the UI to update before typing more.
- `<waitXX> ` - Add user defined time.Duration pause before sending any
additional keys. For example `<wait10m>` or `<wait1m20s>`
In addition to the special keys, each command to type is treated as a
[configuration template](/docs/templates/configuration-templates.html). The
available variables are: