def generate_derived_spatial_entity_file(environment, template_path, output_folder, spatial_entity_name): """Generate the derived spatial entity source file Keyword argument: environment -- the environment for loading templates template_path -- path to the template file output_folder -- path to the output folder spatial_entity_name -- the name of the spatial entity """ # Assert the validity of the input parameters assert environment is not None assert isinstance(template_path, str) and len(template_path) > 0 assert isinstance(output_folder, str) and len(output_folder) > 0 assert (isinstance(spatial_entity_name, str) and len(spatial_entity_name) > 0) # Load and get a reference to the template template = environment.get_template(template_path) # Initialize output_path output_path = output_folder + first_to_upper(spatial_entity_name) + str( EXT_HEADER_FILE ) # Generate source file from template with open(output_path, "w+") as output_file: output_file.write( template.render({ TAG_WRN_AUTO_GENERATED_FILE : WRN_AUTO_GENERATED_FILE, TAG_UNIT_TESTS_NR_OF_TIMEPOINTS : UNIT_TESTS_NR_OF_TIMEPOINTS, TAG_SPATIAL_ENTITY_NAME : spatial_entity_name }) )
def generate_spatial_entities_and_measures_dependent_file(environment, template_path, output_path, spatial_entities, spatial_measures): """Generate the source file dependent on the collection of spatial entities and spatial measures Keyword argument: environment -- the environment for loading templates template_path -- path to the template file output_path -- path to the output file spatial_entities -- the list of spatial entities spatial_measures -- the list of spatial measures """ # Assert the validity of the input parameters assert environment is not None assert isinstance(template_path, str) and len(template_path) > 0 assert isinstance(output_path, str) and len(output_path) > 0 assert isinstance(spatial_entities, list) and len(spatial_entities) > 0 assert isinstance(spatial_measures, list) and len(spatial_measures) > 0 # Load and get a reference to the template template = environment.get_template(template_path) # Generate source file from template with open(output_path, "w+") as output_file: output_file.write( template.render({ TAG_WRN_AUTO_GENERATED_FILE : WRN_AUTO_GENERATED_FILE, TAG_UNIT_TESTS_NR_OF_TIMEPOINTS : UNIT_TESTS_NR_OF_TIMEPOINTS, TAG_SPATIAL_ENTITIES : spatial_entities, TAG_SPATIAL_MEASURES : spatial_measures }) )
def root(context, environment=environment): parent_template = None if 0: yield None parent_template = environment.get_template('core/__base.html', '/source/landing.html') for name, parent_block in parent_template.blocks.iteritems(): context.blocks.setdefault(name, []).append(parent_block) for event in parent_template.root_render_func(context): yield event
def print_changelog(entries, headers, output_format, output_file=None): """ Render the changelog report :param entries: typically commit objects :param headers: release headers (dictionary with release tag as key) :param output_format: string, e.g. 'rpm' or 'deb' :param output_file: optional; file name to write to. By default write to standard output :return: n/a """ environment = init_jinja_env() template = environment.get_template(output_format) output = template.render(entries=entries, headers=headers) if output_file: with open(output_file, 'w') as ofile: ofile.write(output) else: print(output)
def block_js_pageobject(context, environment=environment): l_security = context.resolve('security') l_page = context.resolve('page') l_transport = context.resolve('transport') if 0: yield None included_template = environment.get_template( 'macros/apptools.html', '/source/core/__base.html').module l_build_native_page_object = getattr(included_template, 'build_native_page_object', missing) if l_build_native_page_object is missing: l_build_native_page_object = environment.undefined( "the template %r (imported on line 77 in '/source/core/__base.html') does not export the requested name 'build_native_page_object'" % included_template.__name__, name='build_native_page_object') yield u'\n ' yield to_string( context.call(l_build_native_page_object, l_page, l_transport, l_security))