MCPcopy Create free account
hub / github.com/cavaliercoder/y10k / LoadYumfile

Function LoadYumfile

yumfile.go:29–148  ·  view source on GitHub ↗

LoadYumfile loads a Yumfile from disk

(path string)

Source from the content-addressed store, hash-verified

27
28// LoadYumfile loads a Yumfile from disk
29func LoadYumfile(path string) (*Yumfile, error) {
30 Dprintf("Loading Yumfile: %s\n", path)
31
32 yumfile := Yumfile{}
33
34 // open file
35 f, err := os.Open(path)
36 if err != nil {
37 return nil, err
38 }
39 defer f.Close()
40
41 // read each line
42 n := 0
43 scanner := bufio.NewScanner(f)
44 var repo *Repo = nil
45 for scanner.Scan() {
46 n++
47 s := scanner.Text()
48
49 if matches := sectionHeadPattern.FindAllStringSubmatch(s, -1); len(matches) > 0 {
50 // line is a [section header]
51 id := matches[0][1]
52
53 // append previous section
54 if repo != nil {
55 yumfile.Repos = append(yumfile.Repos, *repo)
56 }
57
58 // create new repo def
59 repo = NewRepo()
60
61 repo.YumfilePath = path
62 repo.YumfileLineNo = n
63 repo.ID = id
64 } else if matches := keyValPattern.FindAllStringSubmatch(s, -1); len(matches) > 0 {
65 // line is a key=val pair
66 key := matches[0][1]
67 val := matches[0][2]
68
69 if repo == nil {
70 // global key/val pair
71 switch key {
72 case "pathprefix":
73 yumfile.LocalPathPrefix = val
74
75 default:
76 return nil, NewErrorf("Syntax error in Yumfile on line %d: Unknown key: %s", n, key)
77 }
78 } else {
79 // add key/val to current repo
80 switch key {
81 case "localpath":
82 repo.LocalPath = val
83
84 case "arch":
85 repo.Architecture = val
86

Callers 3

ActionYumfileValidateFunction · 0.85
ActionYumfileListFunction · 0.85
ActionYumfileSyncFunction · 0.85

Calls 5

ValidateMethod · 0.95
DprintfFunction · 0.85
NewRepoFunction · 0.85
NewErrorfFunction · 0.85
strToBoolFunction · 0.85

Tested by

no test coverage detected