def add_file_to_detail_list(self, match_name): """ 设定国土行业数据国情的附属文件的验证规则(镶嵌影像) 完成 负责人 王学谦 在这里检验国情的附属文件 :return: """ file_main_name = self._object_name file_path = self.file_info.file_path # 正则匹配附属文件 if not CUtils.equal_ignore_case(file_path, ''): match_str = '{0}*.*'.format(match_name) match_file_list = CFile.file_or_dir_fullname_of_path( file_path, False, match_str, CFile.MatchType_Common) match_str_main_name = r'(?i)^{0}[FMP]$'.format(match_name) # 主附属 ext_list = [ 'rar', 'zip', 'doc', 'docx', 'xls', 'xlsx', 'txt', 'xml' ] for file_with_path in match_file_list: if CUtils.equal_ignore_case( CFile.file_main_name(file_with_path), file_main_name): # 去除自身与同名文件 pass elif CUtils.text_match_re(CFile.file_main_name(file_with_path), match_str_main_name): self.add_file_to_details(file_with_path) # 将文件加入到附属文件列表中 elif CFile.file_ext(file_with_path).lower() in ext_list: self.add_file_to_details(file_with_path) else: pass
def __init__(self, file_type, file_name_with_full_path): self.__file_name_with_full_path = file_name_with_full_path self.__file_name_without_path = CFile.file_name( self.file_name_with_full_path) self.__file_main_name = CFile.file_main_name( self.file_name_with_full_path) self.__file_ext = CFile.file_ext(self.file_name_with_full_path) self.__file_path = CFile.file_path(self.file_name_with_full_path) self.__file_main_name_with_full_path = CFile.join_file( self.file_path, self.file_main_name) self.__file_type = file_type self.__file_existed = CFile.file_or_path_exist( self.file_name_with_full_path) if self.__file_existed: if CFile.is_file(self.file_name_with_full_path): self.__file_size = CFile.file_size( self.file_name_with_full_path) self.__file_create_time = CFile.file_create_time( self.file_name_with_full_path) self.__file_access_time = CFile.file_access_time( self.file_name_with_full_path) self.__file_modify_time = CFile.file_modify_time( self.file_name_with_full_path)
def add_file_to_detail_list(self, match_name): """ 设定国土行业数据三调的附属文件的验证规则(镶嵌影像) 完成 负责人 王学谦 在这里检验三调的附属文件 :return: """ file_main_name = self._object_name file_path = self.file_info.file_path # 模糊匹配附属文件 if not CUtils.equal_ignore_case(file_path, ''): match_str = '{0}*xq.*'.format(match_name) match_file_list = CFile.file_or_dir_fullname_of_path( file_path, False, match_str, CFile.MatchType_Common) for file_with_path in match_file_list: if not CUtils.equal_ignore_case( CFile.file_main_name(file_with_path), file_main_name): # 去除自身与同名文件 self.add_file_to_details(file_with_path) # 将文件加入到附属文件列表中 try: db = CFactory().give_me_db(self.file_info.db_server_id) metadata_name_before_six_name = db.one_row("select gdstitle from ro_global_dim_space " "where gdsid = '{0}'".format(match_name)) \ .value_by_name(0, 'gdstitle', None) metadata_file_name = '{0}{1}.mdb'.format( match_name, metadata_name_before_six_name) metadata_file_name_with_path = CFile.join_file( file_path, metadata_file_name) if CFile.file_or_path_exist(metadata_file_name_with_path): self.add_file_to_details(metadata_file_name_with_path) except: pass
def register_dm_modules(self): sql_register_dm_metadata_modules_clear = ''' truncate table dm2_modules cascade ''' sql_register_dm_metadata_modules = ''' insert into dm2_modules(dmid, dmtitle) values (:dmid, :dmtitle) ''' CFactory().give_me_db().execute(sql_register_dm_metadata_modules_clear) modules_root_dir = CSys.get_metadata_data_access_modules_root_dir() module_file_name_list = CFile.file_or_subpath_of_path( modules_root_dir, '*.{0}'.format(self.FileExt_Py)) for module_file_name in module_file_name_list: if CFile.is_file( CFile.join_file(modules_root_dir, module_file_name)) and ( not (str(module_file_name)).startswith('_')): module_name = CFile.file_main_name(module_file_name) module_obj = CObject.create_module_instance( CSys.get_metadata_data_access_modules_root_name(), module_name, CResource.DB_Server_ID_Default) module_info = module_obj.information() CFactory().give_me_db().execute( sql_register_dm_metadata_modules, { 'dmid': module_name, 'dmtitle': CUtils.dict_value_by_name( module_info, CResource.Name_Title, module_name) })
def search_type(self): """ 检索插件类型 :return: """ listplugin = [] plugins_root_dir = CSys.get_plugins_root_dir() plugins_type_list = CFile.file_or_subpath_of_path(plugins_root_dir) for plugins_type in plugins_type_list: if CFile.is_dir(CFile.join_file( plugins_root_dir, plugins_type)) and ( not (str(plugins_type)).startswith('_')): plugins_root_package_name = '{0}.{1}'.format( CSys.get_plugins_package_root_name(), plugins_type) path = CFile.join_file(CSys.get_plugins_root_dir(), plugins_type) plugins_file_list = CFile.file_or_subpath_of_path( path, '{0}_*.{1}'.format(self.Name_Plugins, self.FileExt_Py)) for file_name_without_path in plugins_file_list: file_main_name = CFile.file_main_name( file_name_without_path) class_classified_obj = CObject.create_plugins_instance( plugins_root_package_name, file_main_name, None) plugins_info = class_classified_obj.get_information() # 获取插件的类型和名字 plugins_info["dsodid"] = '{0}'.format( plugins_type) + CFile.unify_seperator + '{0}'.format( file_main_name) listplugin.append(plugins_info) plugin_path = [] # 遍历listplugin for i in listplugin: file_dict = {} # 获取当前文件工作目录 work_path = CFile.file_abs_path('.') # 拼接通用路径 main_path = work_path + "/imetadata/business/metadata/inbound/plugins/" # 分割插件类型和名字 list = CUtils.dict_value_by_name(i, "dsodid", '').split(CFile.unify_seperator) # 拼接插件所在路径 file_path = main_path + CUtils.dict_value_by_name( i, "dsodid", '') + "." + self.FileExt_Py # 格式化文件路径 sorted_file_path = CFile.unify(file_path) """ type: dir/file/layer source: 待压缩的文件路径 target: 压缩后路径和名字(根据用户输入的压缩地址,然后拼接出完整的压缩文件) """ file_dict[CResource.Name_Type] = list[0] file_dict.setdefault(CResource.Name_Source, []).append(sorted_file_path) file_dict[CResource.Name_Target] = str( CUtils.dict_value_by_name(i, "dsodtype", '')) + ".zip" print(file_dict) plugin_path.append(file_dict) return plugin_path
def register_dm_metadata_plugins(self): sql_register_dm_metadata_plugins_clear = ''' truncate table dm2_storage_object_def cascade ''' sql_unregister_dm_metadata_plugins = ''' delete from dm2_storage_object_def where dsodid = :dsodid ''' sql_register_dm_metadata_plugins = ''' insert into dm2_storage_object_def( dsodid, dsodtitle, dsodtype, dsodtypetitle, dsodtypecode, dsodgroup, dsodgrouptitle, dsodcatalog, dsodcatalogtitle, dsod_otheroption) values (:dsodid, :dsodtitle, :dsodtype, :dsodtypetitle, :dsodtypecode, :dsodgroup, :dsodgrouptitle, :dsodcatalog, :dsodcatalogtitle, :dsod_otheroption) ''' CFactory().give_me_db().execute(sql_register_dm_metadata_plugins_clear) plugins_root_dir = CSys.get_plugins_root_dir() plugins_type_list = CFile.file_or_subpath_of_path(plugins_root_dir) for plugins_type in plugins_type_list: if CFile.is_dir(CFile.join_file( plugins_root_dir, plugins_type)) and ( not (str(plugins_type)).startswith('_')): plugins_root_package_name = '{0}.{1}'.format( CSys.get_plugins_package_root_name(), plugins_type) path = CFile.join_file(CSys.get_plugins_root_dir(), plugins_type) plugins_file_list = CFile.file_or_subpath_of_path( path, '{0}_*.{1}'.format(self.Name_Plugins, self.FileExt_Py)) for file_name_without_path in plugins_file_list: file_main_name = CFile.file_main_name( file_name_without_path) class_classified_obj = CObject.create_plugins_instance( plugins_root_package_name, file_main_name, None) plugins_info = class_classified_obj.get_information() json_obj = CJson() json_obj.set_value_of_name( self.Name_Is_Spatial, CUtils.dict_value_by_name( plugins_info, CPlugins.Plugins_Info_Is_Spatial, False)) json_obj.set_value_of_name( self.Name_Is_DataSet, CUtils.dict_value_by_name( plugins_info, CPlugins.Plugins_Info_Is_Dataset, False)) plugins_info['dsod_otheroption'] = json_obj.to_json() print('{0}/{1}:{2}'.format(plugins_type, file_main_name, plugins_info)) CFactory().give_me_db().execute( sql_unregister_dm_metadata_plugins, plugins_info) CFactory().give_me_db().execute( sql_register_dm_metadata_plugins, plugins_info)
def __plugins_classified_of_directory__( cls, file_info: CDMFilePathInfoEx) -> CPlugins: """ 使用系统目录下的所有插件进行识别 :param file_info: :return: """ target = file_info.file_main_name target_type = file_info.file_type plugins_root_package_name = '{0}.{1}'.format( CSys.get_plugins_package_root_name(), target_type) path = CFile.join_file(CSys.get_plugins_root_dir(), target_type) plugins_file_list = CFile.file_or_subpath_of_path( path, '{0}_*.{1}'.format(cls.Name_Plugins, cls.FileExt_Py)) for file_name_without_path in plugins_file_list: file_main_name = CFile.file_main_name(file_name_without_path) try: class_classified_obj = CObject.create_plugins_instance( plugins_root_package_name, file_main_name, file_info) obj_info = class_classified_obj.get_information() # 王西亚 添加逻辑于2021-02-12, 解决项目插件调试不方便的问题 obj_classified_valid = False obj_owner_project_id = CUtils.dict_value_by_name( obj_info, CPlugins.Plugins_Info_Project_ID, None) system_project_id = settings.application.xpath_one( cls.Path_Setting_Project_ID, None) if obj_owner_project_id is None: obj_classified_valid = True else: obj_classified_valid = CUtils.equal_ignore_case( obj_owner_project_id, system_project_id) if obj_classified_valid: object_confirm, object_name = class_classified_obj.classified( ) if object_confirm != cls.Object_Confirm_IUnKnown: obj_id = class_classified_obj.get_id() CLogger().debug('{0} is classified as {1}.{2}'.format( target, obj_info, obj_id)) return class_classified_obj except Exception as error: CLogger().debug('插件[{0}]解析出现异常, 错误信息为: [{1}], 请检查!'.format( file_main_name, error.__str__())) if settings.application.xpath_one( '{0}.{1}'.format(cls.Name_Application, cls.Name_Debug), cls.DB_False) == cls.DB_True: raise else: continue else: return None
def is_raster_file_integrity(cls, raster_file_with_path: str) -> bool: """ 判断影像数据的文件完整性,img xxx.img 文件 栅格数据可读 错误 xxx.ige 文件 img小于1M时必须存在 警告 @param raster_file_with_path: @return: """ file_ext = CFile.file_ext(raster_file_with_path) if file_ext.lower() == 'img': size = CFile.file_size(raster_file_with_path) if size < 1024 * 1024: file_main_name = CFile.file_main_name(raster_file_with_path) file_path = CFile.file_path(raster_file_with_path) ige = CFile.join_file(file_path, file_main_name + '.ige') if not CFile.file_or_path_exist(ige): return False return True
def create_job_instance(cls, package_directory, package_root_name, package_subdir, package_name, *args, **kwargs): package_root = os.path.join(package_directory, package_subdir) dir_list = os.listdir(package_root) for cur_file in dir_list: if not CUtils.equal_ignore_case(CFile.file_main_name(cur_file), package_name): continue path = os.path.join(package_root, cur_file) if os.path.isfile(path) and (not cur_file.startswith('__init__')): package_root_name = '{0}.{1}.{2}'.format(package_root_name, package_subdir, package_name) package_obj = importlib.import_module(package_root_name) class_meta = getattr(package_obj, package_name) class_meta_one = class_meta obj_id = args[0] obj_params = args[1] obj = class_meta_one(obj_id, obj_params) return obj else: raise BusinessNotExistException(package_subdir, package_name)
def add_file_to_detail_list(self): """ 设定国土行业数据mosaic的附属文件的验证规则(镶嵌影像) 完成 负责人 李宪 在这里检验mosaic的附属文件的识别规则 :return: """ file_detail_xml = '{0}.xml'.format( self.file_info.file_main_name_with_full_path[:-2]) self.add_file_to_details(file_detail_xml) # 将文件加入到附属文件列表中 file_detail_mbtiles = '{0}_*.mbtiles'.format( self.file_info.file_main_name[:-2]) if not CUtils.equal_ignore_case(self.file_info.file_path, ''): list_file_fullname_xq = CFile.file_or_dir_fullname_of_path( self.file_info.file_path, False, file_detail_mbtiles, CFile.MatchType_Common) # 模糊匹配文件列表 for list_file_fullname in list_file_fullname_xq: if not CUtils.equal_ignore_case( CFile.file_main_name(list_file_fullname), self.file_info.file_main_name): self.add_file_to_details( list_file_fullname) # 将文件加入到附属文件列表中
def execute(self) -> str: inbound_ib_n_list = CFactory().give_me_db( self.get_mission_db_id()).all_row(''' select dsiid as query_ib_id , dsiotheroption as query_ib_option , dsidirectory as query_ib_relation_dir , dsidirectoryid as query_ib_dir_id , dsitargetstorageid as query_ib_target_storage_id from dm2_storage_inbound where dsi_na_status = {0} '''.format(self.ProcStatus_WaitConfirm)) if inbound_ib_n_list.is_empty(): return CResult.merge_result(CResult.Success, '本次没有需要检查的通知任务!') for data_index in range(inbound_ib_n_list.size()): ds_ib_id = inbound_ib_n_list.value_by_name(data_index, 'query_ib_id', '') ds_ib_option = CUtils.any_2_str( inbound_ib_n_list.value_by_name(data_index, 'query_ib_option', '')) ds_ib_directory_name = inbound_ib_n_list.value_by_name( data_index, 'query_ib_relation_dir', '') ds_ib_directory_id = inbound_ib_n_list.value_by_name( data_index, 'query_ib_dir_id', '') ds_ib_target_storage_id = inbound_ib_n_list.value_by_name( data_index, 'query_ib_target_storage_id', '') module_name_list = CJson.json_attr_value( ds_ib_option, self.Path_IB_Opt_Notify_module, None) if module_name_list is None: modules_root_dir = CSys.get_metadata_data_access_modules_root_dir( ) module_file_list = CFile.file_or_subpath_of_path( modules_root_dir, '{0}_*.{1}'.format(self.Name_Module, self.FileExt_Py)) module_name_list = list() for module_file in module_file_list: module_name_list.append(CFile.file_main_name(module_file)) CLogger().debug('正在检查入库批次[ds_ib_id]的通知进度...'.format(ds_ib_id)) try: # 所有通知对象的统计数 sql_record_total_count = CUtils.replace_placeholder( ''' select count(*) from dm2_storage_obj_na where dson_app_id in ($module_name_list) and dson_object_id in ( select dsoid from dm2_storage_object where dso_ib_id = :ib_id ) ''', { 'module_name_list': CUtils.list_2_str(module_name_list, "'", ',', "'") }) record_total_count = CFactory().give_me_db( self.get_mission_db_id()).one_value( sql_record_total_count, {'ib_id': ds_ib_id}, 0) if record_total_count == 0: self.update_inbound_na_result( ds_ib_id, CResult.merge_result( self.Failure, '入库任务下没有可通知的数据, 请检查异常情况! '.format(ds_ib_id))) continue # 已经完成的通知对象的统计数, 包括正常完成和错误的 sql_record_finished_count = CUtils.replace_placeholder( ''' select count(*) from dm2_storage_obj_na where dson_notify_status in ({0}, {1}) and dson_app_id in ($module_name_list) and dson_object_id in ( select dsoid from dm2_storage_object where dso_ib_id = :ib_id ) '''.format(self.ProcStatus_Finished, self.ProcStatus_Error), { 'module_name_list': CUtils.list_2_str(module_name_list, "'", ',', "'") }) record_finished_count = CFactory().give_me_db( self.get_mission_db_id()).one_value( sql_record_finished_count, {'ib_id': ds_ib_id}, 0) # 错误的记录数 sql_record_error_count = CUtils.replace_placeholder( ''' select count(*) from dm2_storage_obj_na where dson_notify_status = {0} and dson_app_id in ($module_name_list) and dson_object_id in ( select dsoid from dm2_storage_object where dso_ib_id = :ib_id ) '''.format(self.ProcStatus_Error), { 'module_name_list': CUtils.list_2_str(module_name_list, "'", ',', "'") }) record_error_count = CFactory().give_me_db( self.get_mission_db_id()).one_value( sql_record_error_count, {'ib_id': ds_ib_id}, 0) if record_total_count != record_finished_count: message = '入库任务[{0}]下的数据正在通知其他子系统, 共有[{1}]个, 已处理[{2}]个, 失败[{3}]个...'.format( ds_ib_id, record_total_count, record_finished_count, record_error_count) CLogger().debug(message) self.update_inbound_na_progress( ds_ib_id, CResult.merge_result(self.Failure, message)) else: message = '入库任务[{0}]下的数据已经通知其他子系统, 共有[{1}]个, 已处理[{2}]个, 失败[{3}]个, 请检查修正! '.format( ds_ib_id, record_total_count, record_finished_count, record_error_count) CLogger().debug(message) self.update_inbound_na_result( ds_ib_id, CResult.merge_result(self.Success, message)) except Exception as error: self.update_inbound_na_result( ds_ib_id, CResult.merge_result( self.Failure, '入库任务下的数据通知其他子系统过程中出现异常情况, 详细错误信息为: [{1}]'.format( ds_ib_id, error.__str__()))) continue return CResult.merge_result(self.Success, '本次通知监控任务成功结束!')
os.makedirs(input_file_path) except OSError as error: print(u"{'result': 0, 'message': '目录%s无法创建!'}" % input_file_path) return f = open(file_name, 'w') f.write(text) f.close() def process_bus(input_filename, output_filename, result_filename): try: CResult.to_file(CRasterMDReader(input_filename).get_metadata_2_file(output_filename), result_filename) except Exception as error: write_output_file(u"{'result': 0, 'message': '算法计算过程出现错误!'}", result_filename) if __name__ == "__main__": parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-i', '--input_filename', required=True, help='输入文件', dest='input_filename') parser.add_argument('-rf', '--result_filename', required=True, help='输入文件', dest='result_filename') parser.add_argument('-o', '--output_filename', required=True, help='输出文件', dest='output_filename') args = parser.parse_args() application_dir = CFile.file_path(CFile.file_abs_path(__file__)) application_name = CFile.file_main_name(application_dir) settings.application.set_app_information(application_dir, application_name) process_bus(args.input_filename, args.output_filename, args.result_filename)
def process_mission(self, dataset) -> str: """ :param dataset: :return: """ ds_storage_id = dataset.value_by_name(0, 'query_storage_id', '') ds_storage_title = dataset.value_by_name(0, 'query_storage_title', '') ds_ib_id = dataset.value_by_name(0, 'query_ib_id', '') ds_ib_directory_name = dataset.value_by_name(0, 'query_ib_relation_dir', '') ds_ib_batch_no = dataset.value_by_name(0, 'query_ib_batchno', '') ds_ib_option = CUtils.any_2_str( dataset.value_by_name(0, 'query_ib_option', '')) CLogger().debug('与第三方模块同步的目录为: {0}.{1}'.format(ds_ib_id, ds_ib_directory_name)) data_count = 0 try: module_name_list = CJson.json_attr_value( ds_ib_option, self.Path_IB_Opt_Notify_module, None) if module_name_list is None: modules_root_dir = CSys.get_metadata_data_access_modules_root_dir( ) module_file_list = CFile.file_or_subpath_of_path( modules_root_dir, '{0}_*.{1}'.format(self.Name_Module, self.FileExt_Py)) module_name_list = list() for module_file in module_file_list: module_name_list.append(CFile.file_main_name(module_file)) sql_ib_need_notify_object = ''' select dsoid, dsoobjecttype, dsoobjectname, dso_da_result from dm2_storage_object where dso_ib_id = :ib_id ''' dataset = CFactory().give_me_db(self.get_mission_db_id()).all_row( sql_ib_need_notify_object, {'ib_id': ds_ib_id}) if dataset.is_empty(): result = CResult.merge_result( self.Success, '存储[{0}]下, 批次为[{1}]的目录[{2}]下无任何对象, 不再通知给第三方应用!'.format( ds_storage_title, ds_ib_batch_no, ds_ib_directory_name)) self.update_notify_result(ds_ib_id, result) return result CLogger().debug( '存储[{0}]下, 批次为[{1}]的目录[{2}]下有[{3}]个对象等待通知给第三方应用!'.format( ds_storage_title, ds_ib_batch_no, ds_ib_directory_name, dataset.size())) data_count = dataset.size() error_message = '' for data_index in range(data_count): record_object = dataset.record(data_index) object_id = CUtils.dict_value_by_name(record_object, 'dsoid', '') object_type = CUtils.dict_value_by_name( record_object, 'dsoobjecttype', '') object_name = CUtils.dict_value_by_name( record_object, 'dsoobjectname', '') object_da_result_text = CUtils.any_2_str( CUtils.dict_value_by_name(record_object, 'dso_da_result', '')) object_da_result = CJson() object_da_result.load_json_text(object_da_result_text) for module_name in module_name_list: module_obj = CObject.create_module_instance( CSys.get_metadata_data_access_modules_root_name(), module_name, self.get_mission_db_id()) module_id = module_name module_title = CUtils.dict_value_by_name( module_obj.information(), self.Name_Title, '') module_enable = CUtils.dict_value_by_name( module_obj.information(), self.Name_Enable, True) if not module_enable: continue module_access = object_da_result.xpath_one( '{0}.{1}'.format(module_id, self.Name_Result), self.DataAccess_Forbid) module_access_memo = object_da_result.xpath_one( '{0}.{1}'.format(module_id, self.Name_Message), '') CLogger().debug( '存储[{0}]下, 批次为[{1}]的目录[{2}]下的对象[{3}], 与模块[{4}]的访问权限为[{5}]!' .format(ds_storage_title, ds_ib_batch_no, ds_ib_directory_name, object_name, module_title, module_access)) # todo(王西亚) 仔细考虑这里是否要放开, 是放开pass的, 还是放开pass和wait!!!!!! # if not \ # ( # CUtils.equal_ignore_case(module_access, self.DataAccess_Pass) # or CUtils.equal_ignore_case(module_access, self.DataAccess_Wait) # ): # continue result = module_obj.notify_object(ds_ib_id, module_access, module_access_memo, object_id, object_name, object_type, None) if not CResult.result_success(result): message = CResult.result_message(result) CLogger().debug( '存储[{0}]下, 批次为[{1}]的目录[{2}]下的对象[{3}], 与模块[{4}]的通知处理结果出现错误, 详细情况: [{5}]!' .format(ds_storage_title, ds_ib_batch_no, ds_ib_directory_name, object_name, module_title, message)) error_message = CUtils.str_append( error_message, message) if CUtils.equal_ignore_case(error_message, ''): result = CResult.merge_result( self.Success, '存储[{0}]下, 批次为[{1}]的目录[{2}]下有[{3}]个对象成功通知给第三方应用!'.format( ds_storage_title, ds_ib_batch_no, ds_ib_directory_name, data_count)) self.update_notify_result(ds_ib_id, result) return result else: result = CResult.merge_result( self.Failure, '存储[{0}]下, 批次为[{1}]的目录[{2}]下有[{3}]个对象在通知给第三方应用时, 部分出现错误! 错误信息如下: \n{4}' .format(ds_storage_title, ds_ib_batch_no, ds_ib_directory_name, data_count, error_message)) self.update_notify_result(ds_ib_id, result) return result except Exception as error: result = CResult.merge_result( self.Failure, '存储[{0}]下, 批次为[{1}]的目录[{2}]下有[{3}]个对象通知给第三方应用时出现异常! 错误原因为: {4}!' .format(ds_storage_title, ds_ib_batch_no, ds_ib_directory_name, data_count, error.__str__())) self.update_notify_result(ds_ib_id, result) return result
def process_mission(self, dataset): dso_id = dataset.value_by_name(0, 'dsoid', '') dso_data_type = dataset.value_by_name(0, 'dsodatatype', '') dso_object_type = dataset.value_by_name(0, 'dsoobjecttype', '') dso_object_name = dataset.value_by_name(0, 'dsoobjectname', '') dso_object_da_content = CUtils.any_2_str(dataset.value_by_name(0, 'dso_da_result', '')) dso_object_quality = dataset.value_by_name(0, 'dso_quality', '') ds_retry_times = dataset.value_by_name(0, 'retry_times', 0) if ds_retry_times >= self.abnormal_job_retry_times(): ds_last_process_memo = CUtils.any_2_str(dataset.value_by_name(0, 'last_process_memo', None)) process_result = CResult.merge_result( self.Failure, '{0}, \n系统已经重试{1}次, 仍然未能解决, 请人工检查修正后重试!'.format( ds_last_process_memo, ds_retry_times ) ) self.update_status(dso_id, None, process_result, self.ProcStatus_Error) return process_result dso_quality = CXml() dso_quality.load_xml(dso_object_quality) dso_da_json = CJson() dso_da_json.load_json_text(dso_object_da_content) CLogger().debug( '开始处理对象: {0}.{1}.{2}.{3}对各个子系统的支撑能力'.format(dso_id, dso_data_type, dso_object_type, dso_object_name)) try: modules_root_dir = CSys.get_metadata_data_access_modules_root_dir() modules_file_list = CFile.file_or_subpath_of_path( modules_root_dir, '{0}_*.{1}'.format(self.Name_Module, self.FileExt_Py) ) for file_name_without_path in modules_file_list: file_main_name = CFile.file_main_name(file_name_without_path) # 判断模块的可访问是否已经被人工审批, 如果人工审批, 则这里不再计算和覆盖 module_access = dso_da_json.xpath_one( '{0}.{1}'.format(file_main_name, self.Name_Audit), self.Name_System ) if CUtils.equal_ignore_case(module_access, self.Name_User): continue try: module_obj = CObject.create_module_instance( CSys.get_metadata_data_access_modules_root_name(), file_main_name, self.get_mission_db_id() ) module_title = CUtils.dict_value_by_name(module_obj.information(), self.Name_Title, '') result = CUtils.any_2_str(module_obj.access(dso_id, dso_object_name, dso_data_type, dso_quality) ) if CResult.result_success(result): module_access = CResult.result_info(result, self.Name_Access, self.DataAccess_Forbid) else: CLogger().debug('模块[{0}]解析出现错误, 系统将忽略本模块, 继续处理下一个!'.format(file_main_name)) module_access = self.DataAccess_Unknown module_access_message = CResult.result_message(result) module_obj = {self.Name_Audit: self.Name_System, self.Name_Result: module_access, self.Name_Title: module_title, self.Name_Message: module_access_message} dso_da_json.set_value_of_name(file_main_name, module_obj) except Exception as error: CLogger().debug('模块[{0}]解析出现异常, 原因为[{1}], 请检查!'.format(file_main_name, error.__str__())) module_access = self.DataAccess_Unknown module_access_message = '模块[{0}]解析出现异常, 原因为[{1}], 请检查!'.format(file_main_name, error.__str__()) module_obj = {self.Name_Audit: self.Name_System, self.Name_Result: module_access, self.Name_Title: file_main_name, self.Name_Message: module_access_message} dso_da_json.set_value_of_name(file_main_name, module_obj) process_result = CResult.merge_result( self.Success, '对象[{0}.{1}]访问权限解析成功!'.format(dso_id, dso_object_name) ) self.update_status( dso_id, dso_da_json.to_json(), process_result ) return process_result except Exception as error: process_result = CResult.merge_result( self.Failure, '对象[{0}.{1}]访问权限解析出错, 原因为[{2}]!'.format(dso_id, dso_object_name, error.__str__()) ) self.update_status(dso_id, None, process_result) return process_result
def init_metadata_bus(self, parser: CMetaDataParser) -> str: """ 通过相应信息转换xml """ xml_obj = CXml() # 建立xml对象 node_root = xml_obj.new_xml('root') node_item1 = xml_obj.create_element(node_root, 'item') xml_obj.set_attr(node_item1, self.Name_Name, 'ProductName') xml_obj.set_element_text(node_item1, parser.file_info.file_main_name) # 设置item节点与属性与内容 pathdata_list = re.findall( r'(?i)^.+' r'[-_/]?([1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1]))[-_/]?' r'.+' r'[\\\\/]影像', parser.file_info.file_path ) if len(pathdata_list) > 0: pathdata = CUtils.any_2_str(pathdata_list[0]) else: pathdata = '' node_item2 = xml_obj.create_element(node_root, 'item') xml_obj.set_attr(node_item2, self.Name_Name, 'DataDate') xml_obj.set_element_text(node_item2, pathdata) # 设置item节点与属性与内容 # 影像元数据dsometadatajson.pixelsize.width节点 # width < 0.01时,resolution = width * 110000, # width > 0.01时,resolution = width pixelsize_value = parser.metadata.metadata_json().xpath_one('pixelsize.width', None) if pixelsize_value is not None: pixelsize_num = CUtils.to_decimal(pixelsize_value, None) if pixelsize_num is not None: if CUtils.to_decimal(pixelsize_value, 0) < 0.01: pixelsize_value = pixelsize_num * 110000 else: pixelsize_value = '' else: pixelsize_value = '' pixelsize_value = CUtils.any_2_str(pixelsize_value) if len(pixelsize_value) > 10: pixelsize_value = pixelsize_value[:10] node_item3 = xml_obj.create_element(node_root, 'item') xml_obj.set_attr(node_item3, self.Name_Name, 'Resolution') xml_obj.set_element_text(node_item3, pixelsize_value) # 设置item节点与属性与内容 SatelliteID_list = re.findall( r'(?i)^.+' r'[-_/]?[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])[-_/]?' r'(.+)' r'[\\\\/]影像', parser.file_info.file_path ) if len(SatelliteID_list) > 0: SatelliteID = CUtils.any_2_str(SatelliteID_list[0][2]) else: SatelliteID = '' node_item4 = xml_obj.create_element(node_root, 'item') xml_obj.set_attr(node_item4, self.Name_Name, 'SatelliteID') xml_obj.set_element_text(node_item4, SatelliteID) # 设置item节点与属性与内容 GeographicName_list = re.findall( r'(?i)^(.+)' r'[-_/]?[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])[-_/]?' r'.+' r'[\\\\/]影像', parser.file_info.file_path ) if len(GeographicName_list) > 0: GeographicName = CUtils.any_2_str(GeographicName_list[0]) if CUtils.text_match_re(GeographicName, '[-_/]$'): GeographicName = GeographicName[:-1] GeographicName = CFile.file_main_name(GeographicName) else: GeographicName = '' node_item5 = xml_obj.create_element(node_root, 'item') xml_obj.set_attr(node_item5, self.Name_Name, 'GeographicName') xml_obj.set_element_text(node_item5, GeographicName) # 设置item节点与属性与内容 node_item6 = xml_obj.create_element(node_root, 'item') xml_obj.set_attr(node_item6, self.Name_Name, 'Description') xml_obj.set_element_text(node_item6, '') # 设置item节点与属性与内容 try: if xml_obj is not None: parser.metadata.set_metadata_bus( self.Success, '元数据文件成功构建! ', self.MetaDataFormat_XML, xml_obj.to_xml() ) return CResult.merge_result( self.Success, '元数据文件成功构建! ' ) else: raise except Exception as error: parser.metadata.set_metadata_bus( self.Exception, '构建元数据文件失败, 无法处理! 错误原因为{0}'.format(error.__str__()), self.MetaDataFormat_Text, '' ) return CResult.merge_result( self.Exception, '构建元数据文件失败, 无法处理! 错误原因为{0}'.format(error.__str__()) )