From e9da89ac2fd71a172a235034b5541ce8db917fac Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 18 Dec 2015 21:36:58 +0100 Subject: implemened set command for telnet control interface diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go index dd95cd6..38ee5c0 100644 --- a/src/helsinki.at/rhimportd/ctrlTelnet.go +++ b/src/helsinki.at/rhimportd/ctrlTelnet.go @@ -29,6 +29,7 @@ import ( "fmt" "helsinki.at/rhimport" "net" + "strconv" "strings" ) @@ -87,6 +88,8 @@ func (c *TelnetClient) handle_cmd_help(args []string) { c.say(" AutotrimLevel int autotrim level in dB (defaults to: %v)", c.conf.ImportParamDefaults.AutotrimLevel) c.say(" UseMetaData bool extract meta data from source file (defaults to: %v)", c.conf.ImportParamDefaults.UseMetaData) c.say("") + c.say(" UserName, Password and SourceUri are mandatory parameters.") + c.say("") c.say(" If ShowId is supplied GroupName, Channels, NomalizationLevel, AutorimLevel, UseMetaData") c.say(" and Cut will be ignored. The values from the shows dropbox will be used instead. Cart may") c.say(" be specified but must point to a empty cart within that show. If Cart is 0 the next free") @@ -128,10 +131,78 @@ func (c *TelnetClient) handle_cmd_help(args []string) { } func (c *TelnetClient) handle_cmd_set(args []string) { - c.say("setting args: %v", args) + if len(args) != 2 { + c.say("wrong number of arguments") + return + } if c.ctx == nil { - c.ctx = &rhimport.ImportContext{Config: c.conf, RdDb: c.rddb} - c.ctx.UserName = "hugo" + c.ctx = rhimport.NewImportContext(c.conf, c.rddb, "") + } + switch strings.ToLower(args[0]) { + case "username": + c.ctx.UserName = args[1] + case "password": + c.ctx.Password = args[1] + case "sourceuri": + c.ctx.SourceUri = args[1] + case "showid": + if id, err := strconv.ParseUint(args[1], 10, 32); err != nil { + c.say("invalid value (must be an positive integer)") + } else { + c.ctx.ShowId = uint(id) + } + case "clearshowcarts": + if val, err := strconv.ParseBool(args[1]); err != nil { + c.say("invalid value (must be true or false)") + } else { + c.ctx.ClearShowCarts = val + } + case "groupname": + c.ctx.GroupName = args[1] + case "cart": + if cart, err := strconv.ParseUint(args[1], 10, 32); err != nil { + c.say("invalid value (must be an positive integer)") + } else { + c.ctx.Cart = uint(cart) + } + case "clearcart": + if val, err := strconv.ParseBool(args[1]); err != nil { + c.say("invalid value (must be true or false)") + } else { + c.ctx.ClearCart = val + } + case "cut": + if cut, err := strconv.ParseUint(args[1], 10, 32); err != nil { + c.say("invalid value (must be an positive integer)") + } else { + c.ctx.Cut = uint(cut) + } + case "channels": + if channels, err := strconv.ParseUint(args[1], 10, 32); err != nil { + c.say("invalid value (must be an positive integer)") + } else { + c.ctx.Channels = uint(channels) + } + case "normalizationlevel": + if normalizationlevel, err := strconv.ParseInt(args[1], 10, 32); err != nil { + c.say("invalid value (must be an positive integer)") + } else { + c.ctx.NormalizationLevel = int(normalizationlevel) + } + case "autotrimlevel": + if autotrimlevel, err := strconv.ParseInt(args[1], 10, 32); err != nil { + c.say("invalid value (must be an positive integer)") + } else { + c.ctx.AutotrimLevel = int(autotrimlevel) + } + case "usemetadata": + if val, err := strconv.ParseBool(args[1]); err != nil { + c.say("invalid value (must be true or false)") + } else { + c.ctx.UseMetaData = val + } + default: + c.say("unknown parameter, use 'help set' for a list of available parameters") } } @@ -151,6 +222,7 @@ func (c *TelnetClient) handle_cmd_show(args []string) { if c.ctx != nil { c.say(" UserName: %v", c.ctx.UserName) c.say(" Password: %v", c.ctx.Password) + c.say(" SourceUri: %v", c.ctx.SourceUri) c.say(" ShowId: %v", c.ctx.ShowId) c.say(" ClearShowCarts: %v", c.ctx.ClearShowCarts) c.say(" GroupName: %v", c.ctx.GroupName) @@ -161,7 +233,6 @@ func (c *TelnetClient) handle_cmd_show(args []string) { c.say(" NormalizationLevel: %v", c.ctx.NormalizationLevel) c.say(" AutotrimLevel: %v", c.ctx.AutotrimLevel) c.say(" UseMetaData: %v", c.ctx.UseMetaData) - c.say(" SourceUri: %v", c.ctx.SourceUri) } else { c.say("context is empty") } -- cgit v0.10.2