Exemple #1
0
    def stat(self):
        """Get status of a finalized file.

    Returns:
      a _FileStat object similar to that returned by python's os.stat(path).

    Throws:
      FinalizationError if file is not finalized.
    """
        self._verify_read_mode()

        request = file_service_pb.StatRequest()
        response = file_service_pb.StatResponse()
        request.set_filename(self._filename)

        _make_call('Stat', request, response)

        if response.stat_size() == 0:
            raise ExistenceError("File %s not found." % self._filename)

        if response.stat_size() > 1:
            raise ValueError(
                "Requested stat for one file. Got more than one response.")

        file_stat_pb = response.stat(0)
        file_stat = _FileStat()
        file_stat.filename = file_stat_pb.filename()
        file_stat.finalized = file_stat_pb.finalized()
        file_stat.st_size = file_stat_pb.length()
        file_stat.st_mtime = file_stat_pb.mtime()
        file_stat.st_ctime = file_stat_pb.ctime()

        return file_stat
Exemple #2
0
def stat(filename):
    """Get status of a finalized file given it's full path filename.

  Returns:
    a _FileStat object similar to that returned by python's os.stat(path).

  Throws:
    FinalizationError if file is not finalized.
  """
    if not filename:
        raise InvalidArgumentError('Filename is empty')
    if not isinstance(filename, basestring):
        raise InvalidArgumentError('Filename should be a string')

    request = file_service_pb.StatRequest()
    response = file_service_pb.StatResponse()
    request.set_filename(filename)

    with open(filename, 'r'):
        _make_call('Stat', request, response)

    if response.stat_size() != 1:
        raise ValueError(
            "Requested stat for one file. Got zero or more than one responses")

    file_stat_pb = response.stat(0)
    file_stat = _FileStat()
    file_stat.filename = file_stat_pb.filename()
    file_stat.finalized = file_stat_pb.finalized()
    file_stat.st_size = file_stat_pb.length()

    return file_stat