#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
list_svg_layers.py
Liste les groupes (<g>) dans un SVG pour trouver les noms de couches.
"""

from lxml import etree

SVG_INPUT = "carte_analyses_original.svg"

NS = {
    "svg": "http://www.w3.org/2000/svg",
    "inkscape": "http://www.inkscape.org/namespaces/inkscape",
}

def main():
    parser = etree.XMLParser(remove_comments=True)
    tree = etree.parse(SVG_INPUT, parser)
    root = tree.getroot()

    groups = root.findall(".//svg:g", namespaces=NS)

    print("Groupes trouvés dans le SVG :")
    for i, g in enumerate(groups, start=1):
        gid = g.attrib.get("id", "")
        label = g.attrib.get("{http://www.inkscape.org/namespaces/inkscape}label", "")
        mode = g.attrib.get("{http://www.inkscape.org/namespaces/inkscape}groupmode", "")
        print(f"{i:3d}. id='{gid}'  label='{label}'  groupmode='{mode}'")

if __name__ == "__main__":
    main()