예제 #1
0
def wcst11ActionDelete(action, context):

    aname = action["Action"]
    logger.debug("WCSt11:%s: START" % aname)

    # extract permanet storage
    pathPerm = os.path.abspath("%s/.." % context['pathPerm'])

    # extract user provided CID
    coverageId = action["Identifier"]

    if not coverageId:
        raise ExActionFailed, "WCSt11:%s: Missing the required coverage identifier!" % aname

    # check the covergae type
    coverageType = CoverageIdManager().getCoverageType(coverageId)

    if not coverageType:
        raise ExActionFailed, "WCSt11:%s: Invalid coverage identifier! Identifier=%s" % (
            aname, repr(coverageId))

    # process the supproted coverage types

    if coverageType == "RectifiedDataset":
        cls = RectifiedDatasetRecord
        mng = RectifiedDatasetManager()

    elif coverageType == "ReferenceableDataset":
        cls = ReferenceableDatasetRecord
        mng = ReferenceableDatasetManager()

    else:  # unsupproted coverage types
        raise ExActionFailed, "WCSt11:%s: Unsupported coverage type! Type=%s ; Identifier=%s" % (
            aname, repr(coverageType), repr(coverageId))

    # check the location

    obj = cls.objects.get(coverage_id=coverageId)
    pck = obj.data_package

    if pck.data_package_type == 'local':

        logger.debug(dir(pck.localdatapackage))

        lpath = pck.localdatapackage.data_location.path
        mpath = pck.localdatapackage.metadata_location.path

        # let only the covergas inserted via the WCS-T to be deletable via this interface
        if not (lpath.startswith(pathPerm) and mpath.startswith(pathPerm)):
            raise ExActionFailed, "WCSt11:%s: No permission to remove the coverage! Identifier=%s" % (
                aname, repr(coverageId))

        # delete the coverage
        logger.info("WCSt11:%s: Removing coverage: %s " % (aname, coverageId))
        mng.delete(coverageId)

        # delete the coverage data
        for f in (lpath, mpath):
            try:
                logger.info("WCSt11:%s: Removing file: %s " % (aname, f))
                os.remove(f)
            except Exception as e:
                logger.warn("WCSt11:%s: Failed to remove file! path=%s " %
                            (aname, f))
                logger.warn("WCSt11:%s: Reason: %s %s" %
                            (aname, str(type(e)), str(e)))

        # delete directories if empty
        for d in set((os.path.dirname(lpath), os.path.dirname(mpath))):
            try:
                logger.info("WCSt11:%s: Removing directory: %s " % (aname, d))
                os.rmdir(d)
            except Exception as e:
                logger.warn("WCSt11:%s: Failed to remove directory! path=%s " %
                            (aname, d))
                logger.warn("WCSt11:%s: Reason: %s %s" %
                            (aname, str(type(e)), str(e)))

    return coverageId
예제 #2
0
def wcst11ActionDelete( action , context ) : 

    aname = action["Action"]
    logger.debug( "WCSt11:%s: START" % aname ) 

    # extract permanet storage 
    pathPerm = os.path.abspath( "%s/.."%context['pathPerm'] ) 

    # extract user provided CID 
    coverageId = action["Identifier"] 

    if not coverageId: raise ExActionFailed , "WCSt11:%s: Missing the required coverage identifier!" % aname 

    # check the covergae type 
    coverageType = CoverageIdManager().getCoverageType( coverageId )

    if not coverageType: raise ExActionFailed , "WCSt11:%s: Invalid coverage identifier! Identifier=%s" % ( aname , repr( coverageId ) )  
    
    # process the supproted coverage types 

    if coverageType == "RectifiedDataset":
        cls = RectifiedDatasetRecord
        mng = RectifiedDatasetManager() 

    elif coverageType == "ReferenceableDataset": 
        cls = ReferenceableDatasetRecord
        mng = ReferenceableDatasetManager()  

    else : # unsupproted coverage types 
        raise ExActionFailed , "WCSt11:%s: Unsupported coverage type! Type=%s ; Identifier=%s" % ( aname , repr(coverageType) , repr( coverageId ) )  

    # check the location 

    obj = cls.objects.get( coverage_id = coverageId ) 
    pck = obj.data_package

    if pck.data_package_type == 'local' : 

        logger.debug( dir( pck.localdatapackage ) ) 

        lpath = pck.localdatapackage.data_location.path
        mpath = pck.localdatapackage.metadata_location.path

        # let only the covergas inserted via the WCS-T to be deletable via this interface 
        if not ( lpath.startswith( pathPerm ) and mpath.startswith( pathPerm ) ) : 
            raise ExActionFailed , "WCSt11:%s: No permission to remove the coverage! Identifier=%s" % ( aname , repr(coverageId) )  

        # delete the coverage 
        logger.info( "WCSt11:%s: Removing coverage: %s " % ( aname , coverageId ) ) 
        mng.delete( coverageId ) 

        # delete the coverage data 
        for f in ( lpath , mpath ) : 
            try : 
                logger.info( "WCSt11:%s: Removing file: %s " % ( aname , f ) )
                os.remove( f ) 
            except Exception as e :
                logger.warn( "WCSt11:%s: Failed to remove file! path=%s " % ( aname , f ) ) 
                logger.warn( "WCSt11:%s: Reason: %s %s" % ( aname , str(type(e)) , str(e) ) )  

        # delete directories if empty 
        for d in set( ( os.path.dirname( lpath ) , os.path.dirname( mpath ) ) ) : 
            try : 
                logger.info( "WCSt11:%s: Removing directory: %s " % ( aname , d ) )
                os.rmdir( d ) 
            except Exception as e :
                logger.warn( "WCSt11:%s: Failed to remove directory! path=%s " % ( aname , d ) ) 
                logger.warn( "WCSt11:%s: Reason: %s %s" % ( aname , str(type(e)) , str(e) ) )

    return coverageId