-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspec.go
52 lines (43 loc) · 1.14 KB
/
spec.go
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
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
// Specfile
type Specfile struct {
Name string
Templated bool
Raw []byte
WorkingDirectory string
}
// NewSpecfile initialize a new Specfile structure
func NewSpecfile(name, wd, specTemplate string) Specfile {
spec := filepath.Join(wd, name+".spec")
templated := false
if _, err := os.Stat(spec); os.IsNotExist(err) {
templated = true
spec = specTemplate
}
raw, err := ioutil.ReadFile(spec)
if err != nil {
log.Printf("Can not find or read specfile %s", filepath.Join(wd, name+".spec"))
}
return Specfile{name, templated, raw, wd}
}
func (s *Specfile) Fill(pkg, ver string, bundle bool, temp TempData) {
raw := string(s.Raw)
if s.Templated {
raw = strings.Replace(raw, "<PACKAGE>", pkg, -1)
raw = strings.Replace(raw, "<VERSION>", ver, -1)
raw = strings.Replace(raw, "<SOURCE>", temp.Tarballs.String(), 1)
raw = strings.Replace(raw, "<LICENSE>", temp.Licenses.String(), 1)
} else {
}
s.Raw = []byte(raw)
}
func (s Specfile) Save() {
ioutil.WriteFile(filepath.Join(s.WorkingDirectory, s.Name+".spec"), s.Raw, 0644)
}