Exemplo n.º 1
0
def preview():
    input = StringIO(request.form.get('in-juben-text'))
    has_scene_num = bool(request.form.get('in-has-scene-num'))
    first_page_number = bool(request.form.get('in-first-page-num'))
    strong_scene_heading = bool(request.form.get('in-strong-scene-heading'))
    first_line_indent = bool(request.form.get('in-first-line-indent'))
    in_lang = request.form.get('in-lang')
    tmp_file = tempfile.SpooledTemporaryFile()
    suffix = "pdf"
    try:
        if in_lang == 'zh':
            input = normalize.parse(input, first_line_indent)
        filename = input.readline().replace("Title:", '').strip()
        input.seek(0)
        screenplay = fountain.parse(input)
        if in_lang == 'zh':
            to_pdf(screenplay, tmp_file._file, is_strong=strong_scene_heading, has_scene_num=has_scene_num, first_page_number=first_page_number, first_line_indent=first_line_indent)
        else:
            to_en_pdf(screenplay, tmp_file._file, is_strong=strong_scene_heading)
        tmp_file.seek(0)
        encoded_string = base64.b64encode(tmp_file.read()).decode('ascii')
        r = make_response('{"filename":"' + filename + '", "suffix":"' + suffix + '", "content":"' + encoded_string + '"}')
        r.headers['Content-Type'] = 'text/plain; charset=UTF-8'
        return r
    except:
        return locales().get('_')('Invalid Format'), 500
    finally:
        if tmp_file:
           tmp_file.close()
Exemplo n.º 2
0
def screenplay_export(context, screenplay_filepath, opt_exp, open_browser):

    import os
    dir = os.path.dirname(bpy.data.filepath)
    if not dir in sys.path:
        sys.path.append(dir)

    fountain_script = bpy.context.area.spaces.active.text.as_string()
    if fountain_script.strip() == "": return {"CANCELLED"}

    # screenplain
    try:
        import screenplain
    except ImportError:
        print('Installing screenplain module (this is only required once)...')
        import urllib.request as urllib
        import zipfile
        import shutil

        url = 'https://github.com/vilcans/screenplain/archive/0.8.0.zip'
        home_url = bpy.utils.script_path_user() + "\\addons\\"
        urllib.urlretrieve(url, home_url + 'screenplain-0.8.0.zip')
        with zipfile.ZipFile(home_url + 'screenplain-0.8.0.zip', 'r') as z:
            z.extractall(home_url)
        target_dir = home_url
        shutil.move(home_url + 'screenplain-0.8.0/screenplain', target_dir)
        os.remove(home_url + 'screenplain-0.8.0.zip')
        shutil.rmtree(home_url + 'screenplain-0.8.0')
        import screenplain

    import screenplain.parsers.fountain as fountain
    from io import StringIO
    import webbrowser
    s = StringIO(fountain_script)
    screenplay = fountain.parse(s)
    output = StringIO()
    if opt_exp == "HTML":
        from screenplain.export.html import convert
        convert(screenplay, output, bare=False)
    if opt_exp == "FDX":
        from screenplain.export.fdx import to_fdx
        to_fdx(screenplay, output)
    if opt_exp == "PDF":
        from screenplain.export.pdf import to_pdf
        to_pdf(screenplay, output)
    sp_out = output.getvalue()
    filename, extension = os.path.splitext(screenplay_filepath)
    fileout_name = filename + "." + opt_exp.lower()
    file = open(fileout_name, "w")
    file.write(sp_out)
    file.close()
    if open_browser:
        if opt_exp == "HTML" or opt_exp == "PDF":
            webbrowser.open(fileout_name)

    return {'FINISHED'}
Exemplo n.º 3
0
def screenplay_export(context, screenplay_filepath, opt_exp, open_browser):

    import subprocess, os
    dir = os.path.dirname(bpy.data.filepath)
    if not dir in sys.path:
        sys.path.append(dir)

    fountain_script = bpy.context.area.spaces.active.text.as_string()
    if fountain_script.strip() == "": return {"CANCELLED"}

    # screenplain
    pybin = sys.executable  #bpy.app.binary_path_python #
    try:
        subprocess.call([pybin, "-m", "ensurepip"])
    except ImportError:
        pass
    try:
        import screenplain.parsers.fountain as fountain
    except ImportError:
        subprocess.check_call(
            [pybin, '-m', 'pip', 'install', 'screenplain[PDF]'])
        import screenplain.parsers.fountain as fountain

    from io import StringIO
    import webbrowser
    s = StringIO(fountain_script)
    screenplay = fountain.parse(s)
    output = StringIO()
    filename, extension = os.path.splitext(screenplay_filepath)
    fileout_name = filename + "." + opt_exp.lower()

    if opt_exp == "HTML" or opt_exp == "FDX":
        if opt_exp == "HTML":
            from screenplain.export.html import convert
            convert(screenplay, output, bare=False)
        elif opt_exp == "FDX":
            from screenplain.export.fdx import to_fdx
            to_fdx(screenplay, output)
        sp_out = output.getvalue()
        file = open(fileout_name, "w")
        file.write(sp_out)
        file.close()
    elif opt_exp == "PDF":
        from screenplain.export.pdf import to_pdf
        to_pdf(screenplay, fileout_name)

    if open_browser:
        if opt_exp == "HTML" or opt_exp == "PDF":
            webbrowser.open(fileout_name)

    return {'FINISHED'}
