mod vendor

This commit is contained in:
Mikaël Cluseau 2019-02-11 16:32:01 +11:00
parent c2eda3b1d9
commit 9e597e8a4d
2 changed files with 0 additions and 56 deletions

1
vendor/modules.txt vendored
View File

@ -19,5 +19,4 @@ gopkg.in/yaml.v2
# novit.nc/direktil/pkg v0.0.0-20180706230842-852aa03280f9 # novit.nc/direktil/pkg v0.0.0-20180706230842-852aa03280f9
novit.nc/direktil/pkg/config novit.nc/direktil/pkg/config
novit.nc/direktil/pkg/log novit.nc/direktil/pkg/log
novit.nc/direktil/pkg/sysfs
novit.nc/direktil/pkg/color novit.nc/direktil/pkg/color

View File

@ -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
}