parameters: (entry_output_dir, symlink_dir, desired_files,
                         parent_dirs)
docstring: Creates a directory tree of symlinks to the given files.
  
    The idea here is to replicate a directory tree while leaving out files within
    it not listed by |desired_files|.
docstring_summary: Creates a directory tree of symlinks to the given files.
docstring_tokens: Creates a directory tree of symlinks to the given files .
function: def _CreateSymlinkTree(entry_output_dir, symlink_dir, desired_files,
                         parent_dirs):
    """Creates a directory tree of symlinks to the given files.
  
    The idea here is to replicate a directory tree while leaving out files within
    it not listed by |desired_files|.
    """
    assert _IsSubpathOf(symlink_dir, entry_output_dir)
    if os.path.exists(symlink_dir):
      shutil.rmtree(symlink_dir)
  
    for target_path in desired_files:
      prefix = next(d for d in parent_dirs if target_path.startswith(d))
      subpath = os.path.relpath(target_path, prefix)
      symlinked_path = os.path.join(symlink_dir, subpath)
      symlinked_dir = os.path.dirname(symlinked_path)
      if not os.path.exists(symlinked_dir):
        os.makedirs(symlinked_dir)
      relpath = os.path.relpath(target_path, symlinked_dir)
      logging.debug('Creating symlink %s -> %s', symlinked_path, relpath)
      os.symlink(relpath, symlinked_path)
function_tokens: def _CreateSymlinkTree ( entry_output_dir , symlink_dir , desired_files , parent_dirs ) : assert _IsSubpathOf ( symlink_dir , entry_output_dir ) if os . path . exists ( symlink_dir ) : shutil . rmtree ( symlink_dir ) for target_path in desired_files : prefix = next ( d for d in parent_dirs if target_path . startswith ( d ) ) subpath = os . path . relpath ( target_path , prefix ) symlinked_path = os . path . join ( symlink_dir , subpath ) symlinked_dir = os . path . dirname ( symlinked_path ) if not os . path . exists ( symlinked_dir ) : os . makedirs ( symlinked_dir ) relpath = os . path . relpath ( target_path , symlinked_dir ) logging . debug ( 'Creating symlink %s -> %s' , symlinked_path , relpath ) os . symlink ( relpath , symlinked_path )