code: def copyHdfsDirectoryToLocal(
      hdfsDirectory, localDirectory, hdfsClient
  ):
      """Copy directory from HDFS to local"""
      if not os.path.exists(localDirectory):
          os.makedirs(localDirectory)
      try:
          listing = hdfsClient.list_status(hdfsDirectory)
      except Exception as exception:
          nni_log(
              LogType.Error,
              "List hdfs directory {0} error: {1}".format(
                  hdfsDirectory, str(exception)
              ),
          )
          raise exception
  
      for f in listing:
          if f.type == "DIRECTORY":
              subHdfsDirectory = posixpath.join(
                  hdfsDirectory, f.pathSuffix
              )
              subLocalDirectory = os.path.join(
                  localDirectory, f.pathSuffix
              )
              copyHdfsDirectoryToLocal(
                  subHdfsDirectory, subLocalDirectory, hdfsClient
              )
          elif f.type == "FILE":
              hdfsFilePath = posixpath.join(hdfsDirectory, f.pathSuffix)
              localFilePath = os.path.join(localDirectory, f.pathSuffix)
              copyHdfsFileToLocal(
                  hdfsFilePath, localFilePath, hdfsClient
              )
          else:
              raise AssertionError("unexpected type {}".format(f.type))
  
imports: import os
  import posixpath
  from .log_utils import LogType, nni_log
label_desc: Use image node_id 1 for calling a global function with example usage: copyHdfsDirectoryToLocal(hdfsDirectory, localDirectory, hdfsClient) without return types