summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd/ctrlTelnet.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimportd/ctrlTelnet.go')
-rw-r--r--src/helsinki.at/rhimportd/ctrlTelnet.go58
1 files changed, 37 insertions, 21 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)
}
}