Exemplo n.º 4
0
def parse(lines):
    content = '\n'.join(lines)
    return list(fountain.parse(StringIO(content)))
Exemplo n.º 5
0
def main(args):
    parser = OptionParser(usage=usage)
    parser.add_option(
        '-f', '--format', dest='output_format',
        metavar='FORMAT',
        help=(
            'Set what kind of file to create. FORMAT can be one of ' +
            ', '.join(output_formats)
        )
    )
    parser.add_option(
        '--bare',
        action='store_true',
        dest='bare',
        help=(
            'For HTML output, only output the actual screenplay, '
            'not a complete HTML document.'
        )
    )
    options, args = parser.parse_args(args)
    if len(args) >= 3:
        parser.error('Too many arguments')
    input_file = (len(args) > 0 and args[0] != '-') and args[0] or None
    output_file = (len(args) > 1 and args[1] != '-') and args[1] or None

    format = options.output_format
    if format is None and output_file:
        if output_file.endswith('.fdx'):
            format = 'fdx'
        elif output_file.endswith('.html'):
            format = 'html'
        elif output_file.endswith('.pdf'):
            format = 'pdf'
        else:
            invalid_format(
                parser,
                'Could not detect output format from file name ' + output_file
            )

    if format not in output_formats:
        invalid_format(
            parser, 'Unsupported output format: "%s".' % format
        )

    if input_file:
        input = codecs.open(input_file, 'r', 'utf-8')
    else:
        input = codecs.getreader('utf-8')(sys.stdin)
    screenplay = fountain.parse(input)

    if format == 'pdf':
        from screenplain.export.pdf import to_pdf
        if not output_file:
            sys.stderr.write("Can't write PDF to standard output")
            sys.exit(2)
        to_pdf(screenplay, output_file)
    else:
        if output_file:
            output = codecs.open(output_file, 'w', 'utf-8')
        else:
            output = codecs.getwriter('utf-8')(sys.stdout)
        try:
            if format == 'text':
                from screenplain.export.text import to_text
                to_text(screenplay, output)
            elif format == 'fdx':
                from screenplain.export.fdx import to_fdx
                to_fdx(screenplay, output)
            elif format == 'html':
                from screenplain.export.html import convert
                convert(screenplay, output, bare=options.bare)
        finally:
            if output_file:
                output.close()
Exemplo n.º 6
0
def main(args):
    parser = OptionParser(usage=usage)
    parser.add_option(
        '-f', '--format', dest='output_format',
        metavar='FORMAT',
        help=(
            'Set what kind of file to create. FORMAT can be one of ' +
            ', '.join(output_formats)
        )
    )
    parser.add_option(
        '--bare',
        action='store_true',
        dest='bare',
        help=(
            'For HTML output, only output the actual screenplay, '
            'not a complete HTML document.'
        )
    )
    parser.add_option(
        '--css',
        metavar='FILE',
        help=(
            'For HTML output, inline the given CSS file in the HTML document '
            'instead of the default.'
        )
    )
    parser.add_option(
        '--strong',
        action='store_true',
        dest='strong',
        help=(
            'For PDF output, scene headings will appear '
            'Bold and Underlined.'
        )
    )
    options, args = parser.parse_args(args)
    if len(args) >= 3:
        parser.error('Too many arguments')
    input_file = (len(args) > 0 and args[0] != '-') and args[0] or None
    output_file = (len(args) > 1 and args[1] != '-') and args[1] or None

    format = options.output_format
    if format is None and output_file:
        if output_file.endswith('.fdx'):
            format = 'fdx'
        elif output_file.endswith('.html'):
            format = 'html'
        elif output_file.endswith('.pdf'):
            format = 'pdf'
        else:
            invalid_format(
                parser,
                'Could not detect output format from file name ' + output_file
            )

    if format not in output_formats:
        invalid_format(
            parser, 'Unsupported output format: "%s".' % format
        )

    if input_file:
        input = codecs.open(input_file, 'r', 'utf-8-sig')
    else:
        input = codecs.getreader('utf-8')(sys.stdin)
    screenplay = fountain.parse(input)

    if format == 'pdf':
        output_encoding = None
    else:
        output_encoding = 'utf-8'

    if output_file:
        if output_encoding:
            output = codecs.open(output_file, 'w', output_encoding)
        else:
            output = open(output_file, 'wb')
    else:
        if output_encoding:
            output = codecs.getwriter(output_encoding)(sys.stdout)
        else:
            output = sys.stdout

    try:
        if format == 'text':
            from screenplain.export.text import to_text
            to_text(screenplay, output)
        elif format == 'fdx':
            from screenplain.export.fdx import to_fdx
            to_fdx(screenplay, output)
        elif format == 'html':
            from screenplain.export.html import convert
            convert(
                screenplay, output,
                css_file=options.css, bare=options.bare
            )
        elif format == 'pdf':
            from screenplain.export.pdf import to_pdf
            to_pdf(screenplay, output, is_strong=options.strong)
    finally:
        if output_file:
            output.close()
