コード例 #1
0
    def perform_test(self, name, setting_file, golden_file):
        print("%s test" % name, end="")
        sys.stdout.flush()
        from util.config import Config
        config = Config(get_file(setting_file))

        notify_data = collections.OrderedDict()
        for notify_name in config.notifications:
            parsed_data = collections.OrderedDict()
            notification = config.notifications[notify_name]
            for entry in notification.get_key_and_path():
                [key, path] = entry
                from util.content import get_content
                content = get_content(path)
                data_list = notification.parser.parse(content)
                assert data_list and type(data_list) is list
                source_key = tuple(sorted(key.items()))  # convert to sorted-tuple, for dict is not hashable
                parsed_data[source_key] = data_list
            analyzed_data = notification.post_analysis.analyze(parsed_data, notify_data)
            notify_data[notify_name] = analyzed_data
            os.remove("immature_" + notify_name + ".txt")
            os.remove("mature_" + notify_name + ".txt")
        with open(get_file(golden_file), encoding='utf8') as f:
            golden = f.read()
        from pp.pretty_print import get_beautiful_data
        self.assertEqual(get_beautiful_data(notify_data), golden)
コード例 #2
0
ファイル: main.py プロジェクト: sw-craftsmen/web-notifier
    def run(self):
        logging.info("[WbNt] web-notifier is running!")

        notify_data = collections.OrderedDict()  # key: notify_name, value: dict (see below)
        for notify_name in self.__config.notifications:
            logging.info("[WbNt] dealing with notification \"%s\"" % notify_name)
            parsed_data = collections.OrderedDict()  # key: source key, value: list of parsed data
            notification = self.__config.notifications[notify_name]
            for entry in notification.get_key_and_path():
                assert isinstance(entry, list) and 2 == len(entry)
                [key, path] = entry
                key_str = "" if 0 == len(key) else \
                    str([key_value_pair[1] for key_value_pair in list(key.items())])
                logging.debug("[WbNt] " + path)
                content = get_content(path, self.args.web_login, self.args.web_password)
                WebNotifier.backup_content(key, content, notify_name)
                data_list = notification.parser.parse(content)
                if data_list:
                    assert type(data_list) is list
                    source_key = tuple(sorted(key.items()))  # convert to sorted-tuple, for dict is not hashable
                    parsed_data[source_key] = data_list
                    logging.info("[WbNt] %s %sfind %i entry(s)" %
                                 (key_str, " => " if len(key_str) > 0 else "", len(data_list)))
                else:
                    if "" != key_str:
                        logging.info("[WbNt] %s" % key_str)
            info_entry = notification.parser.informative
            analyzed_data = notification.post_analysis.analyze(parsed_data, notify_data, info_entry)
            notify_data[notify_name] = analyzed_data

        pp_data = get_beautiful_data(notify_data, self.args.full_data)
        logging.info(pp_data)
        self.__config.audiences.notify(pp_data)

        import json
        output_file = self.args.output
        with open(output_file, 'w') as write_fd:
            json.dump(get_beautiful_pre_json(notify_data), write_fd)

        logging.info("[WbNt] notification done")