# Path: coshsh/application.py
# class Application(coshsh.item.Item):
# 
#     class_factory = []
#     lower_columns = ['name', 'type', 'component', 'version', 'patchlevel']
# 
#     def __init__(self, params):
#         #print "Application init", self.__class__, self.__class__.__name__, len(self.__class__.class_factory)
#         if self.__class__.__name__ == "Application":
#             for c in self.__class__.lower_columns:
#                 try:
#                     params[c] = params[c].lower()
#                 except Exception:
#                     if c in params:
#                         params[c] = None
#             newcls = self.__class__.get_class(params)
#             if newcls:
#                 self.__class__ = newcls
#                 self.contact_groups = []
#                 super(Application, self).__init__(params)
#                 self.__init__(params)
#                 self.fingerprint = lambda s=self:s.__class__.fingerprint(params)
#             else:
#                 logger.debug('this will be Generic %s' % params)
#                 self.__class__ = GenericApplication
#                 self.contact_groups = []
#                 super(Application, self).__init__(params)
#                 self.__init__(params)
#                 #raise ApplicationNotImplemented
#                 self.fingerprint = lambda s=self:s.__class__.fingerprint(params)
#         else:
#             pass
# 
#     @classmethod
#     def fingerprint(self, params={}):
#         return "%s+%s+%s" % (params["host_name"], params["name"], params["type"])
# 
#     def _i_init__(self, params={}):
#         super(Application, self).__init__(params)
#         self.contact_groups = []
# 
#     def create_servicegroups(self):
#         pass
# 
#     def create_contacts(self):
#         pass
# 
#     def create_templates(self):
#         pass
# 
#     @classmethod
#     def init_classes(cls, classpath):
#         sys.dont_write_bytecode = True
#         for p in [p for p in reversed(classpath) if os.path.exists(p) and os.path.isdir(p)]:
#             for module, path in [(item, p) for item in sorted(os.listdir(p), reverse=True) if item[-3:] == ".py" and (item.startswith('app_') or item.startswith('os_'))]:
#                 try:
#                     path = os.path.abspath(path)
#                     fp, filename, data = imp.find_module(module.replace('.py', ''), [path])
#                     toplevel = imp.load_source(module.replace(".py", ""), filename)
#                     for cl in inspect.getmembers(toplevel, inspect.isfunction):
#                         if cl[0] ==  "__mi_ident__":
#                             cls.class_factory.append([path, module, cl[1]])
#                 except Exception, e:
#                     print e
#                 finally:
#                     if fp:
#                         fp.close()
#         #print ".............fill %s / %s woth %s" % (cls, cls.__name__, cls.class_factory)
# 
# 
#     @classmethod
#     def get_class(cls, params={}):
#         #print "getclass from cache", cls, cls.__name__,  cls.class_factory
#         for path, module, class_func in reversed(cls.class_factory):
#             try:
#                 #print "get_class trys", path, module, class_func
#                 newcls = class_func(params)
#                 #print "get_class says", newcls.__module__, sys.modules[newcls.__module__].__file__
#                 if newcls:
#                     return newcls
#             except Exception:
#                 pass
#         logger.debug("found no matching class for this monitoring item %s" % params)
#         return None
# 
# Path: coshsh/templaterule.py
# class TemplateRule:
#     def __init__(self, needsattr=None, isattr=None, template=None, unique_attr="name", unique_config=None, self_name="application", suffix="cfg", for_tool="nagios"):
#         # This rule applies by default (needsattr=None) or if a certain
#         # property exists
#         self.needsattr = needsattr
#         self.isattr = isattr
#         self.template = template
#         # Sometimes more than one configs are needed
#         # This property is used to separate the application objects
#         self.unique_attr = unique_attr 
#         # The name of the config file which can contain %s
#         self.unique_config = unique_config
#         self.suffix = suffix
#         self.self_name = self_name
#         self.for_tool = for_tool
#     
#     def __str__(self):
#         return "Rule: needsattr=%s, isattr=%s, template=%s, unique_attr=%s, unique_config=%s, suffix=%s, self_name=%s" % (self.needsattr, self.isattr, self.template, self.unique_attr, self.unique_config, self.suffix, self.self_name)
# 
# Path: coshsh/util.py
# def compare_attr(key, params, strings):
#     if not isinstance(strings, list):
#         strings = [strings]
#     if key in params:
#         if params[key] == None:
#             return False
#         elif [str1 for str1 in strings if re.match(str1, params[key], re.IGNORECASE)]:
#             return True
#     return False


import coshsh
from coshsh.application import Application
from coshsh.templaterule import TemplateRule
from coshsh.util import compare_attr

def __mi_ident__(params={}):
    if coshsh.util.compare_attr("type", params, ".*red\s*hat.*|.*sles.*|.*linux.*|.*limux.*|.*debian.*|.*ubuntu.*|.*centos.*"):
        return Linux


