Пример #1
0
def convert_binary(openfile,ToFormat,FromFormat,extra_args):
    # ReturnValues: OpenedText, ToFormat, FromFormat, ExtraArguments (divided by blanks, if empty, use '')

    try:
        path_pandoc = get_path_pandoc()


        args = [path_pandoc, '--from=' + FromFormat, '--to=' + ToFormat, openfile]

        if extra_args is not '' :
            extra_args = extra_args.split(';')
            for arg in extra_args:
                args.append(arg)

        get_pandoc_formats()

        from_formats, to_formats = get_pandoc_formats()

        if FromFormat not in from_formats:
            QtWidgets.QMessageBox.warning(None, 'Warning-Message',
                                          'Invalid from format! Expected one of these: ' + ', '.join(from_formats))

        if ToFormat not in to_formats:
            QtWidgets.QMessageBox.warning(None, 'Warning-Message',
                                          'Invalid to format! Expected one of these: ' + ', '.join(to_formats))

        output = 'If you can read this message, something went wrong. Get some help at ' \
                 'http://panconvert.sourceforge.net/help'

        p = subprocess.Popen(
                args,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)

        output1, error1 = p.communicate(output.encode('utf-8'))
        output = output1.decode('utf-8')
        error = error1.decode('utf-8')

        if p.returncode != 0:
            QtWidgets.QMessageBox.warning(None, 'Error-Message',
                                          'An Error occurred. <br><br>{}'.format(error))
        else:
            if output != '':
                return output
            else:
                message = 'There was no visible output. Did you write output to the filesystem?' \
                          ' Please look in the folder of PanConvert for some output-file'
                return message


        #return p.communicate(output.encode('utf-8'))[0].decode('utf-8')

    except OSError:
        QtWidgets.QMessageBox.warning(None, 'Error-Message',
                                          'Pandoc could not be found on your System. Is it installed?'
                                          'If so, please check the Pandoc Path in your Preferences.')
Пример #2
0
def batch_convert_manual(openfile,FromFormat,ToFormat,extra_args):
    # ReturnValues: OpenedText, ToFormat, FromFormat, ExtraArguments (divided by blanks, if empty, use '')

    try:
        path_pandoc = get_path_pandoc()

        if extra_args is '':
            args = [path_pandoc, '--from=' + FromFormat, '--to=' + ToFormat, openfile, '--output=' + openfile + '.' + ToFormat]
        else:
            args = [path_pandoc, '--from=' + FromFormat, '--to=' + ToFormat, openfile, '--output=' + openfile + '.' + ToFormat, extra_args]

        if extra_args is not '' :
            extra_args = extra_args.split(';')
            for arg in extra_args:
                args.append(arg)

        get_pandoc_formats()

        from_formats, to_formats = get_pandoc_formats()

        if FromFormat not in from_formats:
            QtWidgets.QMessageBox.warning(None, 'Warning-Message',
                                          'Invalid from format! Expected one of these: ' + ', '.join(from_formats))

        if ToFormat not in to_formats:
            QtWidgets.QMessageBox.warning(None, 'Warning-Message',
                                          'Invalid to format! Expected one of these: ' + ', '.join(to_formats))

        output = 'If you can read this message, something went wrong. Get some help at ' \
                 'http://panconvert.sourceforge.net/help'

        p = subprocess.Popen(
                args,
                stdin=subprocess.PIPE,
                #stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)

        error1 = p.communicate(output.encode('utf-8'))

        #error = error1.decode('utf-8')
        message = '\n Converted files should have been written to the same place as the original files.' \
                  ' \n There is no visual output. So please check your converted files at the filesystem level.' \
                  '\n \n When in batch-file-mode, for a better experience, please clear the window before starting a new conversion'
        error = ''


        if p.returncode != 0:
            result = ''
            error = 'An Error occurred. <br><br>{}'.format(error1)
            QtWidgets.QMessageBox.warning(None, 'Error-Message',
                                          'An Error occurred. <br><br>{}'.format(error1))




        return message


        #return p.communicate(output.encode('utf-8'))[0].decode('utf-8')

    except OSError:
        QtWidgets.QMessageBox.warning(None, 'Error-Message',
                                          'Pandoc could not be found on your System. Is it installed?'
                                          'If so, please check the Pandoc Path in your Preferences.')