# Tai Sakuma <tai.sakuma@cern.ch>

##____________________________________________________________________________||
import os

##____________________________________________________________________________||
class Heppy(object):
    def __init__(self, path):
        self.path = path
        excludeList = ('Chunks', 'failed')
        self.componentNames = [n for n in os.listdir(path) if os.path.isdir(os.path.join(path, n)) and n not in excludeList]

        self._compDict = { }

    def __getattr__(self, name):
        if name not in self._compDict:
            if name not in self.componentNames:
                raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
            path = os.path.join(self.path, name)
            self._compDict[name] = Component(path)
        return self._compDict[name]

    def components(self):
        return [getattr(self, n) for n in self.componentNames]

##____________________________________________________________________________||
class Component(object):
    def __init__(self, path):
        self.path = path
        self.name = os.path.basename(path)
        self.analyzerNames = [n for n in os.listdir(self.path) if os.path.isdir(os.path.join(self.path, n))]

    def __getattr__(self, name):
        if name not in self.analyzerNames:
            raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
        path = os.path.join(self.path, name)
        return Analyzer(path)

##____________________________________________________________________________||
class Analyzer(object):
    def __init__(self, path):
        self.path = path
        self.name = os.path.basename(path)

##____________________________________________________________________________||
if __name__ == '__main__':
    pass

# Tai Sakuma <tai.sakuma@cern.ch>

##____________________________________________________________________________||
import os

##____________________________________________________________________________||
class Heppy(object):
    def __init__(self, path):
        self.path = path
        excludeList = ('Chunks', 'failed')
        self.componentNames = [n for n in os.listdir(path) if os.path.isdir(os.path.join(path, n)) and n not in excludeList]

        self._compDict = { }

    def __getattr__(self, name):
        if name not in self._compDict:
            if name not in self.componentNames:
                raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
            path = os.path.join(self.path, name)
            self._compDict[name] = Component(path)
        return self._compDict[name]

    def components(self):
        return [getattr(self, n) for n in self.componentNames]

##____________________________________________________________________________||
class Component(object):
    def __init__(self, path):
        self.path = path
        self.name = os.path.basename(path)
        self.analyzerNames = [n for n in os.listdir(self.path) if os.path.isdir(os.path.join(self.path, n))]

        self._anaDict = { }

    def __getattr__(self, name):
        if name not in self._anaDict:
            if name not in self.analyzerNames:
                raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
            path = os.path.join(self.path, name)
            self._anaDict[name] = Analyzer(path)
        return self._anaDict[name]

##____________________________________________________________________________||
class Analyzer(object):
    def __init__(self, path):
        self.path = path
        self.name = os.path.basename(path)

##____________________________________________________________________________||
if __name__ == '__main__':
    pass

make Component use the same object for the same analyzer