예제 #1
0
 def get_output_by_conf(conf: WhatTheFileConfiguration):
     if "output" in conf.get_whatthefile_secction():
         output = conf.get_whatthefile_secction()["output"]
         if output == "print":
             return OutputFactory._get_print_output(conf.get_section("output.print"))
         if output == "list":
             return OutputFactory._get_list_output(conf.get_section("output.list"))
         if output == "file":
             return OutputFactory._get_file_output(conf.get_section("output.file"))
         if output == "elasticsearch":
             return OutputFactory._get_elasticsearch_output(conf.get_section("output.elasticsearch"))
     return OutputFactory._get_print_output(conf.get_section("output.print"))
예제 #2
0
    def configure(conf: WhatTheFileConfiguration):
        output = conf.get_property("whatthefile", "log_output")

        switcher = {
            "stdout":
            sys.stdout,
            "stderr":
            sys.stderr,
            "file":
            conf.get_section("log_output.file")["filename"] +
            str("_{time}.log") if "filename"
            in conf.get_section("log_output.file") else sys.stderr
        }
        logger.remove()
        logger.add(switcher.get(output, sys.stderr),
                   format="{time} {level} {message}",
                   level=conf.get_section("whatthefile")["log_level"] if
                   "log_level" in conf.get_section("whatthefile") else "DEBUG")
예제 #3
0
 def _import_module(conf: WhatTheFileConfiguration, module_section_name,
                    position: int) -> Module:
     module_name = module_section_name.split(".")[1]
     try:
         mod = importlib.import_module(
             conf.get_property("whatthefile", "modules_package") + "." +
             module_name + ".main")
         py_mod = getattr(mod, "Constructor")()
         configuration = conf.get_whatthefile_secction()
         configuration.update(conf.get_section(module_section_name))
         py_mod.set_params(configuration)
         return Module(module_name, position, py_mod)
     except:
         traceback.print_exc()
         return None
 def test_load_conf_dict(self):
     conf = WhatTheFileConfiguration()
     conf.parse_dict(self.get_conf_dict())
     self.assertEqual(len(conf.get_modules_names()), 10)
     self.assertTrue(conf.get_property_boolean("module.hashes", "active"))
     self.assertTrue("active" in conf.get_section("module.hashes"))
 def test_load_conf_file(self):
     conf = WhatTheFileConfiguration()
     conf.parse_file('./tests/examples/whatthefile.ini')
     self.assertEqual(len(conf.get_modules_names()), 10)
     self.assertTrue(conf.get_property_boolean("module.hashes", "active"))
     self.assertTrue("active" in conf.get_section("module.hashes"))