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'}
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'}
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()
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()
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()