def process_parent_labels(elem): name = None parent_name = None for e in elem.iterchildren(): if e.tag == 'name' and e.text is not None: name = e.text if e.tag == 'parentLabel' and e.text is not None: # We strip() because some parentLabels have erroneous whitespace parent_name = e.text.strip() if name is None or parent_name is None: return label = Label.get_by_name(name) if label is None: return label.set_parent_label(parent_name) return label
def process_label_sublabels(elem): name = None sublabels = [] for e in elem.iterchildren(): if e.tag == 'name' and e.text is not None: name = e.text if e.tag == 'sublabels': for f in e.iterchildren(tag='label'): if f.text is not None: sublabels.append(f.text) if name is None or not sublabels: return label = Label.get_by_name(name) if label is None: return label.set_sublabels(sublabels) return label