diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-04 00:26:12 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-04 00:26:12 (GMT) |
commit | 80c19f00f3b098621fe5bb8f42c009f2890e84f8 (patch) | |
tree | aedaa9ff503802941c4539f8a2d9d1b4a5a1115a /src/helsinki.at/rhimport | |
parent | ece69efd67af2982cac882b9192872c7ff6957bb (diff) |
introduced conf
Diffstat (limited to 'src/helsinki.at/rhimport')
-rw-r--r-- | src/helsinki.at/rhimport/conf.go | 98 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 63 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/log.go | 9 |
3 files changed, 154 insertions, 16 deletions
diff --git a/src/helsinki.at/rhimport/conf.go b/src/helsinki.at/rhimport/conf.go new file mode 100644 index 0000000..bd350c3 --- /dev/null +++ b/src/helsinki.at/rhimport/conf.go @@ -0,0 +1,98 @@ +// +// rhimportd +// +// The Radio Helsinki Rivendell Import Daemon +// +// +// Copyright (C) 2015 Christian Pointner <equinox@helsinki.at> +// +// This file is part of rhimportd. +// +// rhimportd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// rhimportd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with rhimportd. If not, see <http://www.gnu.org/licenses/>. +// + +package rhimport + +import () + +type getPasswordResult struct { + password string + err error +} + +type getPasswordRequest struct { + username string + cached bool + response chan getPasswordResult +} + +type Config struct { + configfile string + RDXportEndpoint string + db_host string + db_user string + db_passwd string + db_db string + // TODO: reference to sql connection + password_cache map[string]string + getPasswordChan chan getPasswordRequest + quit chan bool + done chan bool +} + +func (self Config) getPassword(username string, cached bool) (pwd string, err error) { + //TODO: actually fetch password from cache or DB + pwd = "12345" + return +} + +func (self Config) dispatchRequests() { + defer func() { self.done <- true }() + for { + select { + case <-self.quit: + return + case req := <-self.getPasswordChan: + if req.cached { + rhdl.Println("Config: got getPassword request for", req.username, "(cached)") + } else { + rhdl.Println("Config: got getPassword request for", req.username, "(not cached)") + } + pwd, err := self.getPassword(req.username, req.cached) + req.response <- getPasswordResult{pwd, err} + } + } +} + +func (self Config) Cleanup() { + self.quit <- true + <-self.done + close(self.quit) + close(self.done) + close(self.getPasswordChan) + //TODO : close db connection +} + +func NewConfig(configfile, rdxport_endpoint *string) (conf *Config, err error) { + conf = new(Config) + conf.configfile = *configfile + conf.quit = make(chan bool) + conf.done = make(chan bool) + conf.RDXportEndpoint = *rdxport_endpoint + //TODO : init db connection + conf.password_cache = make(map[string]string) + conf.getPasswordChan = make(chan getPasswordRequest) + go conf.dispatchRequests() + return +} diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index 5da6075..8c7e66e 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -34,16 +34,49 @@ import ( ) type ImportContext struct { - username string - groupname string - // TODO: password channel - cart int - channels int - normalization_level int - autotrim_level int - use_meta_data bool - source_file string - delete_source_file bool + Conf *Config + UserName string + password string + GroupName string + Cart int + Channels int + NormalizationLevel int + AutotrimLevel int + UseMetaData bool + SourceFile string + DeleteSourceFile bool +} + +func NewImportContext(conf *Config, user string, group string, cart int) *ImportContext { + ctx := new(ImportContext) + ctx.Conf = conf + ctx.UserName = user + ctx.GroupName = group + ctx.Cart = cart + ctx.Channels = 2 + ctx.NormalizationLevel = 1200 + ctx.AutotrimLevel = 0 + ctx.UseMetaData = false + ctx.SourceFile = "" + ctx.DeleteSourceFile = false + + return ctx +} + +func (ctx *ImportContext) getPassword(cached bool) (err error) { + req := getPasswordRequest{} + req.username = ctx.UserName + req.cached = cached + req.response = make(chan getPasswordResult) + ctx.Conf.getPasswordChan <- req + + res := <-req.response + if res.err != nil { + err = res.err + return + } + ctx.password = res.password + return } // func import_audio(url, file string) (err error) { @@ -94,6 +127,14 @@ type ImportContext struct { // } func ImportFile(ctx *ImportContext) (err error) { - err = fmt.Errorf("not yet implemented") + rhl.Println("ImportFile called for", ctx.SourceFile) + + if err = ctx.getPassword(true); err != nil { + return + } + rhdl.Println("credentials:", ctx.UserName, "/", ctx.password) + + err = fmt.Errorf("%+v", ctx) + return } diff --git a/src/helsinki.at/rhimport/log.go b/src/helsinki.at/rhimport/log.go index 46b0e52..b192c30 100644 --- a/src/helsinki.at/rhimport/log.go +++ b/src/helsinki.at/rhimport/log.go @@ -25,14 +25,13 @@ package rhimport import ( - "io/ioutil" + // "io/ioutil" "log" "os" ) var ( - rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags) - // use ioutil.Discard to switch that thing off - // rhtl = log.New(os.Stderr, "[rhdbg]\t", log.LstdFlags) - rhtl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags) + rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags) + rhdl = log.New(os.Stderr, "[rhimport-dbg]\t", log.LstdFlags) + //rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags) ) |