<commit_before># coding=utf-8
# -------------------------------------------------------------------------------
# Author: <NAME> <<EMAIL>>
# Grupo de Inteligencia Computational <www.ehu.es/ccwintco>
# Universidad del Pais Vasco UPV/EHU
#
# 2015, <NAME>
# Use this at your own risk!
# -------------------------------------------------------------------------------

import logging
import os.path as op

from   .config      import get_inkscape_binpath
from   .commands    import call_command

log = logging.getLogger(__name__)


class FileExporter(object):
    """A base class to template a basic file converter: from the template to
    anything the output_filepath extension says.
    """
    def export(input_filepath, output_filepath, args_string, **kwargs):
        raise NotImplementedError


def call_inkscape(args_strings, inkscape_binpath=None):
    """Call inkscape CLI with arguments and returns its return value.

    Parameters
    ----------
    args_string: list of str

    inkscape_binpath: str

    Returns
    -------
    return_value
        Inkscape command CLI call return value.
    """
    log.debug('Looking for the binary file for inkscape.')

    if inkscape_binpath is None:
        inkscape_binpath = get_inkscape_binpath()

    if inkscape_binpath is None or not op.exists(inkscape_binpath):
        raise IOError('Inkscape binary has not been found. Please check '
                      'configuration.')

    return call_command(inkscape_binpath, args_strings)


def inkscape_export(input_file, output_file, export_flag="-A", dpi=90, inkscape_binpath=None):
    """ Call Inkscape to export the input_file to outpu_file using the
    specific export argument flag for the output file type.

    Parameters
    ----------

    input_file: str
        Path to the input file

    output_file: str
        Path to the output file

    export_flag: str
        Inkscape CLI flag to indicate the type of the output file

    Returns
    -------
    return_value
        Command call return value

    """
    if not op.exists(input_file):
        log.error('File {} not found.'.format(input_file))
        raise IOError((0, 'File not found.', input_file))

    if not '=' in export_flag:
        export_flag += ' '

    arg_strings  = []
    arg_strings += ['--without-gui']
    arg_strings += ['{}"{}"'.format(export_flag, output_file)]
    arg_strings += ['--export-dpi={}'.format(dpi)]
    arg_strings += ['"{}"'.format(input_file)]

    return call_inkscape(arg_strings, inkscape_binpath=inkscape_binpath)
<commit_msg>add export-text-to-path option in inkscape export<commit_after># coding=utf-8
# -------------------------------------------------------------------------------
# Author: <NAME> <<EMAIL>>
# Grupo de Inteligencia Computational <www.ehu.es/ccwintco>
# Universidad del Pais Vasco UPV/EHU
#
# 2015, <NAME>
# Use this at your own risk!
# -------------------------------------------------------------------------------

import logging
import os.path as op

from   .config      import get_inkscape_binpath
from   .commands    import call_command

log = logging.getLogger(__name__)


class FileExporter(object):
    """A base class to template a basic file converter: from the template to
    anything the output_filepath extension says.
    """
    def export(input_filepath, output_filepath, args_string, **kwargs):
        raise NotImplementedError


def call_inkscape(args_strings, inkscape_binpath=None):
    """Call inkscape CLI with arguments and returns its return value.

    Parameters
    ----------
    args_string: list of str

    inkscape_binpath: str

    Returns
    -------
    return_value
        Inkscape command CLI call return value.
    """
    log.debug('Looking for the binary file for inkscape.')

    if inkscape_binpath is None:
        inkscape_binpath = get_inkscape_binpath()

    if inkscape_binpath is None or not op.exists(inkscape_binpath):
        raise IOError('Inkscape binary has not been found. Please check '
                      'configuration.')

    return call_command(inkscape_binpath, args_strings)


def inkscape_export(input_file, output_file, export_flag="-A", dpi=90, inkscape_binpath=None):
    """ Call Inkscape to export the input_file to outpu_file using the
    specific export argument flag for the output file type.

    Parameters
    ----------

    input_file: str
        Path to the input file

    output_file: str
        Path to the output file

    export_flag: str
        Inkscape CLI flag to indicate the type of the output file

    Returns
    -------
    return_value
        Command call return value

    """
    if not op.exists(input_file):
        log.error('File {} not found.'.format(input_file))
        raise IOError((0, 'File not found.', input_file))

    if not '=' in export_flag:
        export_flag += ' '

    arg_strings  = []
    arg_strings += ['--without-gui']
    arg_strings += ['--export-text-to-path']
    arg_strings += ['{}"{}"'.format(export_flag, output_file)]
    arg_strings += ['--export-dpi={}'.format(dpi)]
    arg_strings += ['"{}"'.format(input_file)]

    return call_inkscape(arg_strings, inkscape_binpath=inkscape_binpath)

{'fraction_non_alphanumeric': 0.15890199110767447, 'fraction_numerical': 0.003092982795283201, 'mean_word_length': 2.340219496449322, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5152482', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1498, 'n_words': 439}