~rogpeppe/juju-core/themue-058-debug-log-api

« back to all changes in this revision

Viewing changes to utils/apt.go

  • Committer: Frank Mueller
  • Date: 2014-01-21 08:46:24 UTC
  • mfrom: (2152.1.76 juju-core)
  • Revision ID: frank.mueller@canonical.com-20140121084624-rv32dv6ufzul9h1b
debugger: merged trunk and added access to debugger API facade

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
        "strings"
13
13
 
14
14
        "launchpad.net/loggo"
 
15
 
 
16
        "launchpad.net/juju-core/juju/osenv"
15
17
)
16
18
 
17
19
var (
18
20
        aptLogger  = loggo.GetLogger("juju.utils.apt")
19
 
        aptProxyRE = regexp.MustCompile(`(?im)^\s*Acquire::[a-z]+::Proxy\s+"[^"]+";\s*$`)
 
21
        aptProxyRE = regexp.MustCompile(`(?im)^\s*Acquire::(?P<protocol>[a-z]+)::Proxy\s+"(?P<proxy>[^"]+)";\s*$`)
20
22
)
21
23
 
22
24
// Some helpful functions for running apt in a sane way
74
76
        return string(bytes.Join(aptProxyRE.FindAll(out, -1), []byte("\n"))), nil
75
77
}
76
78
 
 
79
// DetectAptProxies will parse the results of AptConfigProxy to return a
 
80
// ProxySettings instance.
 
81
func DetectAptProxies() (result osenv.ProxySettings, err error) {
 
82
        output, err := AptConfigProxy()
 
83
        if err != nil {
 
84
                return result, err
 
85
        }
 
86
        for _, match := range aptProxyRE.FindAllStringSubmatch(output, -1) {
 
87
                switch match[1] {
 
88
                case "http":
 
89
                        result.Http = match[2]
 
90
                case "https":
 
91
                        result.Https = match[2]
 
92
                case "ftp":
 
93
                        result.Ftp = match[2]
 
94
                }
 
95
        }
 
96
        return result, nil
 
97
}
 
98
 
77
99
// IsUbuntu executes lxb_release to see if the host OS is Ubuntu.
78
100
func IsUbuntu() bool {
79
101
        out, err := RunCommand("lsb_release", "-i", "-s")