Exemple #1
0
    def parser_file_or_subpath_of_path(self, dataset, ds_id, ds_path,
                                       ds_rule_content, inbound_id):
        """
        处理目录(完整路径)下的子目录和文件
        :param inbound_id: 入库标识
        :param ds_rule_content:
        :param dataset: 数据集
        :param ds_id: 路径标识
        :param ds_path: 路径全名
        :return:
        """
        ds_storage_id = dataset.value_by_name(0, 'query_storage_id', '')
        ignore_file_array = settings.application.xpath_one(
            self.Path_Setting_MetaData_InBound_ignore_file, None)
        ignore_dir_array = settings.application.xpath_one(
            self.Path_Setting_MetaData_InBound_ignore_dir, None)

        file_list = CFile.file_or_subpath_of_path(ds_path)
        for file_name in file_list:
            file_name_with_full_path = CFile.join_file(ds_path, file_name)

            if CFile.is_dir(file_name_with_full_path):
                CLogger().debug('在目录{0}下发现子目录: {1}'.format(ds_path, file_name))

                if CUtils.list_count(ignore_dir_array, file_name) > 0:
                    CLogger().debug(
                        '子目录: {0}在指定的忽略入库名单中, 将不入库! '.format(file_name))
                    continue

                path_obj = CDMPathInfo(
                    self.FileType_Dir, file_name_with_full_path,
                    dataset.value_by_name(0, 'query_storage_id', ''), None,
                    ds_id,
                    dataset.value_by_name(0, 'query_dir_parent_objid', None),
                    self.get_mission_db_id(), ds_rule_content)

                if path_obj.white_black_valid():
                    path_obj.db_check_and_update(inbound_id)
                else:
                    CLogger().info('目录[{0}]未通过黑白名单检验, 不允许入库! '.format(
                        file_name_with_full_path))
            elif CFile.is_file(file_name_with_full_path):
                if CUtils.list_count(ignore_file_array, file_name) > 0:
                    CLogger().debug(
                        '子目录: {0}在指定的忽略入库名单中, 将不入库! '.format(file_name))
                    continue

                CLogger().debug('在目录{0}下发现文件: {1}'.format(ds_path, file_name))
                file_obj = CDMFileInfo(
                    self.FileType_File, file_name_with_full_path,
                    dataset.value_by_name(0, 'query_storage_id', ''), None,
                    ds_id,
                    dataset.value_by_name(0, 'query_dir_parent_objid', None),
                    self.get_mission_db_id(), ds_rule_content)
                if file_obj.white_black_valid():
                    file_obj.db_check_and_update(inbound_id)
                else:
                    CLogger().info('文件[{0}]未通过黑白名单检验, 不允许入库! '.format(
                        file_name_with_full_path))
Exemple #2
0
    def list_item_match(self, data_sample_list, keyword_value, fuzzy_matching):
        """
        根据给定列表和关键字和匹配选项, 对列表是否包含关键字进行完全匹配或模糊匹配
        :param data_sample_list:
        :param keyword_value:
        :param fuzzy_matching:
        :return:
        """
        keyword_text = CUtils.any_2_str(keyword_value).lower()
        if fuzzy_matching:
            for data_sample in data_sample_list:
                data_sample_text = CUtils.any_2_str(data_sample).lower()
                if data_sample_text.find(keyword_text) > -1:
                    return True
        else:
            if CUtils.list_count(data_sample_list, keyword_value) > 0:
                return True

        return False
Exemple #3
0
    def __a_check_value_not_in_list__(cls, result_template: dict, value,
                                      title_prefix, value_list: list):
        """
        根据规则, 验证值的合法性
        注意: 值有可能为None!
        完成 负责人 赵宇飞 这里对值在列表中存在性检验
        :param result_template: 检查结果的模板
        :param value: 待检验的值, 可能为None
        :param title_prefix: 提示文本的前缀
        :param value_list: 检查value的必须存在于指定的列表
        :return:
        """
        result_dict = copy.deepcopy(result_template)
        if CUtils.list_count(value_list, value) == 0:
            result_dict[cls.Name_Message] = '{0}的值在不指定列表中, 符合要求!'.format(
                title_prefix)
            result_dict[cls.Name_Result] = cls.QA_Result_Pass
        else:
            result_dict[
                cls.Name_Message] = '{0}的值[{1}], 在指定列表中, 请检查修正!'.format(
                    title_prefix, value)

        return result_dict