~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-old/plugins/proxy_info.py

  • Committer: Tarmac
  • Author(s): Brendan Donegan
  • Date: 2013-06-03 11:12:58 UTC
  • mfrom: (2154.2.1 bug1185759)
  • Revision ID: tarmac-20130603111258-1b3m5ydvkf1accts
"[r=zkrynicki][bug=1185759][author=brendan-donegan] automatic merge by tarmac"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2008 Canonical Ltd.
 
5
#
 
6
# Checkbox is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# Checkbox is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
import re
 
20
 
 
21
from checkbox.lib.environ import add_variable, get_variable
 
22
 
 
23
from checkbox.properties import String
 
24
from checkbox.plugin import Plugin
 
25
 
 
26
 
 
27
class ProxyInfo(Plugin):
 
28
 
 
29
    # HTTP proxy to use instead of the one specified in environment.
 
30
    http_proxy = String(required=False)
 
31
 
 
32
    # HTTPS proxy to use instead of the one specified in environment.
 
33
    https_proxy = String(required=False)
 
34
 
 
35
    def register(self, manager):
 
36
        super(ProxyInfo, self).register(manager)
 
37
 
 
38
        self.proxy = {}
 
39
 
 
40
        self._manager.reactor.call_on("report-gconf", self.report_gconf)
 
41
        self._manager.reactor.call_on("gather", self.gather, 100)
 
42
 
 
43
    def report_gconf(self, resources):
 
44
        proxy_pattern = re.compile(r"/system/(http_)?proxy/(?P<name>[^/]+)$")
 
45
        for resource in resources:
 
46
            match = proxy_pattern.match(resource["name"])
 
47
            if match:
 
48
                self.proxy[match.group("name")] = resource["value"]
 
49
 
 
50
    def gather(self):
 
51
        # Config has lowest precedence
 
52
        http_proxy = self.http_proxy
 
53
        https_proxy = self.https_proxy
 
54
 
 
55
        # Gconf has higher precedence
 
56
        proxy = self.proxy
 
57
        if proxy.get("use_http_proxy", False):
 
58
            if proxy.get("use_authentication", False):
 
59
                http_proxy = "http://%s:%s@%s:%s" % (
 
60
                    proxy["authentication_user"],
 
61
                    proxy["authentication_password"],
 
62
                    proxy["host"],
 
63
                    proxy["port"])
 
64
            elif "host" in proxy:
 
65
                http_proxy = "http://%s:%s" % (
 
66
                    proxy["host"],
 
67
                    proxy["port"])
 
68
 
 
69
            if proxy.get("use_same_proxy", False):
 
70
                https_proxy = http_proxy
 
71
            elif "secure_host" in proxy:
 
72
                https_proxy = "https://%s:%s" % (
 
73
                    proxy["secure_host"],
 
74
                    proxy["secure_port"])
 
75
 
 
76
        # Environment has highest precedence
 
77
        http_proxy = get_variable("http_proxy", http_proxy)
 
78
        https_proxy = get_variable("https_proxy", https_proxy)
 
79
 
 
80
        add_variable("http_proxy", http_proxy)
 
81
        add_variable("https_proxy", https_proxy)
 
82
 
 
83
 
 
84
factory = ProxyInfo