IsInstalled() works
This commit is contained in:
parent
1ecaeb97e3
commit
9b401ef56b
|
@ -10,6 +10,26 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
m := testMachine()
|
m := testMachine()
|
||||||
testPackages(m)
|
testPackages(m)
|
||||||
|
|
||||||
|
loop := m.Packages.SortByName()
|
||||||
|
for loop.Scan() {
|
||||||
|
p := loop.Package()
|
||||||
|
log.Info("installed package:", p.Name, p.Version, p.PkgName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.IsInstalled("bash") {
|
||||||
|
log.Info("bash installed check worked")
|
||||||
|
} else {
|
||||||
|
log.Info("bash installed check failed")
|
||||||
|
panic("bash")
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.IsInstalled("foo") {
|
||||||
|
log.Info("foo not-installed check failed")
|
||||||
|
panic("foo")
|
||||||
|
} else {
|
||||||
|
log.Info("foo not-installed check worked")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMachine() *zoopb.Machine {
|
func testMachine() *zoopb.Machine {
|
||||||
|
@ -20,14 +40,13 @@ func testMachine() *zoopb.Machine {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPackages(m *zoopb.Machine) {
|
func testPackages(m *zoopb.Machine) {
|
||||||
var all *zoopb.Packages
|
m.Packages = new(zoopb.Packages)
|
||||||
all = new(zoopb.Packages)
|
|
||||||
// r = zoopb.LoadJSON("go.wit.com/lib/protobuf/zoopb")
|
// r = zoopb.LoadJSON("go.wit.com/lib/protobuf/zoopb")
|
||||||
|
|
||||||
new1 := new(zoopb.Package)
|
new1 := new(zoopb.Package)
|
||||||
new1.Name = "bash"
|
new1.Name = "bash"
|
||||||
new1.Version = "5.2.21"
|
new1.Version = "5.2.21"
|
||||||
if all.Append(new1) {
|
if m.Packages.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.Name, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new1.Name, "failed")
|
log.Info("added", new1.Name, "failed")
|
||||||
|
@ -36,17 +55,17 @@ func testPackages(m *zoopb.Machine) {
|
||||||
new2 := new(zoopb.Package)
|
new2 := new(zoopb.Package)
|
||||||
new2.Name = "go-clone"
|
new2.Name = "go-clone"
|
||||||
new2.Version = "0.6.8" // good version of the macos
|
new2.Version = "0.6.8" // good version of the macos
|
||||||
if all.Append(new2) {
|
if m.Packages.Append(new2) {
|
||||||
log.Info("added", new2.Name, "ok")
|
log.Info("added", new2.Name, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new2.Name, "failed")
|
log.Info("added", new2.Name, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if all.Append(new2) {
|
if m.Packages.Append(new2) {
|
||||||
log.Info("added", new2.Name, "ok (this is bad)")
|
log.Info("added", new2.Name, "ok (this is bad)")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new2.Name, "failed (but ok)")
|
log.Info("added", new2.Name, "failed (but ok)")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("packages are:", len(all.Packages))
|
fmt.Println("package count = ", m.Packages.Len())
|
||||||
}
|
}
|
||||||
|
|
16
wit.go
16
wit.go
|
@ -11,6 +11,16 @@ var VERSION string
|
||||||
var BUILDTIME string
|
var BUILDTIME string
|
||||||
|
|
||||||
func (m *Machine) IsInstalled(name string) bool {
|
func (m *Machine) IsInstalled(name string) bool {
|
||||||
|
loop := m.Packages.SortByName()
|
||||||
|
for loop.Scan() {
|
||||||
|
p := loop.Package()
|
||||||
|
if name == p.Name {
|
||||||
|
// log.Info("package installed:", p.Name, p.Version, p.PkgName)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// log.Info("package not-installed:", name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +127,10 @@ func parsePackageInfo(lines string) *Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
p := Package{
|
p := Package{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: version,
|
Version: version,
|
||||||
PkgName: filename,
|
PkgName: filename,
|
||||||
SrcPath: gopath,
|
SrcPath: gopath,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &p
|
return &p
|
||||||
|
|
Loading…
Reference in New Issue