Exemplo n.º 1
0
    def test_filesystem(self):
        hfile = Hfile(hostname, port, path, mode='w')
        hfile.close()

        fs = Hfilesystem(hostname, port)

        self.assertTrue(fs.exists(path))
        self.assertFalse(fs.exists(path + 'doesnotexist'))

        self.assertTrue(fs.rename(path, path + 'renamed'))

        self.assertTrue(fs.delete(path + 'renamed'))
        self.assertFalse(fs.delete(path))
Exemplo n.º 2
0
  def test_filesystem(self):
    hfile = Hfile(hostname, port, path, mode='w')
    hfile.close()

    fs = Hfilesystem(hostname, port)

    self.assertTrue(fs.exists(path))
    self.assertFalse(fs.exists(path + 'doesnotexist'))

    self.assertTrue(fs.rename(path, path + 'renamed'))

    self.assertTrue(fs.delete(path + 'renamed'))
    self.assertFalse(fs.delete(path))
Exemplo n.º 3
0
  def StoreBlob(self, blob_key, blob_stream):
    """Store blob stream to disk.

    Args:
      blob_key: Blob key of blob to store.
      blob_stream: Stream or stream-like object that will generate blob content.
    """
    logging.debug('storing blob with key %s' %blob_key)
    blob_key = self._BlobKey(blob_key)
    blob_directory = self._DirectoryForBlob(blob_key)
    if not self._fs.exists(blob_directory):
      self._fs.mkdir(blob_directory)
    blob_file = self._FileForBlob(blob_key)
    hdfs_file = Hfile(self._server, self._port, blob_file, mode='w')

    try:
      while True:
        block = blob_stream.read(1 << 20)
        if not block:
          break
        hdfs_file.write(block)
    finally:
     hdfs_file.close()
Exemplo n.º 4
0
    def OpenBlob(self, blob_key):
        """Open blob file for streaming.

    Args:
      blob_key: Blob-key of existing blob to open for reading.

    Returns:
      Open file stream for reading blob from disk.
    """
        logging.debug('reading blob with key %s' % blob_key)
        return Hfile(self._server,
                     self._port,
                     self._FileForBlob(blob_key),
                     mode='r')
Exemplo n.º 5
0
    def StoreBlob(self, blob_key, blob_stream):
        """Store blob stream to disk.

    Args:
      blob_key: Blob key of blob to store.
      blob_stream: Stream or stream-like object that will generate blob content.
    """
        logging.debug('storing blob with key %s' % blob_key)
        blob_key = self._BlobKey(blob_key)
        blob_directory = self._DirectoryForBlob(blob_key)
        if not self._fs.exists(blob_directory):
            self._fs.mkdir(blob_directory)
        blob_file = self._FileForBlob(blob_key)
        hdfs_file = Hfile(self._server, self._port, blob_file, mode='w')

        try:
            while True:
                block = blob_stream.read(1 << 20)
                if not block:
                    break
                hdfs_file.write(block)
        finally:
            hdfs_file.close()