GSSHAPY Project Write WMS Datasets to File Method

def _writeWMSDatasets(self, session, directory, wmsDatasetCards, name=None):
        """
        GSSHAPY Project Write WMS Datasets to File Method
        """
        if self.mapType in self.MAP_TYPES_SUPPORTED:
            for card in self.projectCards:
                if (card.name in wmsDatasetCards) and self._noneOrNumValue(card.value):
                    filename = card.value.strip('"')

                    # Determine new filename
                    filename = self._replaceNewFilename(filename, name)

                    # Handle case where fileIO interfaces with multiple files
                    # Retrieve File using FileIO and file extension
                    extension = filename.split('.')[1]

                    # Get mask map file
                    maskMap = session.query(RasterMapFile).\
                        filter(RasterMapFile.projectFile == self).\
                        filter(RasterMapFile.fileExtension == 'msk').\
                        one()

                    # Default wms dataset
                    wmsDataset = None

                    try:
                        wmsDataset = session.query(WMSDatasetFile). \
                            filter(WMSDatasetFile.projectFile == self). \
                            filter(WMSDatasetFile.fileExtension == extension). \
                            one()

                    except NoResultFound:
                        # Handle case when there is no file in database but
                        # the card is listed in the project file
                        log.warning('{0} listed as card in project file, '
                                 'but the file is not found in the database.'.format(filename))

                    except MultipleResultsFound:
                        # Write all instances
                        self._invokeWriteForMultipleOfType(directory, extension,
                                                           WMSDatasetFile, filename,
                                                           session, maskMap=maskMap)
                        return

                    # Initiate Write Method on File
                    if wmsDataset is not None and maskMap is not None:
                        wmsDataset.write(session=session, directory=directory,
                                         name=filename, maskMap=maskMap)
        else:
            log.error('Could not write WMS Dataset files. '
                      'MAP_TYPE {0} not supported.'.format(self.mapType))