def create_new(self, ds_info): if not self.check_existing_id(ds_info.id): return False # set paths dir_path = path.join(extra_sources.USER_DIR_PATH, extra_sources.DATA_SOURCES_DIR_NAME, ds_info.id) if path.exists(dir_path): salt = 0 while path.exists(dir_path + str(salt)): salt += 1 dir_path += str(salt) ini_path = path.join(dir_path, 'metadata.ini') ico_path = path.join(dir_path, ds_info.icon) # create dir os.mkdir(dir_path) # copy icon shutil.copy(ds_info.icon_path, ico_path) if ds_info.type == KNOWN_DRIVERS.GDAL: # copy gdal file gdal_file_name = path.basename(ds_info.gdal_source_file) gdal_file_path = path.join(dir_path, gdal_file_name) shutil.copy(ds_info.gdal_source_file, gdal_file_path) # write config DataSourceSerializer.write_to_ini(ds_info, ini_path) return True
def _fill_data_sources_list(self): self.data_sources = {} for ds_path in self.ds_paths: for root, dirs, files in os.walk(ds_path): for ini_file in [f for f in files if f.endswith('.ini')]: try: ini_full_path = os.path.join(root, ini_file) ds = DataSourceSerializer.read_from_ini(ini_full_path) # set contrib&user if ds_path in ROOT_MAPPING.keys(): ds.category = ROOT_MAPPING[ds_path] else: ds.category = DataSourceCategory.USER # action ds.action = QAction(QIcon(ds.icon_path), self.tr(ds.alias), None) ds.action.setData(ds) # append to array self.data_sources[ds.id] = ds except Exception, e: error_message = 'INI file can\'t be parsed: ' + e.message QgsMessageLog.logMessage(error_message, level=QgsMessageLog.CRITICAL)
def result_selected(self, current=None, previous=None): if current: try: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) geoservice = current.data(Qt.UserRole) geoservice_info = Client().get_geoservice_info(geoservice) ds = DataSourceSerializer.read_from_json(geoservice_info) add_layer_to_map(ds) except Exception as ex: pass finally: QApplication.restoreOverrideCursor()
def save_existing(self, ds_info): if ds_info.id != self.ds_info.id and not self.check_existing_id( ds_info.id): return False if ds_info == self.ds_info: return True # replace icon if need if not is_same(ds_info.icon_path, self.ds_info.icon_path): os.remove(self.ds_info.icon_path) dir_path = os.path.dirname(self.ds_info.file_path) ico_file_name = path.basename(ds_info.icon_path) ico_path = path.join(dir_path, ico_file_name) shutil.copy(ds_info.icon_path, ico_path) # replace gdal_conf if need if ds_info.type == KNOWN_DRIVERS.GDAL: def copy_new_gdal_file(): dir_path = os.path.dirname(self.ds_info.file_path) gdal_file_name = path.basename(ds_info.gdal_source_file) gdal_file_path = path.join(dir_path, gdal_file_name) shutil.copy(ds_info.gdal_source_file, gdal_file_path) # old ds = gdal if self.ds_info.type == KNOWN_DRIVERS.GDAL: if ds_info.gdal_source_file != self.ds_info.gdal_source_file: os.remove(self.ds_info.icon_path) copy_new_gdal_file() else: copy_new_gdal_file() # write config DataSourceSerializer.write_to_ini(ds_info, self.ds_info.file_path) return True
def save_existing(self, ds_info): if ds_info.id != self.ds_info.id and not self.check_existing_id(ds_info.id): return False if ds_info == self.ds_info: return True # replace icon if need if not is_same(ds_info.icon_path, self.ds_info.icon_path): os.remove(self.ds_info.icon_path) dir_path = os.path.dirname(self.ds_info.file_path) ico_file_name = path.basename(ds_info.icon_path) ico_path = path.join(dir_path, ico_file_name) shutil.copy(ds_info.icon_path, ico_path) # replace gdal_conf if need if ds_info.type == KNOWN_DRIVERS.GDAL: def copy_new_gdal_file(): dir_path = os.path.dirname(self.ds_info.file_path) gdal_file_name = path.basename(ds_info.gdal_source_file) gdal_file_path = path.join(dir_path, gdal_file_name) shutil.copy(ds_info.gdal_source_file, gdal_file_path) # old ds = gdal if self.ds_info.type == KNOWN_DRIVERS.GDAL: if ds_info.gdal_source_file != self.ds_info.gdal_source_file: os.remove(self.ds_info.icon_path) copy_new_gdal_file() else: copy_new_gdal_file() # write config DataSourceSerializer.write_to_ini(ds_info, self.ds_info.file_path) return True