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
Beispiel #2
0
    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
Beispiel #3
0
    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