def _process_formatting_tags(self, song_xml, temporary): """ Process the formatting tags from the song and either add missing tags temporary or permanently to the formatting tag list. """ if not hasattr(song_xml, u'format'): return found_tags = [] for tag in song_xml.format.tags.getchildren(): name = tag.get(u'name') if name is None: continue start_tag = u'{%s}' % name[:5] # Some tags have only start tag e.g. {br} end_tag = u'{/' + name[:5] + u'}' if hasattr(tag, 'close') else u'' openlp_tag = { u'desc': name, u'start tag': start_tag, u'end tag': end_tag, u'start html': tag.open.text, # Some tags have only start html e.g. {br} u'end html': tag.close.text if hasattr(tag, 'close') else u'', u'protected': False, } # Add 'temporary' key in case the formatting tag should not be # saved otherwise it is supposed that formatting tag is permanent. if temporary: openlp_tag[u'temporary'] = temporary found_tags.append(openlp_tag) existing_tag_ids = [tag[u'start tag'] for tag in FormattingTags.get_html_tags()] new_tags = [tag for tag in found_tags if tag[u'start tag'] not in existing_tag_ids] FormattingTags.add_html_tags(new_tags) FormattingTags.save_html_tags()
def _process_formatting_tags(self, song_xml, temporary): """ Process the formatting tags from the song and either add missing tags temporary or permanently to the formatting tag list. :param song_xml: The song XML :param temporary: Is the song temporary? """ if not hasattr(song_xml, 'format'): return found_tags = [] for tag in song_xml.format.tags.getchildren(): name = tag.get('name') if name is None: continue start_tag = '{{{name}}}'.format(name=name[:5]) # Some tags have only start tag e.g. {br} end_tag = '{{/{name}}}'.format( name=name[:5]) if hasattr(tag, 'close') else '' openlp_tag = { 'desc': name, 'start tag': start_tag, 'end tag': end_tag, 'start html': tag.open.text, # Some tags have only start html e.g. {br} 'end html': tag.close.text if hasattr(tag, 'close') else '', 'protected': False, # Add 'temporary' key in case the formatting tag should not be saved otherwise it is supposed that # formatting tag is permanent. 'temporary': temporary } found_tags.append(openlp_tag) existing_tag_ids = [ tag['start tag'] for tag in FormattingTags.get_html_tags() ] new_tags = [ tag for tag in found_tags if tag['start tag'] not in existing_tag_ids ] # Do not save an empty list. if new_tags: FormattingTags.add_html_tags(new_tags) if not temporary: custom_tags = [ tag for tag in FormattingTags.get_html_tags() if not tag['protected'] and not tag['temporary'] ] FormattingTags.save_html_tags(custom_tags)
def _process_formatting_tags(self, song_xml, temporary): """ Process the formatting tags from the song and either add missing tags temporary or permanently to the formatting tag list. :param song_xml: The song XML :param temporary: Is the song temporary? """ if not hasattr(song_xml, "format"): return found_tags = [] for tag in song_xml.format.tags.getchildren(): name = tag.get("name") if name is None: continue start_tag = "{%s}" % name[:5] # Some tags have only start tag e.g. {br} end_tag = "{/" + name[:5] + "}" if hasattr(tag, "close") else "" openlp_tag = { "desc": name, "start tag": start_tag, "end tag": end_tag, "start html": tag.open.text, # Some tags have only start html e.g. {br} "end html": tag.close.text if hasattr(tag, "close") else "", "protected": False, # Add 'temporary' key in case the formatting tag should not be saved otherwise it is supposed that # formatting tag is permanent. "temporary": temporary, } found_tags.append(openlp_tag) existing_tag_ids = [tag["start tag"] for tag in FormattingTags.get_html_tags()] new_tags = [tag for tag in found_tags if tag["start tag"] not in existing_tag_ids] # Do not save an empty list. if new_tags: FormattingTags.add_html_tags(new_tags) if not temporary: custom_tags = [ tag for tag in FormattingTags.get_html_tags() if not tag["protected"] and not tag["temporary"] ] FormattingTags.save_html_tags(custom_tags)
def _process_formatting_tags(self, song_xml, temporary): """ Process the formatting tags from the song and either add missing tags temporary or permanently to the formatting tag list. :param song_xml: The song XML :param temporary: Is the song temporary? """ if not hasattr(song_xml, 'format'): return found_tags = [] for tag in song_xml.format.tags.getchildren(): name = tag.get('name') if name is None: continue start_tag = '{%s}' % name[:5] # Some tags have only start tag e.g. {br} end_tag = '{/' + name[:5] + '}' if hasattr(tag, 'close') else '' openlp_tag = { 'desc': name, 'start tag': start_tag, 'end tag': end_tag, 'start html': tag.open.text, # Some tags have only start html e.g. {br} 'end html': tag.close.text if hasattr(tag, 'close') else '', 'protected': False, # Add 'temporary' key in case the formatting tag should not be saved otherwise it is supposed that # formatting tag is permanent. 'temporary': temporary } found_tags.append(openlp_tag) existing_tag_ids = [tag['start tag'] for tag in FormattingTags.get_html_tags()] new_tags = [tag for tag in found_tags if tag['start tag'] not in existing_tag_ids] # Do not save an empty list. if new_tags: FormattingTags.add_html_tags(new_tags) if not temporary: custom_tags = [tag for tag in FormattingTags.get_html_tags() if not tag['protected'] and not tag['temporary']] FormattingTags.save_html_tags(custom_tags)
def save_tags(self): """ Save the new tags if they are valid. """ FormattingTags.save_html_tags(self.custom_tags) FormattingTags.load_tags()