def purge_geoserver(self):
        """
        Remove any configured items in geoserver for the namespace.

        This configuration step prevents conflicts in geowebcache 
        when the datastore and featuretype is reconfigured without 
        discarding the old featuretype.

        @returns: A flag indicating if the configuration was purged successfully.
        """
        # get the workspace 
        ws_cfg = self._read_config('/geoserver/rest/workspaces/%s.json' % self.ns, 'Could not get workspace %s.' % self.ns)
        if ws_cfg is None:
            logger.debug("%s configuration could not be fetched.", self.ns)
            return True

        # get the data stores in the workspace
        wsds_cfg = self._read_config(ws_cfg['workspace']['dataStores'], 'Could not get data stores in workspace %s' % ws_cfg['workspace']['name'])
        if wsds_cfg is None:
            logger.debug("Workspace '%s' datastore configuration could not be fetched.", self.ns)
            return False

        # get the data source configuration
        ds_cfg = self._read_config(wsds_cfg['dataStores']['dataStore'][0]['href'], "Could not get datastore configuration for '%s'" % wsds_cfg['dataStores']['dataStore'][0]['name'])
        if ds_cfg is None:
            logger.debug("Datastore configuration could not be fetched.")
            return False

        # get all the feature types in the data store
        fts_cfg = self._read_config(ds_cfg['dataStore']['featureTypes'] + '?list=all', "Could not get feature types in datastore '%s'" % wsds_cfg['dataStores']['dataStore'][0]['name'])
        if fts_cfg is None:
            logger.debug("Data store '%s' feature type configuration could not be fetched.", wsds_cfg['dataStores']['dataStore'][0]['name'])
            return False

        if not 'featureType' in fts_cfg['featureTypes']: 
            fts_cfg['featureTypes'] = { 'featureType':[] }

        for ft_cfg in fts_cfg['featureTypes']['featureType']:
            # Delete the layer
            if not self._rest_config('DELETE', '/geoserver/rest/layers/%s.json' % ft_cfg['name']):
                logger.debug("Could not delete layer %s", ft_cfg['name'])
                continue

            # Delete the feature type
            if self._rest_config('DELETE', ft_cfg['href']):
                logger.debug("Deleted feature type '%s'", ft_cfg['name'])
            else:
                logger.debug("Could not delete feature type '%s'", ft_cfg['name'])

        # now that the data store is empty, delete it
        if not self._rest_config('DELETE', wsds_cfg['dataStores']['dataStore'][0]['href']):
            logger.debug("Could not delete datastore %s", wsds_cfg['dataStores']['dataStore'][0]['name'])
            return False

        # now that the workspace is empty, delete it
        if not self._rest_config('DELETE', '/geoserver/rest/workspaces/%s.json' % self.ns):
            logger.debug("Could not delete workspace %s", self.ns)
            return False

        # Get a list of styles
        sts_cfg = self._read_config('/geoserver/rest/styles.json', "Could not get styles.")
        if not sts_cfg is None:
            includes = ['^%s:.*' % self.ns]
            for st_cfg in sts_cfg['styles']['style']:
                skip = False
                for inc in includes:
                    skip = skip or re.compile(inc).match(st_cfg['name']) is None
                if skip:
                    # This style doesn't match any style starting with the prefix.
                    continue

                # Delete the style
                if not self._rest_config('DELETE', st_cfg['href']):
                    logger.debug("Could not delete style %s", st_cfg['name'])
                else:
                    logger.debug("Deleted style %s", st_cfg['name'])

        return True
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/config.py/SpatialUtils.purge_geoserver/original