-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.go
61 lines (51 loc) · 1.43 KB
/
package.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
53
54
55
56
57
58
59
60
61
package ian
import (
"os/exec"
"path/filepath"
"strconv"
"github.com/penguinpowernz/go-ian/debian/control"
"github.com/penguinpowernz/go-ian/util/file"
)
// Pkg represents a ian debian package with helpers for
// various operations around managing a debian package
// with ian
type Pkg struct {
ctrl control.Control
dir string
errs []error
}
// NewPackage returns a new Pkg object with the control
// file contained within, when given a directory
func NewPackage(dir string) (p *Pkg, err error) {
p = new(Pkg)
p.dir = dir
p.ctrl, err = control.Read(p.CtrlFile())
return
}
// Initialized will return true if the package has been initialized
func (p *Pkg) Initialized() bool {
return file.Exists(p.CtrlFile())
}
// Ctrl returns the control file as a control object
func (p *Pkg) Ctrl() *control.Control {
return &p.ctrl
}
// CtrlFiles returns a list of all the files in the control dir
func (p *Pkg) CtrlFiles() []string {
m, _ := filepath.Glob(filepath.Join(p.CtrlDir(), "*"))
return m
}
// Size returns the total size of the files to be included
// in the package
func (p *Pkg) Size() (string, error) {
size, err := file.DirSize(p.Dir(), p.Excludes())
if err != nil {
size = size / 1024
}
return strconv.Itoa(size), nil
}
// BuildCommand returns the command to run in order to run
// the packages build script
func (p *Pkg) BuildCommand() *exec.Cmd {
return exec.Command(p.BuildFile(), p.Dir(), p.Ctrl().Version, p.Ctrl().Arch)
}