1
1
from gettext import gettext as _
7
def init_proxy(gconfclient=None):
8
""" init proxy settings
10
* first check for http_proxy environment (always wins),
11
* then check the apt.conf http proxy,
12
* then look into synaptics conffile
13
* then into gconf (if gconfclient was supplied)
15
SYNAPTIC_CONF_FILE = "/root/.synaptic/synaptic.conf"
18
if os.getenv("http_proxy"):
20
# generic apt config wins next
22
if apt_pkg.Config.Find("Acquire::http::Proxy") != '':
23
proxy = apt_pkg.Config.Find("Acquire::http::Proxy")
25
elif os.path.exists(SYNAPTIC_CONF_FILE):
26
cnf = apt_pkg.newConfiguration()
27
apt_pkg.ReadConfigFile(cnf, SYNAPTIC_CONF_FILE)
28
use_proxy = cnf.FindB("Synaptic::useProxy", False)
30
proxy_host = cnf.Find("Synaptic::httpProxy")
31
proxy_port = str(cnf.FindI("Synaptic::httpProxyPort"))
32
if proxy_host and proxy_port:
33
proxy = "http://%s:%s/" % (proxy_host, proxy_port)
35
elif gconfclient and gconfclient.get_bool("/system/http_proxy/use_http_proxy"):
36
host = gconfclient.get_string("/system/http_proxy/host")
37
port = gconfclient.get_int("/system/http_proxy/port")
38
use_auth = gconfclient.get_bool("/system/http_proxy/use_authentication")
41
auth_user = gconfclient.get_string("/system/http_proxy/authentication_user")
42
auth_pw = gconfclient.get_string("/system/http_proxy/authentication_password")
43
proxy = "http://%s:%s@%s:%s/" % (auth_user,auth_pw,host, port)
45
proxy = "http://%s:%s/" % (host, port)
46
# if we have a proxy, set it
48
proxy_support = urllib2.ProxyHandler({"http":proxy})
49
opener = urllib2.build_opener(proxy_support)
50
urllib2.install_opener(opener)
51
os.putenv("http_proxy",proxy)
5
53
def _inhibit_sleep_old_interface():