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 open_source(self) -> CDataSetSeqReader: option_source = CUtils.dict_value_by_name(self.__config, self.Name_Source, None) if option_source is None: raise Exception('数据源未设置, 请检查修正后重试! ') type_source = CUtils.dict_value_by_name(option_source, self.Name_Type, self.Name_Table) if CUtils.equal_ignore_case(type_source, self.Name_ShapeFile): source_data_option = CUtils.dict_value_by_name(option_source, type_source, None) source_data_filename = CUtils.dict_value_by_name(source_data_option, self.Name_Name, None) if CUtils.equal_ignore_case(source_data_filename, ''): raise Exception('[{0}]类型数据源未设置文件名, 请检查修正后重试! '.format(type_source)) if not CFile.file_or_path_exist(source_data_filename): raise Exception('[{0}]类型数据源设置的文件[{1}]不存在, 请检查修正后重试! '.format(type_source, source_data_filename)) cpg_file_name = CFile.change_file_ext(source_data_filename, 'cpg') encoding = CResource.Encoding_GBK if CFile.file_or_path_exist(cpg_file_name): encoding = CFile.file_2_str(cpg_file_name) self.__source_data = CVectorDataSets(source_data_filename) self.__source_data.open(encoding) return self.__source_data.layer_by_index(0) elif CUtils.equal_ignore_case(type_source, self.Name_Vector_DataSet): source_data_option = CUtils.dict_value_by_name(option_source, type_source, None) source_data_filename = CUtils.dict_value_by_name(source_data_option, self.Name_Name, None) source_data_layer = CUtils.dict_value_by_name(source_data_option, self.Name_Layer, None) if CUtils.equal_ignore_case(source_data_filename, ''): raise Exception('[{0}]类型数据源未设置文件名, 请检查修正后重试! '.format(type_source)) if CUtils.equal_ignore_case(source_data_layer, ''): raise Exception('[{0}]类型数据源未设置图层名, 请检查修正后重试! '.format(type_source)) if not CFile.file_or_path_exist(source_data_filename): raise Exception('[{0}]类型数据源设置的文件[{1}]不存在, 请检查修正后重试! '.format(type_source, source_data_filename)) self.__source_data = CVectorDataSets(source_data_filename) self.__source_data.open() layer_data = self.__source_data.layer_by_name(source_data_layer) if layer_data is None: raise Exception('[{0}]类型数据源设置的图层[{1}]不存在, 请检查修正后重试! '.format(type_source, source_data_layer)) return layer_data elif CUtils.equal_ignore_case(type_source, self.Name_Table): source_data_option = CUtils.dict_value_by_name(option_source, type_source, None) source_database = CUtils.dict_value_by_name(source_data_option, self.Name_DataBase, self.DB_Server_ID_Default) source_data_table_name = CUtils.dict_value_by_name(source_data_option, self.Name_Name, None) if CUtils.equal_ignore_case(source_data_table_name, ''): raise Exception('[{0}]类型数据源未设置数据表名, 请检查修正后重试! '.format(self.Name_Table)) data_set = CFactory().give_me_db(source_database).all_row( 'select * from {0}'.format(self.replace_placeholder(source_data_table_name)), self.__params ) self.__source_data = CDBDataSetSeqReader(data_set) return self.__source_data elif CUtils.equal_ignore_case(type_source, self.Name_Table): source_data_option = CUtils.dict_value_by_name(option_source, type_source, None) source_database = CUtils.dict_value_by_name(source_data_option, self.Name_DataBase, self.DB_Server_ID_Default) source_data_sql = CUtils.dict_value_by_name(source_data_option, self.Name_SQL, None) if CUtils.equal_ignore_case(source_data_sql, ''): raise Exception('[{0}]类型数据源未设置查询语句, 请检查修正后重试! '.format(type_source)) data_set = CFactory().give_me_db(source_database).all_row( self.replace_placeholder(source_data_sql), self.__params ) self.__source_data = CDBDataSetSeqReader(data_set) return self.__source_data else: raise Exception('系统不支持类型为[{0}]的数据源, 请检查修正后重试! '.format(type_source))
return False elif CUtils.equal_ignore_case(driver.name, 'PGeo'): if layer_name.upper().endswith('_SHAPE_INDEX'): return False elif CUtils.equal_ignore_case(layer_name, 'Selections'): return False elif CUtils.equal_ignore_case(layer_name, 'SelectedObjects'): return False return True if __name__ == '__main__': file_name = '/Users/wangxiya/Documents/我的测试数据/31.混合存储/测试数据/通用数据/矢量数据集/生态治理和水土保持监测数据库_黑岱沟露天煤矿_10017699_2020d1_2020-01-01.mdb' # file_name = '/Users/wangxiya/Documents/我的测试数据/31.混合存储/测试数据/通用数据/矢量/矢量数据/正确数据/生态治理和水土保持监测数据库_利民煤矿_10017574_2020d1_2020-08-05/取排口.shp' cpg_file_name = CFile.change_file_ext(file_name, 'cpg') encoding = CResource.Encoding_GBK if CFile.file_or_path_exist(cpg_file_name): encoding = CFile.file_2_str(cpg_file_name) vector_datasets = CVectorDataSets(file_name) vector_datasets.open(encoding) for vector_layer_index in range(vector_datasets.size()): vector_dataset = vector_datasets.layer_by_index(vector_layer_index) print('*' * 30) print('{0}-{1}'.format(vector_dataset.dataset_name, vector_dataset.size())) print('*' * 10) for field_index in range(vector_dataset.field_count()): print('{0}.{1}'.format(vector_dataset.dataset_name, vector_dataset.field_name(field_index)))