5 def read_config(config_files, **predata):
7 for config_file in config_files:
8 cfg.update(_read_config_file(
13 def _read_config_file(_config_file, predata):
14 _file = open(_config_file)
15 exec _file in globals(), predata
18 for _k, _v in predata.iteritems():
19 if not _k.startswith('_'):
21 for _k, _v in locals().iteritems():
22 if not _k.startswith('_'):
26 class SiteList(object):
31 def __getitem__(self, key):
32 if key not in self.sites:
34 return self.sites[key]
37 return self.sites.itervalues()
40 class ConfiguredSite(client.Site):
42 def __init__(self, *config_files, **kwargs):
43 self.config = read_config(config_files, sites=SiteList())
46 self.config.update(self.config['sites'][kwargs['name']])
48 do_login = 'username' in self.config and 'password' in self.config
50 client.Site.__init__(self, host=self.config['host'],
51 path=self.config['path'], ext=self.config.get('ext', '.php'),
53 retry_timeout=self.config.get('retry_timeout', 30),
54 max_retries=self.config.get('max_retries', -1))
57 self.login(self.config['username'],
58 self.config['password'])
61 class ConfiguredPool(list):
63 def __init__(self, *config_files):
64 self.config = read_config(config_files, sites=SiteList())
65 self.pool = requests.Session()
67 config = dict([(k, v) for k, v in self.config.iteritems()
70 for site in self.config['sites']:
75 do_login = 'username' in site and 'password' in site
77 self.append(client.Site(host=site['host'],
78 path=site['path'], ext=site.get('ext', '.php'),
79 pool=self.pool, do_init=not do_login,
80 retry_timeout=site.get('retry_timeout', 30),
81 max_retries=site.get('max_retries', -1)))
83 self[-1].login(site['username'], site['password'])
84 self[-1].config = site