# Path: sydpy/component.py
# class Component:
#     """Component class is the base class for all objects that are part of the user 
#     object hierarchy.    
#     """
#     
#     comp = {}
#     __cur_parent_class__ = None
#     
#     def __init__(self, name=None, parent=None, **kwargs):
#         """Instantiate a new compinit
#         
#         name    -- The name of the compinit
#         """
#         self.name = name
#         self._parent = parent
#         if parent is not None:
#             self._parent.comp[name] = self
#         self.comp = {}
# 
# #     @property
# #     def qname(self):
# #         if self.name:
# #             if self._parent:
# #                 return sep.join([self._parent.qname, self.name])
# # 
# #         return self.name
# 
#     def __repr__(self):
#         return self.name
# 
#     def __setitem__(self, key, val):
#         try:
#             val = sydsys().get_config(self.name, key)
#         except KeyError: 
#             pass
#         
#         self.comp[key] = val
#         
#         return val
#     
#     def __getitem__(self, key):
# #         return ddic[sep.join([self.qname, key])]
#         return self.comp[key]
# 
#     def inst(self, name, cls, *args, **kwargs):
#         try:
#             val = sydsys().get_config(self.name, name)
#             if not inspect.isclass(val):
#                 setattr(self, name, val)
#                 return val
#             else:
#                 cls = val
#         except KeyError: 
#             pass
#         
#         
#         if self.name:
#             qname = self.name + '.' + name
#         else:
#             qname = name
#         
#         obj = cls(qname, *args , **kwargs)
#         
#         self.comp[name] = obj
#         
#         return obj
#     
#     def search(self, pattern='*', of_type=None, depth=0, pattern_relative=True):
#         
#         if pattern_relative:
#             if self.name:
#                 pattern = sep.join([self.name, pattern])
# 
#         for _, c in self.comp.items():
#             if fnmatch.fnmatch(c.name, pattern):
#                 if (of_type is None) or isinstance(c, of_type):
#                     yield c
#                     
#                 if depth:
#                     yield from c.search(pattern, pattern_relative=False, depth=depth-1)


from sydpy.component import Component

class Unit(Component):
    
    def __init__(self, parent, name, **kwargs):
        Component.__init__(self, name)
        self.__dict__.update(kwargs)
        if parent:
            parent += self
            self._reload_cfg_index()
            self._apply_cfg()
        
        self.build()

    def build(self):
        pass
    
    def _reload_cfg_index(self):
        self.find('/cfg').reload_index()
        

# Path: sydpy/component.py
# class Component:
#     """Component class is the base class for all objects that are part of the user 
#     object hierarchy.    
#     """
#     
#     comp = {}
#     __cur_parent_class__ = None
#     
#     def __init__(self, name=None, parent=None, **kwargs):
#         """Instantiate a new compinit
#         
#         name    -- The name of the compinit
#         """
#         self.name = name
#         self._parent = parent
#         if parent is not None:
#             self._parent.comp[name] = self
#         self.comp = {}
# 
# #     @property
# #     def qname(self):
# #         if self.name:
# #             if self._parent:
# #                 return sep.join([self._parent.qname, self.name])
# # 
# #         return self.name
# 
#     def __repr__(self):
#         return self.name
# 
#     def __setitem__(self, key, val):
#         try:
#             val = sydsys().get_config(self.name, key)
#         except KeyError: 
#             pass
#         
#         self.comp[key] = val
#         
#         return val
#     
#     def __getitem__(self, key):
# #         return ddic[sep.join([self.qname, key])]
#         return self.comp[key]
# 
#     def inst(self, name, cls, *args, **kwargs):
#         try:
#             val = sydsys().get_config(self.name, name)
#             if not inspect.isclass(val):
#                 setattr(self, name, val)
#                 return val
#             else:
#                 cls = val
#         except KeyError: 
#             pass
#         
#         
#         if self.name:
#             qname = self.name + '.' + name
#         else:
#             qname = name
#         
#         obj = cls(qname, *args , **kwargs)
#         
#         self.comp[name] = obj
#         
#         return obj
#     
#     def search(self, pattern='*', of_type=None, depth=0, pattern_relative=True):
#         
#         if pattern_relative:
#             if self.name:
#                 pattern = sep.join([self.name, pattern])
# 
#         for _, c in self.comp.items():
#             if fnmatch.fnmatch(c.name, pattern):
#                 if (of_type is None) or isinstance(c, of_type):
#                     yield c
#                     
#                 if depth:
#                     yield from c.search(pattern, pattern_relative=False, depth=depth-1)


# Path: sydpy/unit.py
from sydpy.component import Component


class Unit(Component):
    
    def __init__(self, parent, name, **kwargs):
        Component.__init__(self, name)
        self.__dict__.update(kwargs)
        if parent:
            parent += self
            self._reload_cfg_index()
            self._apply_cfg()
        
        self.build()

    def build(self):
        pass
    
    def _reload_cfg_index(self):
        self.find('/cfg').reload_index()
        

    def _apply_cfg(self):