mod vendor
This commit is contained in:
parent
c2eda3b1d9
commit
9e597e8a4d
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -19,5 +19,4 @@ gopkg.in/yaml.v2
|
||||
# novit.nc/direktil/pkg v0.0.0-20180706230842-852aa03280f9
|
||||
novit.nc/direktil/pkg/config
|
||||
novit.nc/direktil/pkg/log
|
||||
novit.nc/direktil/pkg/sysfs
|
||||
novit.nc/direktil/pkg/color
|
||||
|
55
vendor/novit.nc/direktil/pkg/sysfs/sysfs.go
vendored
55
vendor/novit.nc/direktil/pkg/sysfs/sysfs.go
vendored
@ -1,55 +0,0 @@
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DeviceByProperty lists the devices where a given property=value filters match.
|
||||
func DeviceByProperty(class string, filters ...string) []string {
|
||||
files, err := filepath.Glob("/sys/class/" + class + "/*/uevent")
|
||||
if err != nil {
|
||||
log.Print("list devices failed: ", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
filtered := make([]string, 0)
|
||||
|
||||
filesLoop:
|
||||
for _, file := range files {
|
||||
ba, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Print("reading ", file, " failed: ", err)
|
||||
continue
|
||||
}
|
||||
|
||||
values := strings.Split(strings.TrimSpace(string(ba)), "\n")
|
||||
|
||||
devName := ""
|
||||
for _, value := range values {
|
||||
if strings.HasPrefix(value, "DEVNAME=") {
|
||||
devName = value[len("DEVNAME="):]
|
||||
}
|
||||
}
|
||||
|
||||
for _, filter := range filters {
|
||||
found := false
|
||||
for _, value := range values {
|
||||
if filter == value {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
continue filesLoop
|
||||
}
|
||||
}
|
||||
|
||||
filtered = append(filtered, devName)
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
Loading…
Reference in New Issue
Block a user