summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-28 15:55:01 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-28 15:55:01 (GMT)
commit9974df73508ae39c0db7a424cf0d52568e002a7e (patch)
treef4de19342edda38e2e654f15d7f7e2d711d762c9 /src
parenta03a9cf4b5b34a54d715a518b83919bb322c42c3 (diff)
moved ImporteContext stuff to core.go
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/core.go138
-rw-r--r--src/helsinki.at/rhimport/importer.go136
2 files changed, 136 insertions, 138 deletions
diff --git a/src/helsinki.at/rhimport/core.go b/src/helsinki.at/rhimport/core.go
index 5498499..3b8280a 100644
--- a/src/helsinki.at/rhimport/core.go
+++ b/src/helsinki.at/rhimport/core.go
@@ -26,14 +26,21 @@ package rhimport
import (
// "io/ioutil"
+ "fmt"
"github.com/golang-basic/go-curl"
"log"
"os"
)
+const (
+ CART_MAX = 999999
+ CUT_MAX = 999
+)
+
var (
- rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags)
- rhdl = log.New(os.Stderr, "[rhimport-dbg]\t", log.LstdFlags)
+ bool2str = map[bool]string{false: "0", true: "1"}
+ 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)
)
@@ -41,3 +48,130 @@ func init() {
curl.GlobalInit(curl.GLOBAL_ALL)
fetcher_init()
}
+
+type ImportProgressCB func(step int, step_name string, progress float64, userdata interface{}) bool
+
+type ImportContext struct {
+ conf *Config
+ rddb *RdDbChan
+ UserName string
+ Password string
+ Trusted bool
+ ShowId uint
+ ClearShowCarts bool
+ GroupName string
+ Cart uint
+ ClearCart bool
+ Cut uint
+ Channels uint
+ NormalizationLevel int
+ AutotrimLevel int
+ UseMetaData bool
+ SourceUri string
+ SourceFile string
+ DeleteSourceFile bool
+ DeleteSourceDir bool
+ ProgressCallBack ImportProgressCB
+ ProgressCallBackData interface{}
+ Cancel <-chan bool
+}
+
+func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext {
+ ctx := new(ImportContext)
+ ctx.conf = conf
+ ctx.rddb = rddb
+ ctx.UserName = user
+ ctx.Password = ""
+ ctx.Trusted = false
+ ctx.ShowId = 0
+ ctx.ClearShowCarts = false
+ ctx.GroupName = ""
+ ctx.Cart = 0
+ ctx.ClearCart = false
+ ctx.Cut = 0
+ ctx.Channels = conf.ImportParamDefaults.Channels
+ ctx.NormalizationLevel = conf.ImportParamDefaults.NormalizationLevel
+ ctx.AutotrimLevel = conf.ImportParamDefaults.AutotrimLevel
+ ctx.UseMetaData = conf.ImportParamDefaults.UseMetaData
+ ctx.SourceFile = ""
+ ctx.DeleteSourceFile = false
+ ctx.DeleteSourceDir = false
+ ctx.ProgressCallBack = nil
+ ctx.Cancel = nil
+
+ return ctx
+}
+
+func (ctx *ImportContext) SanityCheck() error {
+ if ctx.UserName == "" {
+ return fmt.Errorf("empty Username is not allowed")
+ }
+ if ctx.Password == "" && !ctx.Trusted {
+ return fmt.Errorf("empty Password on untrusted control interface is not allowed")
+ }
+ if ctx.ShowId != 0 {
+ if ctx.ShowId != 0 && ctx.ShowId > CART_MAX {
+ return fmt.Errorf("ShowId %d is outside of allowed range (0 < show-id < %d)", ctx.ShowId, CART_MAX)
+ }
+ if ctx.Cart != 0 && ctx.Cart > CART_MAX {
+ return fmt.Errorf("Cart %d is outside of allowed range (0 < cart < %d)", ctx.Cart, CART_MAX)
+ }
+ return nil
+ }
+ if ctx.GroupName != "" {
+ ismusic, err := ctx.checkMusicGroup()
+ if err != nil {
+ return err
+ }
+ if !ismusic {
+ return fmt.Errorf("supplied GroupName '%s' is not a music pool", ctx.GroupName)
+ }
+ if ctx.Cart != 0 || ctx.Cut != 0 {
+ return fmt.Errorf("Cart and Cut must not be supplied when importing into a music group")
+ }
+ return nil
+ }
+ if ctx.Cart == 0 {
+ return fmt.Errorf("either ShowId, PoolName or CartNumber must be supplied")
+ }
+ if ctx.Cart > CART_MAX {
+ return fmt.Errorf("Cart %d is outside of allowed range (0 < cart < %d)", ctx.Cart, CART_MAX)
+ }
+ if ctx.Cut != 0 && ctx.Cut > CUT_MAX {
+ return fmt.Errorf("Cut %d is outside of allowed range (0 < cart < %d)", ctx.Cut, CUT_MAX)
+ }
+ if ctx.Channels != 1 && ctx.Channels != 2 {
+ return fmt.Errorf("channles must be 1 or 2")
+ }
+ return nil
+}
+
+func (ctx *ImportContext) getPassword(cached bool) (err error) {
+ ctx.Password, err = ctx.rddb.GetPassword(ctx.UserName, cached)
+ return
+}
+
+func (ctx *ImportContext) getGroupOfCart() (err error) {
+ ctx.GroupName, err = ctx.rddb.GetGroupOfCart(ctx.Cart)
+ return
+}
+
+func (ctx *ImportContext) getShowInfo() (carts []uint, err error) {
+ ctx.GroupName, ctx.NormalizationLevel, ctx.AutotrimLevel, carts, err = ctx.rddb.GetShowInfo(ctx.ShowId)
+ ctx.Channels = 2
+ ctx.UseMetaData = true
+ return
+}
+
+func (ctx *ImportContext) checkMusicGroup() (bool, error) {
+ return ctx.rddb.CheckMusicGroup(ctx.GroupName)
+}
+
+func (ctx *ImportContext) getMusicInfo() (err error) {
+ ctx.NormalizationLevel, ctx.AutotrimLevel, err = ctx.rddb.GetMusicInfo(ctx.GroupName)
+ ctx.Channels = 2
+ ctx.UseMetaData = true
+ ctx.Cart = 0
+ ctx.Cut = 0
+ return
+}
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go
index 28ca55a..406c58e 100644
--- a/src/helsinki.at/rhimport/importer.go
+++ b/src/helsinki.at/rhimport/importer.go
@@ -35,142 +35,6 @@ import (
"path"
)
-const (
- CART_MAX = 999999
- CUT_MAX = 999
-)
-
-var (
- bool2str = map[bool]string{false: "0", true: "1"}
-)
-
-type ImportProgressCB func(step int, step_name string, progress float64, userdata interface{}) bool
-
-type ImportContext struct {
- conf *Config
- rddb *RdDbChan
- UserName string
- Password string
- Trusted bool
- ShowId uint
- ClearShowCarts bool
- GroupName string
- Cart uint
- ClearCart bool
- Cut uint
- Channels uint
- NormalizationLevel int
- AutotrimLevel int
- UseMetaData bool
- SourceUri string
- SourceFile string
- DeleteSourceFile bool
- DeleteSourceDir bool
- ProgressCallBack ImportProgressCB
- ProgressCallBackData interface{}
- Cancel <-chan bool
-}
-
-func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext {
- ctx := new(ImportContext)
- ctx.conf = conf
- ctx.rddb = rddb
- ctx.UserName = user
- ctx.Password = ""
- ctx.Trusted = false
- ctx.ShowId = 0
- ctx.ClearShowCarts = false
- ctx.GroupName = ""
- ctx.Cart = 0
- ctx.ClearCart = false
- ctx.Cut = 0
- ctx.Channels = conf.ImportParamDefaults.Channels
- ctx.NormalizationLevel = conf.ImportParamDefaults.NormalizationLevel
- ctx.AutotrimLevel = conf.ImportParamDefaults.AutotrimLevel
- ctx.UseMetaData = conf.ImportParamDefaults.UseMetaData
- ctx.SourceFile = ""
- ctx.DeleteSourceFile = false
- ctx.DeleteSourceDir = false
- ctx.ProgressCallBack = nil
- ctx.Cancel = nil
-
- return ctx
-}
-
-func (ctx *ImportContext) SanityCheck() error {
- if ctx.UserName == "" {
- return fmt.Errorf("empty Username is not allowed")
- }
- if ctx.Password == "" && !ctx.Trusted {
- return fmt.Errorf("empty Password on untrusted control interface is not allowed")
- }
- if ctx.ShowId != 0 {
- if ctx.ShowId != 0 && ctx.ShowId > CART_MAX {
- return fmt.Errorf("ShowId %d is outside of allowed range (0 < show-id < %d)", ctx.ShowId, CART_MAX)
- }
- if ctx.Cart != 0 && ctx.Cart > CART_MAX {
- return fmt.Errorf("Cart %d is outside of allowed range (0 < cart < %d)", ctx.Cart, CART_MAX)
- }
- return nil
- }
- if ctx.GroupName != "" {
- ismusic, err := ctx.checkMusicGroup()
- if err != nil {
- return err
- }
- if !ismusic {
- return fmt.Errorf("supplied GroupName '%s' is not a music pool", ctx.GroupName)
- }
- if ctx.Cart != 0 || ctx.Cut != 0 {
- return fmt.Errorf("Cart and Cut must not be supplied when importing into a music group")
- }
- return nil
- }
- if ctx.Cart == 0 {
- return fmt.Errorf("either ShowId, PoolName or CartNumber must be supplied")
- }
- if ctx.Cart > CART_MAX {
- return fmt.Errorf("Cart %d is outside of allowed range (0 < cart < %d)", ctx.Cart, CART_MAX)
- }
- if ctx.Cut != 0 && ctx.Cut > CUT_MAX {
- return fmt.Errorf("Cut %d is outside of allowed range (0 < cart < %d)", ctx.Cut, CUT_MAX)
- }
- if ctx.Channels != 1 && ctx.Channels != 2 {
- return fmt.Errorf("channles must be 1 or 2")
- }
- return nil
-}
-
-func (ctx *ImportContext) getPassword(cached bool) (err error) {
- ctx.Password, err = ctx.rddb.GetPassword(ctx.UserName, cached)
- return
-}
-
-func (ctx *ImportContext) getGroupOfCart() (err error) {
- ctx.GroupName, err = ctx.rddb.GetGroupOfCart(ctx.Cart)
- return
-}
-
-func (ctx *ImportContext) getShowInfo() (carts []uint, err error) {
- ctx.GroupName, ctx.NormalizationLevel, ctx.AutotrimLevel, carts, err = ctx.rddb.GetShowInfo(ctx.ShowId)
- ctx.Channels = 2
- ctx.UseMetaData = true
- return
-}
-
-func (ctx *ImportContext) checkMusicGroup() (bool, error) {
- return ctx.rddb.CheckMusicGroup(ctx.GroupName)
-}
-
-func (ctx *ImportContext) getMusicInfo() (err error) {
- ctx.NormalizationLevel, ctx.AutotrimLevel, err = ctx.rddb.GetMusicInfo(ctx.GroupName)
- ctx.Channels = 2
- ctx.UseMetaData = true
- ctx.Cart = 0
- ctx.Cut = 0
- return
-}
-
type ImportResult struct {
ResponseCode int
ErrorString string