~mvo/update-manager/release-notes-markup

« back to all changes in this revision

Viewing changes to UpdateManager/Common/utils.py

  • Committer: Michael Vogt
  • Date: 2008-07-30 09:56:53 UTC
  • Revision ID: michael.vogt@ubuntu.com-20080730095653-ltsxxs251hrijhgo
* do-release-upgrade:
  - unify proxy configuration between gtk and cli UI

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from gettext import gettext as _
2
2
import locale
3
3
import os
 
4
import apt_pkg
 
5
import urllib2
 
6
 
 
7
def init_proxy(gconfclient=None):
 
8
  """ init proxy settings 
 
9
 
 
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)
 
14
  """
 
15
  SYNAPTIC_CONF_FILE = "/root/.synaptic/synaptic.conf"
 
16
  proxy = None
 
17
  # environment wins
 
18
  if os.getenv("http_proxy"):
 
19
    return
 
20
  # generic apt config wins next
 
21
  apt_pkg.InitConfig()
 
22
  if apt_pkg.Config.Find("Acquire::http::Proxy") != '':
 
23
    proxy = apt_pkg.Config.Find("Acquire::http::Proxy")
 
24
  # then synaptic
 
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)
 
29
    if use_proxy:
 
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)
 
34
  # then gconf
 
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")
 
39
    if host and port:
 
40
      if use_auth:
 
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)
 
44
      else:
 
45
        proxy = "http://%s:%s/" % (host, port)
 
46
  # if we have a proxy, set it
 
47
  if proxy:
 
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)
4
52
 
5
53
def _inhibit_sleep_old_interface():
6
54
  """