<commit_before>import os
import sys
import tempfile

from icqsol.shapes.icqShapeManager import ShapeManager
from icqsol.bem.icqLaplaceMatrices import LaplaceMatrices

PLY = 'ply'
POLYDATA = 'POLYDATA'
VTK = 'vtk'


def asbool(val):
    return str(val).lower() in ['yes', 'true']


def get_format_and_type(galaxy_ext):
    # Define the output file format and type.
    format = None
    datatype = None
    if galaxy_ext in ['vtkascii', 'vtkbinary']:
        format = VTK
    elif galaxy_ext in ['plyascii', 'plybinary']:
        format = PLY
    if galaxy_ext in ['vtkascii', 'plyascii']:
        datatype = 'ascii'
    elif galaxy_ext in ['vtkbinary', 'plybinary']:
        datatype = 'binary'
    return format, datatype


def get_input_file_path(tmp_dir, input_file, format):
    """
    iCqSol uses file extensions (e.g., .ply, .vtk) when reading and
    writing files, so the Galaxy dataset naming convention of
    setting all file extensions as .dat must be handled.
    """
    file_path = get_temporary_file_path(tmp_dir, format)
    # Remove the file so we can create a symlink.
    os.remove(file_path)
    os.symlink(input_file, file_path)
    return file_path


def get_laplace_solver(shape_data, max_edge_length=float('inf')):
    return LaplaceMatrices(shape_data, max_edge_length=max_edge_length)


def get_shape_manager(format=None, dataset_type=None):
    # Instantiate a ShapeManager.
    return ShapeManager(file_format=format, vtk_dataset_type=dataset_type)


def get_temp_dir(prefix='tmp-vtk-', dir=None):
    """
    Return a temporary directory.
    """
    return tempfile.mkdtemp(prefix=prefix, dir=dir)


def get_tempfilename(dir=None, suffix=None):
    """
    Return a temporary file name.
    """
    if suffix is None:
        s = None
    elif suffix.startswith('.'):
        s = suffix
    else:
        s = '.%s' % suffix
    fd, name = tempfile.mkstemp(suffix=s, dir=dir)
    os.close(fd)
    return name


def get_temporary_file_path(tmp_dir, file_extension):
    """<commit_msg> renaming LaplaceMatrices to LaplaceSolver<commit_after>import os
import sys
import tempfile

from icqsol.shapes.icqShapeManager import ShapeManager
from icqsol.bem.icqLaplacesSolver import LaplaceSolver

PLY = 'ply'
POLYDATA = 'POLYDATA'
VTK = 'vtk'


def asbool(val):
    return str(val).lower() in ['yes', 'true']


def get_format_and_type(galaxy_ext):
    # Define the output file format and type.
    format = None
    datatype = None
    if galaxy_ext in ['vtkascii', 'vtkbinary']:
        format = VTK
    elif galaxy_ext in ['plyascii', 'plybinary']:
        format = PLY
    if galaxy_ext in ['vtkascii', 'plyascii']:
        datatype = 'ascii'
    elif galaxy_ext in ['vtkbinary', 'plybinary']:
        datatype = 'binary'
    return format, datatype


def get_input_file_path(tmp_dir, input_file, format):
    """
    iCqSol uses file extensions (e.g., .ply, .vtk) when reading and
    writing files, so the Galaxy dataset naming convention of
    setting all file extensions as .dat must be handled.
    """
    file_path = get_temporary_file_path(tmp_dir, format)
    # Remove the file so we can create a symlink.
    os.remove(file_path)
    os.symlink(input_file, file_path)
    return file_path


def get_laplace_solver(shape_data, max_edge_length=float('inf')):
    return LaplaceSolver(shape_data, max_edge_length=max_edge_length)


def get_shape_manager(format=None, dataset_type=None):
    # Instantiate a ShapeManager.
    return ShapeManager(file_format=format, vtk_dataset_type=dataset_type)


def get_temp_dir(prefix='tmp-vtk-', dir=None):
    """
    Return a temporary directory.
    """
    return tempfile.mkdtemp(prefix=prefix, dir=dir)


def get_tempfilename(dir=None, suffix=None):
    """
    Return a temporary file name.
    """
    if suffix is None:
        s = None
    elif suffix.startswith('.'):
        s = suffix
    else:
        s = '.%s' % suffix
    fd, name = tempfile.mkstemp(suffix=s, dir=dir)
    os.close(fd)
    return name


def get_temporary_file_path(tmp_dir, file_extension):
    """
{'fraction_non_alphanumeric': 0.10409472126295018, 'fraction_numerical': 0.0, 'mean_word_length': 3.53072625698324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4188782', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1342, 'n_words': 358}