def _convert_plots(self, workdir, imgFormat, files):
        """ This method converts the postscript plots to imgFormat
        """
        splitPath = list()
        psFiles = list()
        psFiles = sorted(files)

        # check if the convert command exists
        rc = cesmEnvLib.which('convert')
        if rc is not None and imgFormat.lower() in ['png', 'gif']:
            for psFile in psFiles:

                sourceFile = '{0}/{1}.ps'.format(workdir, psFile)
                ##                print('...... convert source file {0}'.format(sourceFile))

                # check if the image file alreay exists and remove it to regen
                imgFile = '{0}/{1}.{2}'.format(workdir, psFile, imgFormat)
                rc, err_msg = cesmEnvLib.checkFile(imgFile, 'write')
                if rc:
                    print('...... removing {0} before recreating'.format(
                        imgFile))
                    os.remove(imgFile)

                # convert the image from ps to imgFormat
                try:
                    pipe = subprocess.check_call([
                        'convert', '-trim', '-bordercolor', 'white', '-border',
                        '5x5', '-density', '95', '{0}'.format(sourceFile),
                        '{0}'.format(imgFile)
                    ])
##                   print('...... created {0} size = {1}'.format(imgFile, os.path.getsize(imgFile)))
                except subprocess.CalledProcessError as e:
                    print('...... failed to create {0}'.format(imgFile))
                    print(
                        'WARNING: convert_plots call to convert failed with error:'
                    )
                    print('    {0}'.format(e.output))
                else:
                    continue
        else:
            # TODO - need to create a script template to convert the plots
            print(
                'WARNING: convert_plots unable to find convert command in path.'
            )
            print('     Unable to convert ps formatted plots to {0}'.format(
                imgFormat))
            print(
                'Run the following command from a node with convert installed....'
            )
Exemplo n.º 2
0
    def _convert_plots(self, workdir, imgFormat, files):
        """ This method converts the postscript plots to imgFormat
        """
        splitPath = list()
        psFiles = list()
        psFiles = sorted(files)

        # check if the convert command exists
        rc = cesmEnvLib.which('convert')
        if rc is not None and imgFormat.lower() in ['png','gif']:
            for psFile in psFiles:

                sourceFile = '{0}/{1}.ps'.format(workdir, psFile)
##                print('...... convert source file {0}'.format(sourceFile))

                # check if the image file alreay exists and remove it to regen
                imgFile = '{0}/{1}.{2}'.format(workdir, psFile, imgFormat)
                rc, err_msg = cesmEnvLib.checkFile(imgFile,'write')
                if rc:
                    print('...... removing {0} before recreating'.format(imgFile))
                    os.remove(imgFile)

                # convert the image from ps to imgFormat
                try:
                    pipe = subprocess.check_call( ['convert', '-trim', '-bordercolor', 'white', '-border', '5x5', '-density', '95', '{0}'.format(sourceFile),'{0}'.format(imgFile)])
##                   print('...... created {0} size = {1}'.format(imgFile, os.path.getsize(imgFile)))
                except subprocess.CalledProcessError as e:
                    print('...... failed to create {0}'.format(imgFile))
                    print('WARNING: convert_plots call to convert failed with error:')
                    print('    {0}'.format(e.output))
                else:
                    continue
        else:
            # TODO - need to create a script template to convert the plots
            print('WARNING: convert_plots unable to find convert command in path.')
            print('     Unable to convert ps formatted plots to {0}'.format(imgFormat))
            print('Run the following command from a node with convert installed....')