Exemplo n.º 7
0
def parse(lines):
    content = '\n'.join(lines)
    return fountain.parse(StringIO(content))
Exemplo n.º 8
0
def main(args):
    parser = OptionParser(usage=usage)
    parser.add_option(
        '-f', '--format', dest='output_format',
        metavar='FORMAT',
        help=(
            'Set what kind of file to create. FORMAT can be one of ' +
            ', '.join(output_formats)
        )
    )
    parser.add_option(
        '--bare',
        action='store_true',
        dest='bare',
        help=(
            'For HTML output, only output the actual screenplay, '
            'not a complete HTML document.'
        )
    )
    options, args = parser.parse_args(args)
    if len(args) >= 3:
        parser.error('Too many arguments')
    input_file = (len(args) > 0 and args[0] != '-') and args[0] or None
    output_file = (len(args) > 1 and args[1] != '-') and args[1] or None

    format = options.output_format
    if format is None and output_file:
        if output_file.endswith('.fdx'):
            format = 'fdx'
        elif output_file.endswith('.html'):
            format = 'html'
        elif output_file.endswith('.pdf'):
            format = 'pdf'
        else:
            invalid_format(
                parser,
                'Could not detect output format from file name ' + output_file
            )

    if format not in output_formats:
        invalid_format(
            parser, 'Unsupported output format: "%s".' % format
        )

    if input_file:
        input = codecs.open(input_file, 'r', 'utf-8')
    else:
        input = codecs.getreader('utf-8')(sys.stdin)
    screenplay = fountain.parse(input)

    if format == 'pdf':
        from screenplain.export.pdf import to_pdf
        if not output_file:
            sys.stderr.write("Can't write PDF to standard output")
            sys.exit(2)
        to_pdf(screenplay, output_file)
    else:
        if output_file:
            output = codecs.open(output_file, 'w', 'utf-8')
        else:
            output = codecs.getwriter('utf-8')(sys.stdout)
        try:
            if format == 'text':
                from screenplain.export.text import to_text
                to_text(screenplay, output)
            elif format == 'fdx':
                from screenplain.export.fdx import to_fdx
                to_fdx(screenplay, output)
            elif format == 'html':
                from screenplain.export.html import convert
                convert(screenplay, output, bare=options.bare)
        finally:
            if output_file:
                output.close()
Exemplo n.º 9
0
def main(args):
    parser = OptionParser(usage=usage)
    parser.add_option(
        '-f',
        '--format',
        dest='output_format',
        metavar='FORMAT',
        help=('Set what kind of file to create. FORMAT can be one of ' +
              ', '.join(output_formats)))
    parser.add_option(
        '--bare',
        action='store_true',
        dest='bare',
        help=('For HTML output, only output the actual screenplay, '
              'not a complete HTML document.'))
    parser.add_option(
        '--css',
        metavar='FILE',
        help=(
            'For HTML output, inline the given CSS file in the HTML document '
            'instead of the default.'))
    parser.add_option('--strong',
                      action='store_true',
                      dest='strong',
                      help=('For PDF output, scene headings will appear '
                            'Bold and Underlined.'))
    options, args = parser.parse_args(args)
    if len(args) >= 3:
        parser.error('Too many arguments')
    input_file = (len(args) > 0 and args[0] != '-') and args[0] or None
    output_file = (len(args) > 1 and args[1] != '-') and args[1] or None

    format = options.output_format
    if format is None and output_file:
        if output_file.endswith('.fdx'):
            format = 'fdx'
        elif output_file.endswith('.html'):
            format = 'html'
        elif output_file.endswith('.pdf'):
            format = 'pdf'
        else:
            invalid_format(
                parser,
                'Could not detect output format from file name ' + output_file)

    if format not in output_formats:
        invalid_format(parser, 'Unsupported output format: "%s".' % format)

    if input_file:
        input = codecs.open(input_file, 'r', 'utf-8-sig')
    else:
        input = codecs.getreader('utf-8')(sys.stdin)
    screenplay = fountain.parse(input)

    if format == 'pdf':
        output_encoding = None
    else:
        output_encoding = 'utf-8'

    if output_file:
        if output_encoding:
            output = codecs.open(output_file, 'w', output_encoding)
        else:
            output = open(output_file, 'wb')
    else:
        if output_encoding:
            output = codecs.getwriter(output_encoding)(sys.stdout.buffer)
        else:
            output = sys.stdout.buffer

    try:
        if format == 'text':
            from screenplain.export.text import to_text
            to_text(screenplay, output)
        elif format == 'fdx':
            from screenplain.export.fdx import to_fdx
            to_fdx(screenplay, output)
        elif format == 'html':
            from screenplain.export.html import convert
            convert(screenplay,
                    output,
                    css_file=options.css,
                    bare=options.bare)
        elif format == 'pdf':
            from screenplain.export.pdf import to_pdf
            to_pdf(screenplay, output, is_strong=options.strong)
    finally:
        if output_file:
            output.close()