def generate(): """ POST route, generate pdf """ songs = request.forms.getall('songs') subtitle = request.forms.get('subtitle') # Generate yaml and parse it songbook_yaml = template('songbook_yaml', songs=songs, PATADATA=PATADATA, subtitle=subtitle) songbook_raw = yaml.load(songbook_yaml) # Create temp directory and operate patacrep magic outputdir = tempfile.mkdtemp() outputname = 'songbook' with cd(outputdir): songbook = prepare_songbook(songbook_raw, outputdir=outputdir, outputname=outputname, datadir_prefix=PATADATA) songbook['_cache'] = False songbook['_error'] = "failonbook" builder = SongbookBuilder(songbook) builder.unsafe = True builder.build_steps(DEFAULT_STEPS) # Read outputed PDF and delete temp directory with open(os.path.join(outputdir, outputname + '.pdf'), 'rb') as f: pdf = f.read() shutil.rmtree(outputdir) # Send pdf response.content_type = 'application/pdf' return pdf
def compile_songbook_onthefly(base, steps=None): """Compile songbook "on the fly": without a physical songbook file.""" with open(base + ".yaml", mode="r", encoding="utf8") as sbfile: sbyaml = yaml.safe_load(sbfile) outputdir = os.path.dirname(base) outputname = os.path.basename(base) datadir_prefix = os.path.join(outputdir, '..') songbook = prepare_songbook(sbyaml, outputdir, outputname, datadir_prefix=datadir_prefix) songbook['_error'] = "fix" songbook['_cache'] = True sb_builder = SongbookBuilder(songbook) sb_builder.unsafe = True with chdir(outputdir): # Continuous Integration will be verbose if 'CI' in os.environ: with logging_reduced(level=logging.DEBUG): sb_builder.build_steps(steps) else: sb_builder.build_steps(steps)
def _generate_config(cls, sbcontent, outputdir, base): """Generate the config to process the content""" # Load the default songbook config config = prepare_songbook( {'book':{'datadir':['datadir', 'datadir_zippedcontent']}, 'content': sbcontent}, outputdir, base, outputdir ) return config
def _generate_config(cls, sbcontent, outputdir, base): """Generate the config to process the content""" # Load the default songbook config config = prepare_songbook( {'book':{'datadir':'datadir'}, 'content': sbcontent}, outputdir, base, outputdir ) return config
def compile_songbook_onthefly(base, steps=None): """Compile songbook "on the fly": without a physical songbook file.""" with open(base + ".yaml", mode="r", encoding="utf8") as sbfile: sbyaml = yaml.load(sbfile) outputdir = os.path.dirname(base) outputname = os.path.basename(base) datadir_prefix = os.path.join(outputdir, '..') songbook = prepare_songbook(sbyaml, outputdir, outputname, datadir_prefix=datadir_prefix) songbook['_error'] = "fix" songbook['_cache'] = True sb_builder = SongbookBuilder(songbook) sb_builder.unsafe = True with chdir(outputdir): # Continuous Integration will be verbose if 'CI' in os.environ: with logging_reduced(level=logging.DEBUG): sb_builder.build_steps(steps) else: sb_builder.build_steps(steps)
def _generate_config(cls, sbcontent, outputdir, base): """Generate the config to process the content""" # Load the default songbook config config = prepare_songbook( {'book':{'datadir':'datadir'}, 'content': sbcontent}, outputdir, base, outputdir ) # Load the plugins config['_content_plugins'] = files.load_plugins( datadirs=config['_datadir'], root_modules=['content'], keyword='CONTENT_PLUGINS', ) config['_song_plugins'] = files.load_plugins( datadirs=config['_datadir'], root_modules=['songs'], keyword='SONG_RENDERERS', )['tsg'] return config