diff options
author | Devan Franchini <twitch153@gentoo.org> | 2014-05-23 14:37:51 -0400 |
---|---|---|
committer | Devan Franchini <twitch153@gentoo.org> | 2014-06-12 17:11:50 -0400 |
commit | fda51375fed8b54e264e4577fb3d72385bbffa17 (patch) | |
tree | c16be257020f27dafcf8b10b35702f6af4d8937f /layman/config.py | |
parent | api.py: incorporates db.update() in api.sync() (diff) | |
download | layman-fda51375fed8b54e264e4577fb3d72385bbffa17.tar.gz layman-fda51375fed8b54e264e4577fb3d72385bbffa17.tar.bz2 layman-fda51375fed8b54e264e4577fb3d72385bbffa17.zip |
config.py: Adds proxies() @property function
Since remotedb.py and tar.py both made use of the same code
that determined available proxies, the code has been moved to a
function in config.py and both files have been changed to make use
of this function as a value.
Diffstat (limited to 'layman/config.py')
-rw-r--r-- | layman/config.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/layman/config.py b/layman/config.py index 40ee90a..9d2bc7f 100644 --- a/layman/config.py +++ b/layman/config.py @@ -66,7 +66,6 @@ def read_layman_config(config=None, defaults=None, output=None): overlays.update(["file://" + _path]) config.set('MAIN', 'overlays', '\n'.join(overlays)) - # establish the eprefix, initially set so eprefixify can # set it on install EPREFIX = "@GENTOO_PORTAGE_EPREFIX@" @@ -280,6 +279,28 @@ class BareConfig(object): """ return option.lower() in ['yes', 'true', 'y', 't'] + @property + def proxies(self): + """ + Reads the config options to determine the available proxies. + + @param config: config options dict. + @rtype dict + """ + proxies = {} + + for proxy in ['http_proxy', 'https_proxy']: + if self.config and self.config.get('MAIN', proxy): + proxies[proxy.split('_')[0]] = self.config.get('MAIN', proxy) + elif self.get_option(proxy): + proxies[proxy.split('_')[0]] = self.get_option(proxy) + elif os.getenv(proxy): + proxies[proxy.split('_')[0]] = os.getenv(proxy) + if self.config and proxies == {}: + self.output.debug("Warning: unable to determine proxies.", 6) + + return proxies + class OptionConfig(BareConfig): """This subclasses BareCongig adding functions to make overriding |