# coding: utf-8

import logging
import xml.etree.ElementTree as ET

logger = logging.getLogger(__name__)


def get_sdf_urdf_model_name(model_path):
    mytree = ET.parse(model_path)
    myroot = mytree.getroot()
    for elem in myroot.iter():
        if elem.tag in ('link', 'joint', 'material', 'visual', 'collision'):
            continue
        if not elem.attrib.get('name'):
            continue
        return elem.attrib.get('name')
    return logger.warning('Model %s do not have a name!', model_path)
