Exemple #1
0
    def test_rule_extraction(self):
        hosts = get_configuration(self.example_xml)
        hosts = convert_to_dict(hosts)
        self.assertIn("www.lesiteimmo.com", hosts)

        self.assertEqual(len(hosts['www.lesiteimmo.com']), 6)
        patterns = hosts['www.lesiteimmo.com']
        self.pattern_asserts(patterns)
Exemple #2
0
def main(*argv):
    """
    = Configuration import =

    check "--help"

    Run command: python -m toddler.tools.configimport

    :param argv:
    :return:
    """
    parser = argparse.ArgumentParser(argv, description="ConfigImport v{}".format(__version__))

    parser.add_argument("-t", "--type", help="Config type", choices=["crawl"])

    if len(argv) > 0:
        args = setup(argv, argument_parser=parser, do_not_parse_config=True)
    else:
        args = setup(argument_parser=parser, do_not_parse_config=True)

    print(Style.DIM + Fore.BLUE + "ConfigImport v{}".format(__version__))

    with open(args.config) as config_file:
        print(Fore.BLUE + "Opened file:" + Fore.RESET + " {}".format(args.config) + Fore.RESET)
        if args.type == "crawl":
            print(Style.BRIGHT + Fore.BLUE + "Importing crawlConfig")
            from toddler.imports.nimbuscrawl import get_configuration
            from toddler.models import Host

            config_content = config_file.read()
            config = get_configuration(config_content)
            for host_name, crawl_config in config:
                host = Host.objects(host=host_name).first()
                if host is None:
                    host = Host(host=host_name)

                host.config["crawlConfig"] = crawl_config
                host.save()
                print(Fore.GREEN + "+ Added config for host {}".format(host_name))