<commit_before>from os import system, path, remove, chdir, getcwd
import re
from sys import platform

# System dependent functions

# Note, sometime in 2018 ImageMagicks convert program by default
# disallowed pdf file conversions.  A workaround is to edit
# /etc/ImageMagick-6/policy.xml 

def tmpfilename(suffix=''):

    from tempfile import gettempdir, NamedTemporaryFile
    
    # Searches using TMPDIR, TEMP, TMP environment variables
    tempdir = gettempdir()
    
    filename = NamedTemporaryFile(suffix=suffix, dir=tempdir, 
                                  delete=False).name
    return filename


def convert_pdf_svg(pdf_filename, svg_filename):

    system('pdf2svg %s %s' % (pdf_filename, svg_filename))
    if not path.exists(svg_filename):
        raise RuntimeError('Could not generate %s with pdf2svg.  Is it installed?' % 
                           svg_filename)


def convert_pdf_png_convert(pdf_filename, png_filename, oversample=1):

    if 'win' in platform:
        # Windows has a program called convert, try magick convert
        # for image magick convert.
        system('magick convert -density %d %s %s' %
               (oversample * 100, pdf_filename, png_filename))
    else:
        system('convert -density %d %s %s' %
               (oversample * 100, pdf_filename, png_filename))
        
    if not path.exists(png_filename):
        raise RuntimeError('Could not generate %s with convert' % 
                           png_filename)

def convert_pdf_png_pdftoppm(pdf_filename, png_filename, oversample=1):

    system('pdftoppm -r %d -png %s > %s' % (oversample * 200,
                                            pdf_filename, png_filename))
        
    if not path.exists(png_filename):
        raise RuntimeError('Could not generate %s with pdftoppm' % <commit_msg>Improve png conversion<commit_after>from os import system, path, remove, chdir, getcwd
import re
from sys import platform

# System dependent functions

# Note, sometime in 2018 ImageMagicks convert program by default
# disallowed pdf file conversions.  A workaround is to edit
# /etc/ImageMagick-6/policy.xml 

def tmpfilename(suffix=''):

    from tempfile import gettempdir, NamedTemporaryFile
    
    # Searches using TMPDIR, TEMP, TMP environment variables
    tempdir = gettempdir()
    
    filename = NamedTemporaryFile(suffix=suffix, dir=tempdir, 
                                  delete=False).name
    return filename


def convert_pdf_svg(pdf_filename, svg_filename):

    system('pdf2svg %s %s' % (pdf_filename, svg_filename))
    if not path.exists(svg_filename):
        raise RuntimeError('Could not generate %s with pdf2svg.  Is it installed?' % 
                           svg_filename)


def convert_pdf_png_convert(pdf_filename, png_filename, oversample=1):

    if 'win' in platform:
        # Windows has a program called convert, try magick convert
        # for image magick convert.
        system('magick convert -density %d %s %s' %
               (oversample * 100, pdf_filename, png_filename))
    else:
        system('convert -density %d %s %s' %
               (oversample * 100, pdf_filename, png_filename))
        
    if not path.exists(png_filename):
        raise RuntimeError('Could not generate %s with convert' % 
                           png_filename)

def convert_pdf_png_pdftoppm(pdf_filename, png_filename, oversample=1):

    system('pdftoppm -r %d  -png %s -thinlinemode shape > %s' %
           (oversample * 150, pdf_filename, png_filename))
        
    if not path.exists(png_filename):
        raise RuntimeError('Could not generate %s with pdftoppm' % 
{'fraction_non_alphanumeric': 0.08257387462027065, 'fraction_numerical': 0.009942004971002486, 'mean_word_length': 2.6883910386965377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2172737', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1016, 'n_words': 316}