def gen_template_moduleCase(self, file_path=None): """ 功能:将模板代码内容写入文件 """ if not file_path: # 初始化默认生成文件的路径 file_path = self.default_filepath_moduleCase validator.check_file_isExist(file_path) FileHelper.create_filepath(filepath=file_path) with open(file_path, 'a', encoding='utf-8') as f: f.write(self._content_module())
def gen_template_scn(self, file_path=None): """ 功能:将模板代码内容写入文件 :param _content: 模板内容 :param file: 默认路径为($PROJECT_ROOT/output/template/scn_api_device.py) :return: """ if not file_path: # 初始化默认生成文件的路径 file_path = self.default_filepath_scn FileHelper.delete_file(filepath=file_path) FileHelper.create_filepath(filepath=file_path) with open(file_path, 'a', encoding='utf-8') as f: f.write(self._content_scn())
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 gen_template_csv(self, file_path=None): """ 功能:将模板代码内容写入文件 :param _content: 模板内容 :param file: 默认路径为($PROJECT_ROOT/output/template/scn_api_device.py) :return: """ if not file_path: # 初始化默认生成文件的路径 file_path = self.default_filepath_csv validator.check_file_isExist(file_path) # TODO: 如果csv内容多于1行, 则不能随意删除 FileHelper.create_filepath(filepath=file_path) with open(file_path, 'a', encoding='utf-8') as f: f.write(self._content_csv())
def get_face_picture(index=None): ''' 功能描述: 当index不填时,随机获取一张 当index指定时,获取指定索引的图片 ''' img_dir = img1_dir return FileHelper.get_file_from_dir(img_dir,file_index=index)
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))