Exemple #1
0
    def __deleteText(self):
        #Deletes a text file
        keys = self.__db.keys()
        if self.__name not in keys:
            s = "DELETE failed since " + self.__name + " not in inventory"
            raise KeyError, s

        record = self.__db[self.__name]

        if self.__user != "SITE" and str(record.localCtx.getLocalizationLevel()) != "USER":
            raise RuntimeError, "User can only delete user-level files."

        if self.__user == "SITE" and str(record.localCtx.getLocalizationLevel()) != "SITE":
            raise RuntimeError, "SITE can only delete site-level files."

        req = PrivilegedUtilityRequestMessage()
        cmds = []
        cmd = DeleteUtilityCommand()
        cmd.setContext(record.localCtx)
        cmd.setFilename(record.path + "/" + record.fileName)
        cmd.setMyContextName(record.localCtx.getContextName())
        cmds.append(cmd)
        # make sure to delete the .pyo and .pyc files as well
        if os.path.splitext(record.fileName)[1] == ".py":
            for ext in ["c", "o"]:
                cmd = DeleteUtilityCommand()
                cmd.setContext(record.localCtx)
                cmd.setFilename(record.path + "/" + record.fileName + ext)
                cmd.setMyContextName(record.localCtx.getContextName())
                cmds.append(cmd)
        req.setCommands(cmds)

        try:
            serverResponse = self.__thrift.sendRequest(req)
            if not isinstance(serverResponse, SuccessfulExecution):
                message = ""
                if hasattr(serverResponse, "getMessage"):
                    message = serverResponse.getMessage()
                raise RuntimeError(message)
            serverResponse = serverResponse.getResponse()
        except Exception, e:
            raise RuntimeError("Could not delete file from localization server: " + str(e))
Exemple #2
0
def outputAG(db, databaseIds, parmIds, startTime, endTime, outputFile,
             coordConversionString, userName):
    # get the grid slices
    (serverFile, okay) = getGridSlices(db, databaseIds, parmIds, startTime,
                                       endTime, coordConversionString)
    if not okay:
        return 3

    # output the grid slices to the output file
    fh = None
    if outputFile != "-":
        try:
            fh = open(outputFile, 'w')
        except:
            logException("Unable to open the file " + outputFile +
                         " for output")
            return 2
    else:
        fh = sys.stdout

    logEvent("Outputting ASCII Grid File")

    request = LocalizationStreamGetRequest()
    request.setOffset(0)
    request.setNumBytes(BUFFER_SIZE)
    ctx = LocalizationContext()
    ll = LocalizationLevel("USER")
    type = LocalizationType("COMMON_STATIC")
    ctx.setLocalizationType(type)
    ctx.setLocalizationLevel(ll)
    ctx.setContextName(userName)
    request.setContext(ctx)
    request.setMyContextName(ctx.getContextName())
    request.setFileName(serverFile)

    finished = False
    while not finished:
        try:
            serverResponse = db.sendRequest(request)
            if not isinstance(serverResponse, SuccessfulExecution):
                message = ""
                if hasattr(serverResponse, "getMessage"):
                    message = serverResponse.getMessage()
                raise RuntimeError(message)
            serverResponse = serverResponse.getResponse()
        except:
            logException("Could not retrieve ASCIIGrids file " + serverFile +
                         " from localization server")
            okay = False
            break

        # serverResponse will be returned as a LocalizationStreamPutRequest
        # object. we'll use its methods to read back the serialized file
        # data.
        # bytes get returned to us as an numpy.ndarray
        bytes = serverResponse.getBytes()
        fh.write(bytes.tostring())
        request.setOffset(request.getOffset() + len(bytes))
        finished = serverResponse.getEnd()

    if fh is not None:
        fh.close()

    # delete server-side file
    req = PrivilegedUtilityRequestMessage()
    cmds = []
    cmd = DeleteUtilityCommand()
    cmd.setContext(ctx)
    cmd.setFilename(serverFile)
    cmd.setMyContextName(ctx.getContextName())
    cmds.append(cmd)
    req.setCommands(cmds)
    try:
        serverResponse = db.sendRequest(req)
        if not isinstance(serverResponse, SuccessfulExecution):
            message = ""
            if hasattr(serverResponse, "getMessage"):
                message = serverResponse.getMessage()
            raise RuntimeError(message)
    except:
        logException("Could not delete temporary file " + serverFile +
                     " from localization server")
        okay = False

    if okay:
        return 0
    else:
        return 3
Exemple #3
0
 def __deleteText(self):
     #Deletes a text file
     keys = self.__db.keys()
     if self.__name not in keys:
         s = "DELETE failed since " + self.__name + " not in inventory"
         raise KeyError, s
     
     record = self.__db[self.__name]
     
     if self.__user != "SITE" and str(record.localCtx.getLocalizationLevel()) != "USER":
         raise RuntimeError, "User can only delete user-level files."
     
     if self.__user == "SITE" and str(record.localCtx.getLocalizationLevel()) != "SITE":
         raise RuntimeError, "SITE can only delete site-level files."
     
     req = PrivilegedUtilityRequestMessage()
     cmds = []
     cmd = DeleteUtilityCommand()
     cmd.setContext(record.localCtx)
     cmd.setFilename(record.path + "/" + record.fileName)
     cmd.setMyContextName(record.localCtx.getContextName())
     cmds.append(cmd)
     # make sure to delete the .pyo and .pyc files as well
     if os.path.splitext(record.fileName)[1] == ".py":
         for ext in ["c", "o"]:
             cmd = DeleteUtilityCommand()
             cmd.setContext(record.localCtx)
             cmd.setFilename(record.path + "/" + record.fileName + ext)
             cmd.setMyContextName(record.localCtx.getContextName())
             cmds.append(cmd)
     req.setCommands(cmds)
     
     try:
         serverResponse = self.__thrift.sendRequest(req)
         if not isinstance(serverResponse, SuccessfulExecution):
             message = ""
             if hasattr(serverResponse, "getMessage"):
                 message = serverResponse.getMessage()
             raise RuntimeError(message)
         serverResponse = serverResponse.getResponse()
     except Exception, e:
         raise RuntimeError("Could not delete file from localization server: " + str(e))
