parameters: (args, tar_gz_filename)
docstring: Extracts the 'benchmarks' directory of the titan release
      into its corresponding vtr directory
docstring_summary: Extracts the 'benchmarks' directory of the titan release
      into its corresponding vtr directory
docstring_tokens: Extracts the benchmarks directory of the titan release into its corresponding vtr directory
function: def extract_to_vtr_flow_dir(args, tar_gz_filename):
      """
      Extracts the 'benchmarks' directory of the titan release
      into its corresponding vtr directory
      """
  
      # Note that in previous VTR releases, arch files also need to be extracted from the titan release
      # into its corresponding VTR directory. This is no longer needed as VTR is now packed with the
      # newest Titan arch files.
  
      # Reference directories
      arch_dir = os.path.join(args.vtr_flow_dir, "arch")
      benchmarks_dir = os.path.join(args.vtr_flow_dir, "benchmarks")
      titan_benchmarks_extract_dir = os.path.join(benchmarks_dir, "titan_blif")
      titan_other_benchmarks_extract_dir = os.path.join(benchmarks_dir, "titan_other_blif")
      titan_arch_extract_dir = os.path.join(arch_dir, "titan")
  
      arch_upgrade_script = os.path.join(
          os.path.dirname(os.path.realpath(__file__)), "upgrade_arch.py"
      )
  
      if not args.force:
          # Check that all expected directories exist
          expected_dirs = [
              args.vtr_flow_dir,
              benchmarks_dir,
              arch_dir,
              titan_benchmarks_extract_dir,
              titan_arch_extract_dir,
          ]
          for dir in expected_dirs:
              if not os.path.isdir(dir):
                  raise ExtractionError("{} should be a directory".format(dir))
  
      # Create a temporary working directory
      tmpdir = tempfile.mkdtemp(suffix="download_titan", dir=".")
  
      try:
          # We use a callback along with extractall() to only walk through the large tar.gz file
          # once (saving runtime). We then move the files to the correct directories, which should
          # be a cheap rename operation
  
          # Extract matching files into the temporary directory
          with tarfile.TarFile.open(tar_gz_filename, mode="r|*") as tar_file:
              tar_file.extractall(path=tmpdir, members=extract_callback(tar_file))
  
          # Move the extracted files to the relevant directories, SDC files first (since we
          # need to look up the BLIF name to make it match)
          for dirpath, dirnames, filenames in os.walk(tmpdir):
              for filename in filenames:
                  src_file_path = os.path.join(dirpath, filename)
                  dst_file_path = None
                  if fnmatch.fnmatch(src_file_path, "*/titan_release*/benchmarks/titan23/*/*.sdc"):
                      dst_file_path = os.path.join(
                          titan_benchmarks_extract_dir, determine_sdc_name(dirpath)
                      )
                  elif fnmatch.fnmatch(
                      src_file_path, "*/titan_release*/benchmarks/other_benchmarks/*/*.sdc"
                  ):
                      dst_file_path = os.path.join(
                          titan_other_benchmarks_extract_dir, determine_sdc_name(dirpath)
                      )
  
                  if dst_file_path:
                      shutil.move(src_file_path, dst_file_path)
  
          # Then BLIFs
          for dirpath, dirnames, filenames in os.walk(tmpdir):
              for filename in filenames:
                  src_file_path = os.path.join(dirpath, filename)
                  dst_file_path = None
                  if fnmatch.fnmatch(src_file_path, "*/titan_release*/benchmarks/titan23/*/*/*.blif"):
                      dst_file_path = os.path.join(titan_benchmarks_extract_dir, filename)
                  elif fnmatch.fnmatch(
                      src_file_path, "*/titan_release*/benchmarks/other_benchmarks/*/*/*.blif"
                  ):
                      dst_file_path = os.path.join(titan_other_benchmarks_extract_dir, filename)
  
                  if dst_file_path:
                      shutil.move(src_file_path, dst_file_path)
  
      finally:
          # Clean-up
          shutil.rmtree(tmpdir)
  
      print("Done")
function_tokens: def extract_to_vtr_flow_dir ( args , tar_gz_filename ) : # Note that in previous VTR releases, arch files also need to be extracted from the titan release # into its corresponding VTR directory. This is no longer needed as VTR is now packed with the # newest Titan arch files. # Reference directories arch_dir = os . path . join ( args . vtr_flow_dir , "arch" ) benchmarks_dir = os . path . join ( args . vtr_flow_dir , "benchmarks" ) titan_benchmarks_extract_dir = os . path . join ( benchmarks_dir , "titan_blif" ) titan_other_benchmarks_extract_dir = os . path . join ( benchmarks_dir , "titan_other_blif" ) titan_arch_extract_dir = os . path . join ( arch_dir , "titan" ) arch_upgrade_script = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , "upgrade_arch.py" ) if not args . force : # Check that all expected directories exist expected_dirs = [ args . vtr_flow_dir , benchmarks_dir , arch_dir , titan_benchmarks_extract_dir , titan_arch_extract_dir , ] for dir in expected_dirs : if not os . path . isdir ( dir ) : raise ExtractionError ( "{} should be a directory" . format ( dir ) ) # Create a temporary working directory tmpdir = tempfile . mkdtemp ( suffix = "download_titan" , dir = "." ) try : # We use a callback along with extractall() to only walk through the large tar.gz file # once (saving runtime). We then move the files to the correct directories, which should # be a cheap rename operation # Extract matching files into the temporary directory with tarfile . TarFile . open ( tar_gz_filename , mode = "r|*" ) as tar_file : tar_file . extractall ( path = tmpdir , members = extract_callback ( tar_file ) ) # Move the extracted files to the relevant directories, SDC files first (since we # need to look up the BLIF name to make it match) for dirpath , dirnames , filenames in os . walk ( tmpdir ) : for filename in filenames : src_file_path = os . path . join ( dirpath , filename ) dst_file_path = None if fnmatch . fnmatch ( src_file_path , "*/titan_release*/benchmarks/titan23/*/*.sdc" ) : dst_file_path = os . path . join ( titan_benchmarks_extract_dir , determine_sdc_name ( dirpath ) ) elif fnmatch . fnmatch ( src_file_path , "*/titan_release*/benchmarks/other_benchmarks/*/*.sdc" ) : dst_file_path = os . path . join ( titan_other_benchmarks_extract_dir , determine_sdc_name ( dirpath ) ) if dst_file_path : shutil . move ( src_file_path , dst_file_path ) # Then BLIFs for dirpath , dirnames , filenames in os . walk ( tmpdir ) : for filename in filenames : src_file_path = os . path . join ( dirpath , filename ) dst_file_path = None if fnmatch . fnmatch ( src_file_path , "*/titan_release*/benchmarks/titan23/*/*/*.blif" ) : dst_file_path = os . path . join ( titan_benchmarks_extract_dir , filename ) elif fnmatch . fnmatch ( src_file_path , "*/titan_release*/benchmarks/other_benchmarks/*/*/*.blif" ) : dst_file_path = os . path . join ( titan_other_benchmarks_extract_dir , filename ) if dst_file_path : shutil . move ( src_file_path , dst_file_path ) finally : # Clean-up shutil . rmtree ( tmpdir ) print ( "Done" )