(root_dir, sub_dir, writer, recursive=False)
Converts files.

  Args:
    root_dir: A string specifying a root directory.
    sub_dir: A string specifying a path to a directory under `root_dir` in which
        to convert contents.
    writer: A TFRecord writer
    recursive: A boolean specifying whether or not recursively convert files
        contained in subdirectories of the specified directory.

  Returns:
    A map from the resulting Futures to the file paths being converted.
Converts files.
Converts files .
def convert_files(root_dir, sub_dir, writer, recursive=False):
  """Converts files.

  Args:
    root_dir: A string specifying a root directory.
    sub_dir: A string specifying a path to a directory under `root_dir` in which
        to convert contents.
    writer: A TFRecord writer
    recursive: A boolean specifying whether or not recursively convert files
        contained in subdirectories of the specified directory.

  Returns:
    A map from the resulting Futures to the file paths being converted.
  """
  dir_to_convert = os.path.join(root_dir, sub_dir)
  tf.logging.info("Converting files in '%s'.", dir_to_convert)
  files_in_dir = tf.gfile.ListDirectory(os.path.join(dir_to_convert))
  recurse_sub_dirs = []
  written_count = 0
  for file_in_dir in files_in_dir:
    tf.logging.log_every_n(tf.logging.INFO, '%d files converted.',
                           1000, written_count)
    full_file_path = os.path.join(dir_to_convert, file_in_dir)
    if (full_file_path.lower().endswith('.mid') or
        full_file_path.lower().endswith('.midi')):
      try:
        sequence = convert_midi(root_dir, sub_dir, full_file_path)
      except Exception as exc:  # pylint: disable=broad-except
        tf.logging.fatal('%r generated an exception: %s', full_file_path, exc)
        continue
      if sequence:
        writer.write(sequence.SerializeToString())
    elif (full_file_path.lower().endswith('.xml') or
          full_file_path.lower().endswith('.mxl')):
      try:
        sequence = convert_musicxml(root_dir, sub_dir, full_file_path)
      except Exception as exc:  # pylint: disable=broad-except
        tf.logging.fatal('%r generated an exception: %s', full_file_path, exc)
        continue
      if sequence:
        writer.write(sequence.SerializeToString())
    elif full_file_path.lower().endswith('.abc'):
      try:
        sequences = convert_abc(root_dir, sub_dir, full_file_path)
      except Exception as exc:  # pylint: disable=broad-except
        tf.logging.fatal('%r generated an exception: %s', full_file_path, exc)
        continue
      if sequences:
        for sequence in sequences:
          writer.write(sequence.SerializeToString())
    else:
      if recursive and tf.gfile.IsDirectory(full_file_path):
        recurse_sub_dirs.append(os.path.join(sub_dir, file_in_dir))
      else:
        tf.logging.warning(
            'Unable to find a converter for file %s', full_file_path)

  for recurse_sub_dir in recurse_sub_dirs:
    convert_files(root_dir, recurse_sub_dir, writer, recursive)
def convert_files ( root_dir , sub_dir , writer , recursive = False ) : dir_to_convert = os . path . join ( root_dir , sub_dir ) tf . logging . info ( "Converting files in '%s'." , dir_to_convert ) files_in_dir = tf . gfile . ListDirectory ( os . path . join ( dir_to_convert ) ) recurse_sub_dirs = [ ] written_count = 0 for file_in_dir in files_in_dir : tf . logging . log_every_n ( tf . logging . INFO , '%d files converted.' , 1000 , written_count ) full_file_path = os . path . join ( dir_to_convert , file_in_dir ) if ( full_file_path . lower ( ) . endswith ( '.mid' ) or full_file_path . lower ( ) . endswith ( '.midi' ) ) : try : sequence = convert_midi ( root_dir , sub_dir , full_file_path ) except Exception as exc : # pylint: disable=broad-except tf . logging . fatal ( '%r generated an exception: %s' , full_file_path , exc ) continue if sequence : writer . write ( sequence . SerializeToString ( ) ) elif ( full_file_path . lower ( ) . endswith ( '.xml' ) or full_file_path . lower ( ) . endswith ( '.mxl' ) ) : try : sequence = convert_musicxml ( root_dir , sub_dir , full_file_path ) except Exception as exc : # pylint: disable=broad-except tf . logging . fatal ( '%r generated an exception: %s' , full_file_path , exc ) continue if sequence : writer . write ( sequence . SerializeToString ( ) ) elif full_file_path . lower ( ) . endswith ( '.abc' ) : try : sequences = convert_abc ( root_dir , sub_dir , full_file_path ) except Exception as exc : # pylint: disable=broad-except tf . logging . fatal ( '%r generated an exception: %s' , full_file_path , exc ) continue if sequences : for sequence in sequences : writer . write ( sequence . SerializeToString ( ) ) else : if recursive and tf . gfile . IsDirectory ( full_file_path ) : recurse_sub_dirs . append ( os . path . join ( sub_dir , file_in_dir ) ) else : tf . logging . warning ( 'Unable to find a converter for file %s' , full_file_path ) for recurse_sub_dir in recurse_sub_dirs : convert_files ( root_dir , recurse_sub_dir , writer , recursive )