def _parse_siteconf(self, siteconf): if os.getenv("MIC_PLUGIN_DIR"): self.common["plugin_dir"] = os.environ["MIC_PLUGIN_DIR"] if siteconf and not os.path.exists(siteconf): msger.warning("cannot find config file: %s" % siteconf) siteconf = None if not siteconf: self.common["distro_name"] = "Tizen" # append common section items to other sections for section in self.DEFAULTS.keys(): if section != "common": getattr(self, section).update(self.common) return parser = ConfigParser.SafeConfigParser() parser.read(siteconf) for section in parser.sections(): if section in self.DEFAULTS: getattr(self, section).update(dict(parser.items(section))) # append common section items to other sections for section in self.DEFAULTS.keys(): if section != "common": getattr(self, section).update(self.common) # check and normalize the scheme of proxy url if self.create['proxy']: m = re.match('^(\w+)://.*', self.create['proxy']) if m: scheme = m.group(1) if scheme not in ('http', 'https', 'ftp', 'socks'): raise errors.ConfigError("%s: proxy scheme is incorrect" % siteconf) else: msger.warning("%s: proxy url w/o scheme, use http as default" % siteconf) self.create['proxy'] = "http://" + self.create['proxy'] proxy.set_proxies(self.create['proxy'], self.create['no_proxy']) # bootstrap option handling self.set_runtime(self.create['runtime']) if isinstance(self.bootstrap['packages'], basestring): packages = self.bootstrap['packages'].replace('\n', ' ') if packages.find(',') != -1: packages = packages.split(',') else: packages = packages.split() self.bootstrap['packages'] = packages if type(self.create['use_mic_in_bootstrap']) != 'bool': use_mic_in_bootstrap = str(self.create['use_mic_in_bootstrap']) if use_mic_in_bootstrap.lower() in ('on', 'yes', 'true', '1'): self.create['use_mic_in_bootstrap'] = True else: self.create['use_mic_in_bootstrap'] = False
def _parse_siteconf(self, siteconf): if os.getenv("MIC_PLUGIN_DIR"): self.common["plugin_dir"] = os.environ["MIC_PLUGIN_DIR"] if siteconf and not os.path.exists(siteconf): msger.warning("cannot find config file: %s" % siteconf) siteconf = None if not siteconf: self.common["distro_name"] = "Tizen" # append common section items to other sections for section in self.DEFAULTS.keys(): if section != "common": getattr(self, section).update(self.common) return parser = ConfigParser.SafeConfigParser() parser.read(siteconf) for section in parser.sections(): if section in self.DEFAULTS: getattr(self, section).update(dict(parser.items(section))) # append common section items to other sections for section in self.DEFAULTS.keys(): if section != "common": getattr(self, section).update(self.common) # check and normalize the scheme of proxy url if self.create['proxy']: m = re.match('^(\w+)://.*', self.create['proxy']) if m: scheme = m.group(1) if scheme not in ('http', 'https', 'ftp', 'socks'): raise errors.ConfigError("%s: proxy scheme is incorrect" % siteconf) else: msger.warning("%s: proxy url w/o scheme, use http as default" % siteconf) self.create['proxy'] = "http://" + self.create['proxy'] proxy.set_proxies(self.create['proxy'], self.create['no_proxy']) # bootstrap option handling self.set_runtime(self.create['runtime']) if isinstance(self.bootstrap['packages'], basestring): packages = self.bootstrap['packages'].replace('\n', ' ') if packages.find(',') != -1: packages = packages.split(',') else: packages = packages.split() self.bootstrap['packages'] = packages
def _parse_siteconf(self, siteconf): if not siteconf: return if not os.path.exists(siteconf): msger.warning("cannot read config file: %s" % siteconf) return parser = ConfigParser.SafeConfigParser() parser.read(siteconf) for section in parser.sections(): if section in self.DEFAULTS: getattr(self, section).update(dict(parser.items(section))) # append common section items to other sections for section in self.DEFAULTS.keys(): if section != "common": getattr(self, section).update(self.common) # check and normalize the scheme of proxy url if self.create['proxy']: m = re.match('^(\w+)://.*', self.create['proxy']) if m: scheme = m.group(1) if scheme not in ('http', 'https', 'ftp', 'socks'): msger.error("%s: proxy scheme is incorrect" % siteconf) else: msger.warning("%s: proxy url w/o scheme, use http as default" % siteconf) self.create['proxy'] = "http://" + self.create['proxy'] proxy.set_proxies(self.create['proxy'], self.create['no_proxy']) # bootstrap option handling self.set_runtime(self.create['runtime']) if isinstance(self.bootstrap['packages'], basestring): packages = self.bootstrap['packages'].replace('\n', ' ') if packages.find(',') != -1: packages = packages.split(',') else: packages = packages.split() self.bootstrap['packages'] = packages
def test_proxy(self): proxy.set_proxies('http://proxy.some.com:11', '1.2.3.4') self.assertEqual(proxy.get_proxy_for('http://1.2.3.4'), None) self.assertEqual(proxy.get_proxy_for('http://download.tizen.org'), 'http://proxy.some.com:11') proxy.set_proxies('http://proxy.some.com:11', 'download.am.org') self.assertEqual(proxy.get_proxy_for('http://download.am.org'), None) self.assertEqual(proxy.get_proxy_for('https://download.am.org'), None) self.assertEqual(proxy.get_proxy_for('http://download.tizen.org'), 'http://proxy.some.com:11') proxy.set_proxies('http://proxy.some.com:11', '1.2.3.0/24') self.assertEqual(proxy.get_proxy_for('http://1.2.3.4'), None) self.assertEqual(proxy.get_proxy_for('http://1.2.3.0'), None) self.assertEqual(proxy.get_proxy_for('http://1.2.3.255'), None) self.assertEqual(proxy.get_proxy_for('http://download.tizen.org'), 'http://proxy.some.com:11') proxy.set_proxies('http://proxy.some.com:11', '.hello.com') self.assertEqual(proxy.get_proxy_for('http://linux.hello.com'), None) self.assertEqual(proxy.get_proxy_for('http://linux.hello.com.org'), 'http://proxy.some.com:11')