def merge_project_settings(in_tree, updates): itp = in_tree.setdefault('project', comments.CommentedMap()) up = updates.get('project', comments.CommentedMap()) LOG.debug('merging templates') templates = itp.get('templates', []) for t in up.get('templates', []): if t not in templates: LOG.debug(' adding %s', t) templates.append(t) if templates and 'templates' not in itp: LOG.debug(' saving updates') itp.insert(0, 'templates', templates) for pipeline in up.keys(): if pipeline == 'templates': continue if pipeline in ('pre-release', 'release'): LOG.info(' skipping %s pipeline', pipeline) continue new_data = merge_pipeline( pipeline, itp.get(pipeline, comments.CommentedMap()), up.get(pipeline, comments.CommentedMap()), ) if new_data and pipeline not in itp: LOG.debug(' saving %s', pipeline) itp[pipeline] = new_data return in_tree
def test_no_data(self): expected = {} in_tree = comments.CommentedMap() project_config = {} actual = jobs.merge_pipeline( 'check', in_tree, project_config, ) self.assertEqual(expected, actual)
def test_just_queue_2(self): expected = { 'gate': 'gate-name', } in_tree = comments.CommentedMap({ 'gate': 'gate-name', }) project_config = {} actual = jobs.merge_pipeline( 'check', in_tree, project_config, ) self.assertEqual(expected, actual)
def _YAML_represent_instance(dumper, has_traits): from ..cmdlet import traitquery from ruamel.yaml import comments traits = traitquery.select_traits(has_traits, YAMLable, config=True) #cls_name = getattr(has_traits, 'name', type(has_traits).__name__) ddict = {tname: preserve_yaml_literals(getattr(has_traits, tname)) for tname, trait in traits.items()} if _dump_trait_help.get(): ddict = comments.CommentedMap((tname, tvalue) for tname, tvalue in ddict.items() if tvalue != traits[tname].default()) for tname, trait in traits.items(): ddict.yaml_set_comment_before_after_key( tname, before=_make_trait_help(has_traits, trait)) return get_yamel().representer.represent_dict(ddict)
def test_templates_0(self): expected = { 'project': { 'templates': [ 'a', 'b', ], }, } in_tree = comments.CommentedMap() project_config = { 'templates': [ 'a', 'b', ], } actual = jobs.merge_project_settings( {'project': in_tree}, {'project': project_config}, ) self.assertEqual(expected, actual)
def _StartNewCommandExecution(self): if self.current_action: yaml.convert_to_block_text(self.current_action) Interceptor.SCENARIO_DATA['actions'].append(self.current_action) self.current_action = {'execute_command': comments.CommentedMap( [('command', ''), ('events', [])])}
def __set_content_into_built_options(self): content = comments.CommentedMap() populated_content = self.__add_default_options(content) commented_content = self.__add_option_comments(populated_content) self.__built_options[self.__options.plugin_name] = commented_content
def __set_header_into_built_options(self): header = comments.CommentedMap() header.yaml_add_eol_comment( self.__options.module_comment, self.__options.plugin_name ) self.__built_options = header