commit: fda51375fed8b54e264e4577fb3d72385bbffa17 Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org> AuthorDate: Fri May 23 18:37:51 2014 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Thu Jun 12 21:11:50 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=fda51375
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. --- layman/config.py | 23 ++++++++++++++++++++++- layman/overlays/tar.py | 10 +--------- layman/remotedb.py | 11 ++--------- 3 files changed, 25 insertions(+), 19 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 diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py index d2c1cc9..a819475 100644 --- a/layman/overlays/tar.py +++ b/layman/overlays/tar.py @@ -88,19 +88,11 @@ class TarOverlay(OverlaySource): def __init__(self, parent, config, _location, ignore = 0): - self.proxies = {} - - for proxy in ['http_proxy', 'https_proxy']: - if config[proxy]: - self.proxies[proxy.split('_')[0]] = config[proxy] - elif os.getenv(proxy): - self.proxies[proxy.split('_')[0]] = os.getenv(proxy) - - super(TarOverlay, self).__init__(parent, config, _location, ignore) self.output = config['output'] + self.proxies = config.proxies self.subpath = None def __eq__(self, other): diff --git a/layman/remotedb.py b/layman/remotedb.py index 175aeb5..f883799 100644 --- a/layman/remotedb.py +++ b/layman/remotedb.py @@ -57,15 +57,8 @@ class RemoteDB(DbBase): self.output = config['output'] self.detached_urls = [] self.signed_urls = [] - - self.proxies = {} - - for proxy in ['http_proxy', 'https_proxy']: - if config[proxy]: - self.proxies[proxy.split('_')[0]] = config[proxy] - elif os.getenv(proxy): - self.proxies[proxy.split('_')[0]] = os.getenv(proxy) - + self.proxies = config.proxies + self.urls = [i.strip() for i in config['overlays'].split('\n') if len(i)]