def test_ebconfigobj(self): """Test configobj sort""" # the as_dict method is crap # tc >= 0.0.0 returns empty as_dict, although the boundary can be used # anyway, will go away with proper defaults tcfirst = ",".join([ '%s == 0.0.0' % self.tc_namesmax[0], '%s > 0.0.0' % self.tc_namesmax[0] ]) configobj_txt = [ '[SUPPORTED]', 'toolchains=%s,%s >= 7.8.9' % (tcfirst, ','.join(self.tc_namesmax[1:])), 'versions=1.2.3,2.3.4,3.4.5', '[>= 2.3.4]', 'foo=bar', '[== 3.4.5]', 'baz=biz', '[%s == 5.6.7]' % self.tc_first, '[%s > 7.8.9]' % self.tc_lastmax, ] co = ConfigObj(configobj_txt) cov = EBConfigObj(co) # default tc is cgoolf -> cgoolf > 0.0.0 res = cov.get_specs_for(version='2.3.4', tcname=self.tc_first, tcversion='1.0.0') self.assertEqual(res, {'foo': 'bar'})
def test_nested_version(self): """Test nested config""" tc = {'version': '10', 'name': self.tc_first} default_version = '1.0' txt = [ '[SUPPORTED]', 'versions = %s, 0.0, 1.1, 1.5, 1.6, 2.0, 3.0' % default_version, 'toolchains = %(name)s == %(version)s' % tc, # set tc, don't use it '[> 1.0]', 'versionprefix = stable-', '[[>= 1.5]]', 'versionsuffix = -early', '[> 2.0]', 'versionprefix = production-', 'versionsuffix = -mature', ] # version string, attributes without version and toolchain data = [ (None, {}), (default_version, {}), ('0.0', {}), ('1.1', { 'versionprefix': 'stable-' }), ('1.5', { 'versionprefix': 'stable-', 'versionsuffix': '-early' }), ('1.6', { 'versionprefix': 'stable-', 'versionsuffix': '-early' }), ('2.0', { 'versionprefix': 'stable-', 'versionsuffix': '-early' }), ('3.0', { 'versionprefix': 'production-', 'versionsuffix': '-mature' }), ] for version, res in data: # yes, redo this for each test, even if it's static text # some of the data is modified in place co = ConfigObj(txt) cov = EBConfigObj(co) specs = cov.get_specs_for(version=version) self.assertEqual(specs, res)
def test_nested_version(self): """Test nested config""" tc = {'version': '10', 'name': self.tc_first} default_version = '1.0' txt = [ '[SUPPORTED]', 'versions = %s, 0.0, 1.1, 1.5, 1.6, 2.0, 3.0' % default_version, 'toolchains = %(name)s == %(version)s' % tc, # set tc, don't use it '[> 1.0]', 'versionprefix = stable-', '[[>= 1.5]]', 'versionsuffix = -early', '[> 2.0]', 'versionprefix = production-', 'versionsuffix = -mature', ] # version string, attributes without version and toolchain data = [ (None, {}), (default_version, {}), ('0.0', {}), ('1.1', {'versionprefix': 'stable-'}), ('1.5', {'versionprefix': 'stable-', 'versionsuffix': '-early'}), ('1.6', {'versionprefix': 'stable-', 'versionsuffix': '-early'}), ('2.0', {'versionprefix': 'stable-', 'versionsuffix': '-early'}), ('3.0', {'versionprefix': 'production-', 'versionsuffix': '-mature'}), ] for version, res in data: # yes, redo this for each test, even if it's static text # some of the data is modified in place co = ConfigObj(txt) cov = EBConfigObj(co) specs = cov.get_specs_for(version=version) self.assertEqual(specs, res)
def test_ebconfigobj(self): """Test configobj sort""" # the as_dict method is crap # tc >= 0.0.0 returns empty as_dict, although the boundary can be used # anyway, will go away with proper defaults tcfirst = ",".join(['%s == 0.0.0' % self.tc_namesmax[0], '%s > 0.0.0' % self.tc_namesmax[0]]) configobj_txt = [ '[SUPPORTED]', 'toolchains=%s,%s >= 7.8.9' % (tcfirst, ','.join(self.tc_namesmax[1:])), 'versions=1.2.3,2.3.4,3.4.5', '[>= 2.3.4]', 'foo=bar', '[== 3.4.5]', 'baz=biz', '[%s == 5.6.7]' % self.tc_first, '[%s > 7.8.9]' % self.tc_lastmax, ] co = ConfigObj(configobj_txt) cov = EBConfigObj(co) # default tc is cgoolf -> cgoolf > 0.0.0 res = cov.get_specs_for(version='2.3.4', tcname=self.tc_first, tcversion='1.0.0') self.assertEqual(res, {'foo':'bar'})
def get_config_dict(self): """Return the best matching easyconfig dict""" self.log.experimental(self.__class__.__name__) # the toolchain name/version should not be specified in the pyheader, # but other toolchain options are allowed cfg = copy.deepcopy(self.pyheader_localvars) self.log.debug("Config dict based on Python header: %s" % cfg) co = EBConfigObj(self.configobj) # we only need to find one version / toolchain combo # esp. the toolchain name should be fixed, so no need to process anything but one toolchain version = self.specs.get('version', None) if version is None: # check for default version if 'version' in co.default: version = co.default['version'] self.log.info("no software version specified, using default version '%s'" % version) else: self.log.error("no software version specified, no default version found") else: self.log.debug("Using specified software version %s" % version) tc_spec = self.specs.get('toolchain', {}) toolchain_name = tc_spec.get('name', None) if toolchain_name is None: # check for default toolchain if 'toolchain' in co.default: toolchain = co.default['toolchain'] toolchain_name = toolchain['name'] self.log.info("no toolchain name specified, using default '%s'" % toolchain_name) toolchain_version = tc_spec.get('version', None) if toolchain_version is None: toolchain_version = toolchain['version'] self.log.info("no toolchain version specified, using default '%s'" % toolchain_version) else: self.log.error("no toolchain name specified, no default toolchain found") else: self.log.debug("Using specified toolchain name %s" % toolchain_name) toolchain_version = tc_spec.get('version', None) if toolchain_version is None: self.log.error("Toolchain specification incomplete: name %s provided, but no version" % toolchain_name) # toolchain name is known, remove all others toolchains from parsed easyconfig before we continue # this also performs some validation, and checks for conflicts between section markers self.log.debug("sections for full parsed configobj: %s" % co.sections) co.validate_and_filter_by_toolchain(toolchain_name) self.log.debug("sections for filtered parsed configobj: %s" % co.sections) section_specs = co.get_specs_for(version=version, tcname=toolchain_name, tcversion=toolchain_version) cfg.update(section_specs) self.log.debug("Config dict after processing applicable easyconfig sections: %s" % cfg) # FIXME what about updating dict values/appending to list values? how do we allow both redefining and updating? = and +=? # update config with correct version/toolchain (to avoid using values specified in default section) cfg.update({ 'version': version, 'toolchain': {'name': toolchain_name, 'version': toolchain_version}, }) self.log.debug("Final config dict (including correct version/toolchain): %s" % cfg) return cfg