예제 #1
0
파일: imageSharing.py 프로젝트: rexhsu/vdsm
def _copyData(inFile, outFile, totalSize):
    bytesToRead = totalSize
    while totalSize > 0:
        toRead = min(BUFFER_SIZE, totalSize)

        try:
            data = inFile.read(toRead)
        except IOError as e:
            error = "error reading file: %s" % e
            log.error(error)
            raise se.MiscFileReadException(error)

        if not data:
            error = "partial data %s from %s" % \
                    (bytesToRead - totalSize, bytesToRead)
            log.error(error)
            raise se.MiscFileReadException(error)

        outFile.write(data)
        # outFile may not be a real file object but a wrapper.
        # To ensure that we don't use more memory as the input buffer size
        # we flush on every write.
        outFile.flush()

        totalSize = totalSize - len(data)
예제 #2
0
파일: check.py 프로젝트: bronhaim/vdsm
 def delay(self):
     # TODO: Raising MiscFileReadException for all errors to keep the old
     # behavior. Should probably use StorageDomainAccessError.
     if self.rc != 0:
         raise exception.MiscFileReadException(self.path, self.rc, self.err)
     if not self.err:
         raise exception.MiscFileReadException(self.path, "no stats")
     stats = self.err.splitlines()[-1]
     match = self._PATTERN.match(stats)
     if not match:
         raise exception.MiscFileReadException(self.path,
                                               "no match: %r" % stats)
     seconds = match.group(1)
     try:
         return float(seconds)
     except ValueError as e:
         raise exception.MiscFileReadException(self.path, e)