def process_metadata_bus_dict(self): dataset = self._dataset class_plugins = self.get_class_plugins() try: dsometadataxml_xml = CXml() dsometadataxml = dataset.value_by_name(0, 'dsometadataxml_bus', '') dsometadataxml_xml.load_xml(dsometadataxml) view_path = settings.application.xpath_one( self.Path_Setting_MetaData_Dir_View, None) browser_path = CFile.file_path( dataset.value_by_name(0, 'dso_browser', None)) multiple_metadata_bus_filename_dict = \ class_plugins.get_multiple_metadata_bus_filename_with_path( CFile.join_file(view_path, browser_path) ) result, metadata_bus_dict = class_plugins.metadata_bus_xml_to_dict( dsometadataxml_xml, multiple_metadata_bus_filename_dict) self.set_metadata_bus_dict(metadata_bus_dict) return result except Exception as error: return CResult.merge_result( self.Failure, '卫星数据的业务元数据的详细内容解析出错!原因为{0}'.format(error.__str__()))
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 package(output_relation_dir): """ 编译根目录下的包括子目录里的所有py文件成pyc文件到新的文件夹下 :param output_relation_dir: 需编译的目录 :return: """ output_relation_dir = CFile.unify(CUtils.any_2_str(output_relation_dir)) application_dir = CFile.file_path(CFile.file_abs_path(__file__)) output_dir = CFile.file_abs_path(CFile.join_file(application_dir, output_relation_dir)) for each_directory, dir_name_list, file_name_without_path_list in os.walk(application_dir): directory_source = each_directory directory_name = CFile.file_name(directory_source) directory_relation = CFile.file_relation_path(each_directory, application_dir) directory_target = CFile.join_file(output_dir, directory_relation) path_deploy_enable = deploy_match_pattern_list(directory_relation, 'path.white_list', True, True) path_deploy_enable = path_deploy_enable and deploy_match_pattern_list(directory_relation, 'path.black_list', False, True) if path_deploy_enable: directory_deploy_enable = deploy_match_pattern_list(directory_name, 'directory.white_list', True, True) directory_deploy_enable = directory_deploy_enable and deploy_match_pattern_list( directory_name, 'directory.black_list', False, True ) if directory_deploy_enable: for file_name_without_path in file_name_without_path_list: file_deploy_enable = deploy_match_pattern_list( file_name_without_path, 'file.white_list', True, True ) file_deploy_enable = file_deploy_enable and deploy_match_pattern_list( file_name_without_path, 'file.black_list', False, True ) file_name_with_path_source = CFile.join_file(directory_source, file_name_without_path) if file_deploy_enable: file_compile_enable = deploy_match_pattern_list( file_name_without_path, 'compile.file.white_list', True, False ) if file_compile_enable: file_compile_enable = deploy_match_pattern_list( file_name_without_path, 'compile.file.black_list', False, False ) file_name_without_path_target = CFile.change_file_ext(file_name_without_path, 'pyc') file_name_with_path_target = CFile.join_file(directory_target, file_name_without_path_target) CFile.check_and_create_directory_itself(directory_target) if file_compile_enable: py_compile.compile(file_name_with_path_source, cfile=file_name_with_path_target) print('{0}-compile-success'.format(file_name_with_path_source)) else: CFile.copy_file_to(file_name_with_path_source, directory_target) print('{0}-no_compile'.format(file_name_with_path_source))
def blob2file(self, row: int, name: str, file_name: str): if self._data is None: return value = self._value_by_name(row, name) if value is None: return if not CFile.check_and_create_directory(file_name): raise PathNotCreateException(CFile.file_path(file_name)) f = open(file_name, 'wb') try: f.write(value) finally: f.close()
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
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 to_file(self, filename): if not CFile.check_and_create_directory(filename): raise PathNotCreateException(CFile.file_path(filename)) demjson.encode_to_file(filename, self.__json_obj, overwrite=True)
def process_ndi_table(self): object_table_id = self._obj_id # 获取oid metadata_bus_dict = self.get_metadata_bus_dict() ndi_table_name = CUtils.dict_value_by_name(self.information(), 'ndi_table_name', 'ap_product_ndi') ndi_table = CTable() ndi_table.load_info(self._db_id, ndi_table_name) ndi_table.column_list.column_by_name('id').set_value(object_table_id) productname = CUtils.dict_value_by_name(metadata_bus_dict, 'productname', None) if CUtils.equal_ignore_case(productname, ''): productname = self._dataset.value_by_name(0, 'dsoobjectname', None) ndi_table.column_list.column_by_name('rid').set_value(productname) ndi_table.column_list.column_by_name('fid').set_value(object_table_id) ndi_table.column_list.column_by_name('satelliteid').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'satelliteid', None)) ndi_table.column_list.column_by_name('sensorid').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'sensorid', None)) ndi_table.column_list.column_by_name('topleftlatitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'topleftlatitude', None)) ndi_table.column_list.column_by_name('topleftlongitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'topleftlongitude', None)) ndi_table.column_list.column_by_name('toprightlatitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'toprightlatitude', None)) ndi_table.column_list.column_by_name('toprightlongitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'toprightlongitude', None)) ndi_table.column_list.column_by_name('bottomrightlatitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'bottomrightlatitude', None)) ndi_table.column_list.column_by_name('bottomrightlongitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'bottomrightlongitude', None)) ndi_table.column_list.column_by_name('bottomleftlatitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'bottomleftlatitude', None)) ndi_table.column_list.column_by_name('bottomleftlongitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'bottomleftlongitude', None)) ndi_table.column_list.column_by_name('centerlatitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'centerlatitude', None)) ndi_table.column_list.column_by_name('centerlongitude').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'centerlongitude', None)) transformimg = CUtils.dict_value_by_name(metadata_bus_dict, 'transformimg', None) if not CUtils.equal_ignore_case(transformimg, ''): view_path = settings.application.xpath_one( self.Path_Setting_MetaData_Dir_View, None) browser_path = CFile.file_path( self._dataset.value_by_name(0, 'dso_browser', None)) file_list = CFile.file_or_dir_fullname_of_path( CFile.join_file(view_path, browser_path), False, transformimg, CFile.MatchType_Regex) if len(file_list) > 0: ndi_table.column_list.column_by_name('transformimg').set_value( '{0}{1}'.format( CFile.sep(), CFile.join_file(browser_path, CFile.file_name(file_list[0])))) ndi_table.column_list.column_by_name('filesize').set_sql(''' (select sum(dodfilesize) from dm2_storage_obj_detail where dodobjectid='{0}') '''.format(object_table_id)) ndi_table.column_list.column_by_name('dataexist').set_value(0) ndi_table.column_list.column_by_name('centertime').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'centertime', None)) resolution = CUtils.dict_value_by_name(metadata_bus_dict, 'resolution', None) if not CUtils.equal_ignore_case(resolution, ''): ndi_table.column_list.column_by_name('resolution').set_value( resolution) else: ndi_table.column_list.column_by_name('resolution').set_value(0) rollangle = CUtils.dict_value_by_name(metadata_bus_dict, 'rollangle', 0) if CUtils.equal_ignore_case(rollangle, ''): rollangle = 0 ndi_table.column_list.column_by_name('rollangle').set_value(rollangle) cloudpercent = CUtils.dict_value_by_name(metadata_bus_dict, 'cloudpercent', 0) if CUtils.equal_ignore_case(cloudpercent, ''): cloudpercent = 0 ndi_table.column_list.column_by_name('cloudpercent').set_value( cloudpercent) ndi_table.column_list.column_by_name('dataum').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'dataum', None)) ndi_table.column_list.column_by_name('acquisition_id').set_value( CUtils.dict_value_by_name(metadata_bus_dict, 'acquisition_id', None)) result = ndi_table.save_data() return result
def __init__(self, target_name): super().__init__(target_name) self.__virtual_content_root_dir__ = CFile.file_path( self.__target_name__)