Ejemplo n.º 1
0
Archivo: ref.go Proyecto: olragon/dna
func SaveLastedChecktime(db *sqlpg.DB, filePath dna.String) error {
	cf, err := cfg.LoadConfigFile(filePath)
	if err != nil {
		return err
	}
	siteCts, err := GetLastedChecktime(db)
	if err != nil {
		return err
	}
	for site, checktime := range siteCts {
		var key dna.String
		var section dna.String
		switch {
		case site.Match("songs") == true:
			key = "songs"
			section = site.Replace("songs", "")
		case site.Match("albums") == true:
			key = "albums"
			section = site.Replace("albums", "")
		case site.Match("videos") == true:
			key = "videos"
			section = site.Replace("videos", "")
		default:
			panic("site is not valid")
		}
		cf.SetValue(section, key, dna.String(checktime.Format(utils.DefaultTimeLayout)))
	}
	return cfg.SaveConfigFile(cf, filePath)
}
Ejemplo n.º 2
0
Archivo: sqlpg.go Proyecto: olragon/dna
// NewSQLConfig loads sql config from a file and returns new SQLConfig.
func NewSQLConfig(path String) *SQLConfig {
	cfg, err := cfg.LoadConfigFile(path)
	PanicError(err)
	db, err := cfg.GetSection("database")
	PanicError(err)
	return &SQLConfig{
		Username: db["username"],
		Password: db["password"],
		Host:     db["host"],
		Post:     db["port"].ToInt(),
		Database: db["db"],
		SSLMode:  db["sslmode"],
	}
}
Ejemplo n.º 3
0
// LoadSiteConfig loads site config from a path.
//
// 	* siteCode: The code of a site, usually it is the package name of any type implementing dna.Item interface
// 	* filepath: path to config file
// 	* Return an error if occurs
//
// A part from an example config file with a init format:
// 	; nhacso
// 	[ns]
// 	nconcurrent=20
// 	ncsongfail = 0
// 	ncalbumfail = 0
// 	ncvideofail = 0
//
func LoadSiteConfig(siteCode, filepath String) (*SiteConfig, error) {
	cf, err := cfg.LoadConfigFile(filepath)
	if err != nil {
		return nil, err
	}
	section, err := cf.GetSection(siteCode)
	if err != nil {
		return nil, err
	}
	siteConfig := NewSiteConfig()
	siteConfig.NConcurrent = section["nconcurrent"].ToInt()
	siteConfig.NCSongFail = section["ncsongfail"].ToInt()
	siteConfig.NCAlbumFail = section["ncalbumfail"].ToInt()
	siteConfig.NCVideoFail = section["ncvideofail"].ToInt()
	siteConfig.src = cf
	siteConfig.siteCode = siteCode
	return siteConfig, nil
}
Ejemplo n.º 4
0
Archivo: ref.go Proyecto: olragon/dna
func LoadLastedChecktime(filePath dna.String) (map[dna.String]time.Time, error) {
	ret := make(map[dna.String]time.Time)
	cf, err := cfg.LoadConfigFile(filePath)
	if err != nil {
		return nil, err
	}
	for site, _ := range RefTables {
		section, err := cf.GetSection(site)
		if err != nil {
			dna.PanicError(err)
		}
		for postfix, timeStr := range section {
			if timeStr != "" {
				t, err := time.Parse(utils.DefaultTimeLayout, timeStr.String())
				if err == nil {
					ret[site+postfix] = t
				} else {
					dna.PanicError(err)
				}
			}
		}
	}
	return ret, nil
}