~gary-lasker/software-center/installedview-search-fixes

« back to all changes in this revision

Viewing changes to softwarecenter/utils.py

  • Committer: Michael Vogt
  • Date: 2011-09-27 14:05:33 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110927140533-fwll3aujkrerjome
* softwarecenter/ui/gtk3/app.py, softwarecenter/utils.py:
  - add support for proxy setup from gsettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
    else:
248
248
        return proxy
249
249
 
 
250
def get_http_proxy_string_from_gsettings():
 
251
    """Helper that gets the http proxy from gsettings
 
252
 
 
253
    Returns: string with http://auth:pw@proxy:port/ or None
 
254
    """
 
255
    try:
 
256
        from gi.repository import Gio
 
257
        settings = Gio.Settings.new("org.gnome.system.proxy.http")
 
258
        if settings.get_boolean("enabled"):
 
259
            authentication = ""
 
260
            if settings.get_boolean("use-authentication"):
 
261
                user = settings.get_string("authentication-user")
 
262
                password = settings.get_string("authentication-password")
 
263
                authentication = "%s:%s@" % (user, password)
 
264
            host = settings.get_string("host")
 
265
            port = settings.get_int("port")
 
266
            http_proxy = "http://%s%s:%s/" %  (authentication, host, port)
 
267
            if host:
 
268
                return http_proxy
 
269
    except Exception:
 
270
        logging.exception("failed to get proxy from gconf")
 
271
 
250
272
def encode_for_xml(unicode_data, encoding="ascii"):
251
273
    """ encode a given string for xml """
252
274
    return unicode_data.encode(encoding, 'xmlcharrefreplace')