def csv_info(self, csv_file=None, curr_file=None): """ 功能: 将csv文件转为列表 :param csv_file: csv文件 :param curr_file: 默认填写__file__ :return: """ if not csv_file: curr_dir = os.path.dirname(curr_file) csv_file_list = FileHelper.get_files_from_folderOrFolderlist( curr_dir, ".csv", recursive=False) if len(csv_file_list) == 1: csv_file = csv_file_list[0] elif len(csv_file_list) == 0: raise exceptions.FileException( "当前目录下不存在csv文件:{}".format(curr_dir)) else: raise exceptions.FileException( "当前目录下存在多个csv文件,请明确指明csv路径,:{}".format(curr_dir)) validator.check_file_isFile(csv_file) info_list = CsvHelper.load_csv_file(csv_file) return info_list
def base_yaml_info(self, yaml_file=None, module_key=None, func_key=None, curr_file=None): """ 功能:先将yaml文件转为字典,再在字典中通过key取value。 :param yaml_file: yaml文件 :param module_key: 字典的key :param curr_file: 默认填写 __file__ :return: """ # TODO(dongjun): module_key 如果只有一个key时,自动读取 if not yaml_file: curr_dir = os.path.dirname(curr_file) yaml_file_list = FileHelper.get_files_from_folderOrFolderlist( curr_dir, ".yaml", recursive=False) if len(yaml_file_list) == 1: yaml_file = yaml_file_list[0] elif len(yaml_file_list) == 0: raise exceptions.FileException( "当前目录下不存在yaml文件:{}".format(curr_dir)) else: raise exceptions.FileException( "当前目录下存在多个yaml文件,请明确指明yaml路径,:{}".format(curr_dir)) if not module_key: module_key = "" validator.check_file_isFile(yaml_file) validator.check_paramType_str(module_key) api_dictInfo = YamlHelper.load_yaml_file(yaml_file) api_info = api_dictInfo.get(module_key) if module_key is "": return api_dictInfo elif api_info: if func_key: api_info = api_info.get(func_key) if api_info: return api_info raise exceptions.DictException( "yaml中func_key不存在。yaml_path:{},目标key:{}".format( yaml_file, func_key)) return api_info else: raise exceptions.DictException( "yaml中module_key不存在。yaml_path:{},目标key:{}".format( yaml_file, module_key))