Exemple #4
0
def outputAG(db, databaseIds, parmIds, startTime, endTime, outputFile, coordConversionString, userName):    
    # get the grid slices
    (serverFile, okay) = getGridSlices(db, databaseIds, parmIds, startTime, endTime, coordConversionString)
    if not okay:
        return 3
    
    # output the grid slices to the output file
    fh = None
    if outputFile != "-":
        try:
            fh = open(outputFile, 'w')
        except:
            logException("Unable to open the file " + outputFile + " for output")
            return 2
    else:
        fh = sys.stdout
        
    logEvent("Outputting ASCII Grid File")
    
    request = LocalizationStreamGetRequest()
    request.setOffset(0)
    request.setNumBytes(BUFFER_SIZE)
    ctx = LocalizationContext()
    ll = LocalizationLevel("USER")
    type = LocalizationType("COMMON_STATIC")
    ctx.setLocalizationType(type)
    ctx.setLocalizationLevel(ll)
    ctx.setContextName(userName)
    request.setContext(ctx)
    request.setMyContextName(ctx.getContextName())
    request.setFileName(serverFile)
    
    finished = False
    while not finished:
        try:
            serverResponse = db.sendRequest(request)
            if not isinstance(serverResponse, SuccessfulExecution):
                message = ""
                if hasattr(serverResponse, "getMessage"):
                    message = serverResponse.getMessage()
                raise RuntimeError(message)
            serverResponse = serverResponse.getResponse()
        except:
            logException("Could not retrieve ASCIIGrids file " + serverFile + " from localization server")
            okay = False
            break
        
        # serverResponse will be returned as a LocalizationStreamPutRequest
        # object. we'll use its methods to read back the serialized file 
        # data.
        # bytes get returned to us as an numpy.ndarray
        bytes = serverResponse.getBytes()
        fh.write(bytes.tostring())
        request.setOffset(request.getOffset() + len(bytes))
        finished = serverResponse.getEnd()
        
    if fh is not None:
        fh.close()
        
    # delete server-side file
    req = PrivilegedUtilityRequestMessage()
    cmds = []
    cmd = DeleteUtilityCommand()
    cmd.setContext(ctx)
    cmd.setFilename(serverFile)
    cmd.setMyContextName(ctx.getContextName())
    cmds.append(cmd)
    req.setCommands(cmds)
    try:
        serverResponse = db.sendRequest(req)
        if not isinstance(serverResponse, SuccessfulExecution):
            message = ""
            if hasattr(serverResponse, "getMessage"):
                message = serverResponse.getMessage()
            raise RuntimeError(message)
    except:
        logException("Could not delete temporary file " + serverFile + " from localization server")
        okay = False
            
    if okay:
        return 0
    else:
        return 3
Exemple #5
0
def deleteTextData(invRecord):
    req = PrivilegedUtilityRequestMessage()
    cmds = []
    cmd = DeleteUtilityCommand()
    cmd.setContext(invRecord.localCtx)
    cmd.setFilename(invRecord.filePath)
    cmd.setMyContextName(invRecord.localCtx.getContextName())
    cmds.append(cmd)
    # be sure to delete .pyo and .pyc files
    if os.path.splitext(invRecord.filePath)[1] == ".py":
        for ext in ["c", "o"]:
            cmd = DeleteUtilityCommand()
            cmd.setContext(invRecord.localCtx)
            cmd.setMyContextName(invRecord.localCtx.getContextName())
            cmd.setFilename(invRecord.filePath + ext)
            cmds.append(cmd)
    req.setCommands(cmds)

    serverResponse = Source.sendRequest(req)
    if not isinstance(serverResponse, SuccessfulExecution):
        message = ""
        if hasattr(serverResponse, "getMessage"):
            message = serverResponse.getMessage()
        raise RuntimeError(message)
    def createDeleteRequest(self):
        req = DeleteUtilityCommand()

        return req
Exemple #7
0
def deleteTextData(invRecord):
    req = PrivilegedUtilityRequestMessage()
    cmds = []
    cmd = DeleteUtilityCommand()
    cmd.setContext(invRecord.localCtx)
    cmd.setFilename(invRecord.filePath)
    cmd.setMyContextName(invRecord.localCtx.getContextName())
    cmds.append(cmd)
    # be sure to delete .pyo and .pyc files
    if os.path.splitext(invRecord.filePath)[1] == ".py":
        for ext in ["c", "o"]:
            cmd = DeleteUtilityCommand()
            cmd.setContext(invRecord.localCtx)
            cmd.setMyContextName(invRecord.localCtx.getContextName())
            cmd.setFilename(invRecord.filePath + ext)
            cmds.append(cmd)
    req.setCommands(cmds)
    
    serverResponse = Source.sendRequest(req)
    if not isinstance(serverResponse, SuccessfulExecution):
        message = ""
        if hasattr(serverResponse, "getMessage"):
            message = serverResponse.getMessage()
        raise RuntimeError(message)