diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-19 22:44:34 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-19 22:44:34 (GMT) |
commit | 9d0225a63984b408c5246696fd06930386a17bca (patch) | |
tree | b0906388651a21d048ec0c4425bd5155dbb7f92d /src/helsinki.at/rhimportd | |
parent | 94eab548c583491912335d58f6442eb952cec5ab (diff) |
progress for telnet interface works now
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlTelnet.go | 58 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSimple.go | 5 |
2 files changed, 37 insertions, 26 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go index 65504f4..b2bcfa1 100644 --- a/src/helsinki.at/rhimportd/ctrlTelnet.go +++ b/src/helsinki.at/rhimportd/ctrlTelnet.go @@ -266,6 +266,37 @@ func (c *TelnetClient) handle_cmd_show(args []string) { } } +func telnet_progress_callback(step int, step_name string, progress float64, userdata interface{}) { + out := userdata.(chan<- string) + out <- fmt.Sprintf("%s: %3.2f%%\r", step_name, progress*100) +} + +func telnet_cmd_run(ctx rhimport.ImportContext, out chan<- string) { + out <- fmt.Sprintf("fetching file from '%s'\n", ctx.SourceUri) + if res, err := rhimport.FetchFile(&ctx); err != nil { + out <- fmt.Sprintf("fetch file error: %s\n", err) + return + } else if res.ResponseCode != http.StatusOK { + out <- fmt.Sprintf("fetch file error: %s\n", res.ErrorString) + return + } + + out <- fmt.Sprintf("\nimporting file '%s'\n", ctx.SourceFile) + if res, err := rhimport.ImportFile(&ctx); err != nil { + out <- fmt.Sprintf("import file error: %s\n", err) + return + } else { + if res.ResponseCode == http.StatusOK { + out <- fmt.Sprintf("\nFile got succesfully imported into Cart/Cut %d/%d\n", res.Cart, res.Cut) + rhl.Printf("File got succesfully imported into Cart/Cut %d/%d", res.Cart, res.Cut) + } else { + out <- fmt.Sprintf("Fileimport has failed (Cart/Cut %d/%d): %s\n", res.Cart, res.Cut, res.ErrorString) + rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", res.Cart, res.Cut, res.ErrorString) + } + } + close(out) +} + func (c *TelnetClient) handle_cmd_run(args []string) { if c.ctx == nil { c.say("context is empty please set at least one option") @@ -278,27 +309,12 @@ func (c *TelnetClient) handle_cmd_run(args []string) { return } - c.say("fetching file from '%s'", ctx.SourceUri) - if fres, err := rhimport.FetchFile(&ctx); err != nil { - c.say("fetch file error: %s", err) - return - } else if fres.ResponseCode != http.StatusOK { - c.say("fetch file error: %s", fres.ErrorString) - return - } - - c.say("importing file '%s'", ctx.SourceFile) - if ires, err := rhimport.ImportFile(&ctx); err != nil { - c.say("import file error: %s", err) - return - } else { - if ires.ResponseCode == http.StatusOK { - c.say("File got succesfully imported into Cart/Cut %d/%d", ires.Cart, ires.Cut) - rhl.Printf("File got succesfully imported into Cart/Cut %d/%d", ires.Cart, ires.Cut) - } else { - c.say("Fileimport has failed (Cart/Cut %d/%d): %s", ires.Cart, ires.Cut, ires.ErrorString) - rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", ires.Cart, ires.Cut, ires.ErrorString) - } + stdout := make(chan string) + ctx.ProgressCallBack = telnet_progress_callback + ctx.ProgressCallBackData = (chan<- string)(stdout) + go telnet_cmd_run(ctx, stdout) + for str := range stdout { + c.write_string(str) } } diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go index c5b81ce..da240a8 100644 --- a/src/helsinki.at/rhimportd/ctrlWebSimple.go +++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go @@ -91,10 +91,6 @@ func webSimpleResponse(w http.ResponseWriter, result *rhimport.ImportResult) { encoder.Encode(respdata) } -func webSimpleProgressCallback(step int, step_name string, progress float64, userdata interface{}) { - fmt.Printf("Step %d / %s: %3.2f%%\r", step, step_name, progress*100) -} - func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RdDb, trusted bool, r *http.Request) (ctx *rhimport.ImportContext, err error) { decoder := json.NewDecoder(r.Body) @@ -122,7 +118,6 @@ func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RdDb, trusted b ctx.AutotrimLevel = reqdata.AutotrimLevel ctx.UseMetaData = reqdata.UseMetaData ctx.SourceUri = reqdata.SourceUri - ctx.ProgressCallBack = webSimpleProgressCallback return } |