def test_no_change_test(self):
        """plotextractor - get_converted_image_name no change"""
        image = '/path/to/image.png'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == image, 'didn\'t notice image was already ' + \
                                       'converted')
Пример #2
0
    def test_dot_in_dir_name_no_ext_test(self):
        """plotextractor - get_converted_image_name dot in dir name"""
        image = '/path.to/the/image'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == image + '.png',
                        'didn\'t add extension')
Пример #3
0
    def test_change_extension_test(self):
        """plotextractor - get_converted_image_name extension"""
        image = '/path/to/image.eps'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == '/path/to/image.png',
                        'didn\'t change extension')
Пример #4
0
    def test_no_change_test(self):
        """plotextractor - get_converted_image_name no change"""
        image = '/path/to/image.png'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == image, 'didn\'t notice image was already ' + \
                                       'converted')
    def test_change_extension_test(self):
        """plotextractor - get_converted_image_name extension"""
        image = '/path/to/image.eps'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == '/path/to/image.png',
                        "didn't change extension")
    def test_dot_in_dir_name_no_ext_test(self):
        """plotextractor - get_converted_image_name dot in dir name"""
        image = '/path.to/the/image'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == image + '.png',
                        "didn't add extension")
Пример #7
0
def convert_images(image_list):
    '''
    Here we figure out the types of the images that were extracted from
    the tarball and determine how to convert them into PNG.

    @param: image_list ([string, string, ...]): the list of image files
        extracted from the tarball in step 1

    @return: image_list ([str, str, ...]): The list of image files when all
        have been converted to PNG format.
    '''

    png_output_contains = 'PNG image data'
    ps_output_contains = 'Postscript'
    eps_output_contains = 'PostScript'

    ret_list = []

    for image_file in image_list:
        if os.path.isdir(image_file):
            continue

        # FIXME: here and everywhere else in the plot extractor
        # library the run shell command statements should be (1)
        # called with timeout in order to prevent runaway imagemagick
        # conversions; (2) the arguments should be passed properly so
        # that they are escaped.

        dummy1, cmd_out, dummy2 = run_shell_command('file ' + image_file)
        if cmd_out.find(png_output_contains) > -1:
            ret_list.append(image_file)
        else:
            # we're just going to assume that ImageMagick can convert all
            # the image types that we may be faced with
            # for sure it can do EPS->PNG and JPG->PNG and PS->PNG
            # and PSTEX->PNG
            converted_image_file = get_converted_image_name(image_file)

            convert_cmd = 'convert '

            dummy1, cmd_out, cmd_err = run_shell_command(convert_cmd +\
                    image_file + ' ' + converted_image_file)
            if cmd_err == '':
                ret_list.append(converted_image_file)
            else:
                write_message('convert failed on ' + image_file)

    return ret_list
def convert_images(image_list):
    """
    Here we figure out the types of the images that were extracted from
    the tarball and determine how to convert them into PNG.

    @param: image_list ([string, string, ...]): the list of image files
        extracted from the tarball in step 1

    @return: image_list ([str, str, ...]): The list of image files when all
        have been converted to PNG format.
    """
    png_output_contains = 'PNG image'
    ret_list = []
    for image_file in image_list:
        if os.path.isdir(image_file):
            continue

        # FIXME: here and everywhere else in the plot extractor
        # library the run shell command statements should be (1)
        # called with timeout in order to prevent runaway imagemagick
        # conversions; (2) the arguments should be passed properly so
        # that they are escaped.

        dummy1, cmd_out, dummy2 = run_shell_command('file %s', (image_file,))
        if cmd_out.find(png_output_contains) > -1:
            ret_list.append(image_file)
        else:
            # we're just going to assume that ImageMagick can convert all
            # the image types that we may be faced with
            # for sure it can do EPS->PNG and JPG->PNG and PS->PNG
            # and PSTEX->PNG
            converted_image_file = get_converted_image_name(image_file)
            try:
                dummy1, cmd_out, cmd_err = run_process_with_timeout('convert %s %s'\
                                                   % (image_file, \
                                                      converted_image_file), shell = True)
                if cmd_err == '':
                    ret_list.append(converted_image_file)
                else:
                    write_message('convert failed on ' + image_file)
            except Timeout:
                write_message('convert timed out on ' + image_file)

    return ret_list
Пример #9
0
    def test_change_extension_test(self):
        image = '/path/to/image.eps'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == '/path/to/image.png', 'didn\'t change extension')
Пример #10
0
    def test_dot_in_dir_name_no_ext_test(self):
        image = '/path.to/the/image'

        converted_image = get_converted_image_name(image)
        self.assertTrue(converted_image == image + '.png', 'didn\'t add extension')