#!/usr/bin/env/ python3

"""
Wrapper for xcfinfo
"""

import subprocess
import sys

class Xcfinfo():
    def __init__(self, filename):
        self.xcfinfo_str = subprocess.check_output(['xcfinfo', filename]) \
            .decode('utf-8')
        self.layers = {}
        for i, line in enumerate(self.xcfinfo_str.split('\n')[1:-1]):
            spl = line.split(' ', 4)
            self.layers[spl[4]] = {"visible": True if spl[0] == '+' else False,
                                   "offset": spl[1], "format": spl[2],
                                   "mode": spl[3], "pos": i}
        self.layernames = \
            sorted(self.layers.keys(), key=lambda x: self.layers[x]["pos"])

    def __getitem__(self, key):
        return self.layers[key]

if __name__ == "__main__":
    for n in Xcfinfo(sys.argv[1]).layernames:
        print(n)
