mirror of https://github.com/docker/docs.git
Merge pull request #2759 from dgageot/better-windows-version-detection
Better windows version detection
This commit is contained in:
commit
ad3e6b5bf0
|
@ -17,7 +17,6 @@ import (
|
||||||
|
|
||||||
"github.com/bugsnag/bugsnag-go"
|
"github.com/bugsnag/bugsnag-go"
|
||||||
"github.com/docker/machine/libmachine/log"
|
"github.com/docker/machine/libmachine/log"
|
||||||
"github.com/docker/machine/libmachine/mcnutils"
|
|
||||||
"github.com/docker/machine/version"
|
"github.com/docker/machine/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -146,5 +145,5 @@ func detectUname(metaData *bugsnag.MetaData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func detectOSVersion(metaData *bugsnag.MetaData) {
|
func detectOSVersion(metaData *bugsnag.MetaData) {
|
||||||
metaData.Add("device", "os version", mcnutils.LocalOSVersion())
|
metaData.Add("device", "os version", localOSVersion())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package mcnutils
|
package crashreport
|
||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
|
||||||
func LocalOSVersion() string {
|
func localOSVersion() string {
|
||||||
command := exec.Command("bash", "-c", `sw_vers | grep ProductVersion | cut -d$'\t' -f2`)
|
command := exec.Command("bash", "-c", `sw_vers | grep ProductVersion | cut -d$'\t' -f2`)
|
||||||
output, err := command.Output()
|
output, err := command.Output()
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -1,8 +1,8 @@
|
||||||
package mcnutils
|
package crashreport
|
||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
|
||||||
func LocalOSVersion() string {
|
func localOSVersion() string {
|
||||||
command := exec.Command("bash", "-c", `cat /etc/os-release | grep 'VERSION=' | cut -d'=' -f2`)
|
command := exec.Command("bash", "-c", `cat /etc/os-release | grep 'VERSION=' | cut -d'=' -f2`)
|
||||||
output, err := command.Output()
|
output, err := command.Output()
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -1,11 +1,11 @@
|
||||||
package mcnutils
|
package crashreport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LocalOSVersion() string {
|
func localOSVersion() string {
|
||||||
command := exec.Command("ver")
|
command := exec.Command("ver")
|
||||||
output, err := command.Output()
|
output, err := command.Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -24,10 +24,21 @@ func LocalOSVersion() string {
|
||||||
func parseSystemInfoOutput(output string) string {
|
func parseSystemInfoOutput(output string) string {
|
||||||
lines := strings.Split(string(output), "\n")
|
lines := strings.Split(string(output), "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if strings.HasPrefix(line, "OS Version") {
|
if strings.HasPrefix(line, "OS Version:") {
|
||||||
return strings.TrimSpace(line[len("OS Version:"):])
|
return strings.TrimSpace(line[len("OS Version:"):])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we couldn't find the version, maybe the output is not in english
|
||||||
|
// Let's parse the fourth line since it seems to be the one always used
|
||||||
|
// for the version.
|
||||||
|
if len(lines) >= 4 {
|
||||||
|
parts := strings.Split(lines[3], ":")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
return strings.TrimSpace(parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package mcnutils
|
package crashreport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -27,5 +27,21 @@ OS Build Type: Multiprocessor Free
|
||||||
Registered Owner: Windows User
|
Registered Owner: Windows User
|
||||||
`
|
`
|
||||||
|
|
||||||
assert.Equal(t, "10.0.10240 N/A Build 10240", parseOutput(output))
|
assert.Equal(t, "10.0.10240 N/A Build 10240", parseSystemInfoOutput(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseNonEnglishSystemInfoOutput(t *testing.T) {
|
||||||
|
output := `
|
||||||
|
Ignored: ...
|
||||||
|
Ignored: ...
|
||||||
|
Version du Système: 10.0.10350
|
||||||
|
`
|
||||||
|
|
||||||
|
assert.Equal(t, "10.0.10350", parseSystemInfoOutput(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseInvalidSystemInfoOutput(t *testing.T) {
|
||||||
|
output := "Invalid"
|
||||||
|
|
||||||
|
assert.Empty(t, parseSystemInfoOutput(output))
|
||||||
}
|
}
|
Loading…
Reference in New Issue