class Linux(coshsh.application.Application):
    marker = "corporate"
    template_rules = [
        coshsh.templaterule.TemplateRule(needsattr=None, 
            template="os_linux_default"),

# Path: coshsh/application.py
# class Application(coshsh.item.Item):
# 
#     class_factory = []
#     lower_columns = ['name', 'type', 'component', 'version', 'patchlevel']
# 
#     def __init__(self, params):
#         #print "Application init", self.__class__, self.__class__.__name__, len(self.__class__.class_factory)
#         if self.__class__.__name__ == "Application":
#             for c in self.__class__.lower_columns:
#                 try:
#                     params[c] = params[c].lower()
#                 except Exception:
#                     if c in params:
#                         params[c] = None
#             newcls = self.__class__.get_class(params)
#             if newcls:
#                 self.__class__ = newcls
#                 self.contact_groups = []
#                 super(Application, self).__init__(params)
#                 self.__init__(params)
#                 self.fingerprint = lambda s=self:s.__class__.fingerprint(params)
#             else:
#                 logger.debug('this will be Generic %s' % params)
#                 self.__class__ = GenericApplication
#                 self.contact_groups = []
#                 super(Application, self).__init__(params)
#                 self.__init__(params)
#                 #raise ApplicationNotImplemented
#                 self.fingerprint = lambda s=self:s.__class__.fingerprint(params)
#         else:
#             pass
# 
#     @classmethod
#     def fingerprint(self, params={}):
#         return "%s+%s+%s" % (params["host_name"], params["name"], params["type"])
# 
#     def _i_init__(self, params={}):
#         super(Application, self).__init__(params)
#         self.contact_groups = []
# 
#     def create_servicegroups(self):
#         pass
# 
#     def create_contacts(self):
#         pass
# 
#     def create_templates(self):
#         pass
# 
#     @classmethod
#     def init_classes(cls, classpath):
#         sys.dont_write_bytecode = True
#         for p in [p for p in reversed(classpath) if os.path.exists(p) and os.path.isdir(p)]:
#             for module, path in [(item, p) for item in sorted(os.listdir(p), reverse=True) if item[-3:] == ".py" and (item.startswith('app_') or item.startswith('os_'))]:
#                 try:
#                     path = os.path.abspath(path)
#                     fp, filename, data = imp.find_module(module.replace('.py', ''), [path])
#                     toplevel = imp.load_source(module.replace(".py", ""), filename)
#                     for cl in inspect.getmembers(toplevel, inspect.isfunction):
#                         if cl[0] ==  "__mi_ident__":
#                             cls.class_factory.append([path, module, cl[1]])
#                 except Exception, e:
#                     print e
#                 finally:
#                     if fp:
#                         fp.close()
#         #print ".............fill %s / %s woth %s" % (cls, cls.__name__, cls.class_factory)
# 
# 
#     @classmethod
#     def get_class(cls, params={}):
#         #print "getclass from cache", cls, cls.__name__,  cls.class_factory
#         for path, module, class_func in reversed(cls.class_factory):
#             try:
#                 #print "get_class trys", path, module, class_func
#                 newcls = class_func(params)
#                 #print "get_class says", newcls.__module__, sys.modules[newcls.__module__].__file__
#                 if newcls:
#                     return newcls
#             except Exception:
#                 pass
#         logger.debug("found no matching class for this monitoring item %s" % params)
#         return None
# 
# Path: coshsh/templaterule.py
# class TemplateRule:
#     def __init__(self, needsattr=None, isattr=None, template=None, unique_attr="name", unique_config=None, self_name="application", suffix="cfg", for_tool="nagios"):
#         # This rule applies by default (needsattr=None) or if a certain
#         # property exists
#         self.needsattr = needsattr
#         self.isattr = isattr
#         self.template = template
#         # Sometimes more than one configs are needed
#         # This property is used to separate the application objects
#         self.unique_attr = unique_attr 
#         # The name of the config file which can contain %s
#         self.unique_config = unique_config
#         self.suffix = suffix
#         self.self_name = self_name
#         self.for_tool = for_tool
#     
#     def __str__(self):
#         return "Rule: needsattr=%s, isattr=%s, template=%s, unique_attr=%s, unique_config=%s, suffix=%s, self_name=%s" % (self.needsattr, self.isattr, self.template, self.unique_attr, self.unique_config, self.suffix, self.self_name)
# 
# Path: coshsh/util.py
# def compare_attr(key, params, strings):
#     if not isinstance(strings, list):
#         strings = [strings]
#     if key in params:
#         if params[key] == None:
#             return False
#         elif [str1 for str1 in strings if re.match(str1, params[key], re.IGNORECASE)]:
#             return True
#     return False


# Path: tests/recipes/test13c/classes/os_linux.py
import coshsh
from coshsh.application import Application
from coshsh.templaterule import TemplateRule
from coshsh.util import compare_attr


def __mi_ident__(params={}):
    if coshsh.util.compare_attr("type", params, ".*red\s*hat.*|.*sles.*|.*linux.*|.*limux.*|.*debian.*|.*ubuntu.*|.*centos.*"):
        return Linux


class Linux(coshsh.application.Application):
    marker = "corporate"
    template_rules = [
        coshsh.templaterule.TemplateRule(needsattr=None, 
            template="os_linux_default"),

        coshsh.templaterule.TemplateRule(needsattr="filesystems", 