-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_task.go
More file actions
59 lines (53 loc) · 1.73 KB
/
Copy pathgenerate_task.go
File metadata and controls
59 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"bufio"
"fmt"
"github.com/robfig/config"
"os"
"path/filepath"
"strings"
)
type Task struct {
env string
tag string
list string
feature string
}
func ReadTasks(tastfile string) []Task {
fid, err := os.Open(tastfile)
if err != nil {
fmt.Println("Can not open the task file, err: ", err)
}
defer fid.Close()
scanner := bufio.NewScanner(fid)
var tasks []Task
for scanner.Scan() {
fields := strings.Split(scanner.Text(), ";")
tasks = append(tasks, Task{fields[0], fields[1], fields[2], fields[3]})
}
return tasks
}
func main() {
ini := "./conf.base"
inf, _ := config.Read(ini, config.ALTERNATIVE_COMMENT, config.ALTERNATIVE_SEPARATOR, false, true)
// create new options
base_data_dir, _ := inf.String("BASE", "tmp_data")
base_target, _ := inf.String("BASE", "target")
base_source, _ := inf.String("BASE", "source")
base_weight, _ := inf.String("BASE", "weight")
default_weight, _ := inf.String("IN", "weight")
base_feature, _ := inf.String("BASE", "feature_base")
tasks := ReadTasks("task.list")
for idx, task := range tasks {
task_inf := config.New(config.ALTERNATIVE_COMMENT, config.ALTERNATIVE_SEPARATOR, false, true)
task_inf.Merge(inf)
task_inf.AddOption("IN", "tag", task.tag)
task_inf.AddOption("IN", "feature_dir", filepath.Join(base_feature, task.feature))
task_inf.AddOption("IN", "env", task.env)
task_inf.AddOption("IN", "weight", base_weight+default_weight)
task_inf.AddOption("IN", "data_dir", filepath.Join(base_data_dir, task.env, task.tag))
task_inf.AddOption("IN", "list", filepath.Join(base_source+task.list))
task_inf.AddOption("OUT", "dae_dir", filepath.Join(base_target, task.env, task.tag))
task_inf.WriteFile(fmt.Sprintf("./conf.ini.%d", idx), 0666, "")
}
}