def htmlAllViewSave(name): htmlFile = open("combineTemplate.html") t = templite.Templite(htmlFile.read()) htmlFile.close() text = t.render(htmlMsg) outputHtml = open(name, mode='w+') outputHtml.write(text) outputHtml.close()
def main(argc, argv): parser = argparse.ArgumentParser( "Generate C++ amalgamation from C++ Table Plugin targets") parser.add_argument("--foreign", default=False, action="store_true", help="Generate a foreign table set amalgamation") parser.add_argument("--templates", help="Path to codegen output .cpp.in templates") parser.add_argument("--category", help="Category name of generated tables") parser.add_argument("--sources", help="Path to the folder containing the .cpp files") parser.add_argument("--output", help="Path to the output .cpp files") args = parser.parse_args() tables = [] # Discover the output template, usually a black cpp file with includes. template = os.path.join(args.templates, TEMPLATE_NAME) with open(template, "r") as fh: template_data = fh.read() for base, _, filenames in os.walk(args.sources): for filename in filenames: if filename == args.category: continue table_data = genTableData(os.path.join(base, filename)) if table_data is not None: tables.append(table_data) amalgamation = templite.Templite(template_data).render( tables=tables, foreign=args.foreign) try: os.makedirs(os.path.dirname(args.output)) except OSError: # Generated folder already exists pass with open(args.output, "w") as fh: fh.write(amalgamation) return 0
def generate(self, path, template="default"): """Generate the virtual table files""" logging.debug("TableState.generate") all_options = [] # Create a list of column options from the kwargs passed to the column. for column in self.columns(): column_options = [] for option in column.options: # Only allow explicitly-defined options. if option in COLUMN_OPTIONS: column_options.append("ColumnOptions::" + COLUMN_OPTIONS[option]) all_options.append(COLUMN_OPTIONS[option]) else: print( yellow( "Table %s column %s contains an unknown option: %s" % (self.table_name, column.name, option))) column.options_set = " | ".join(column_options) if len(column.aliases) > 0: self.has_column_aliases = True if len(all_options) > 0: self.has_options = True if "event_subscriber" in self.attributes: self.generator = True if "strongly_typed_rows" in self.attributes: self.strongly_typed_rows = True if "cacheable" in self.attributes: if self.generator: print( lightred( "Table cannot use a generator and be marked cacheable: %s" % (path))) exit(1) if self.table_name == "" or self.function == "": print(lightred("Invalid table spec: %s" % (path))) exit(1) # Check for reserved column names for column in self.columns(): if column.name in RESERVED: print( lightred(("Cannot use column name: %s in table: %s " "(the column name is reserved)" % (column.name, self.table_name)))) exit(1) path_bits = path.split("/") for i in range(1, len(path_bits)): dir_path = "" for j in range(i): dir_path += "%s/" % path_bits[j] if not os.path.exists(dir_path): try: os.mkdir(dir_path) except: # May encounter a race when using a make jobserver. pass logging.debug("generating %s" % path) self.impl_content = templite.Templite(TEMPLATES[template]).render( table_name=self.table_name, table_name_cc=to_camel_case(self.table_name), table_name_ucc=to_upper_camel_case(self.table_name), schema=self.columns(), header=self.header, impl=self.impl, function=self.function, class_name=self.class_name, attributes=self.attributes, examples=self.examples, aliases=self.aliases, has_options=self.has_options, has_column_aliases=self.has_column_aliases, generator=self.generator, strongly_typed_rows=self.strongly_typed_rows, attribute_set=[ TABLE_ATTRIBUTES[attr] for attr in self.attributes if attr in TABLE_ATTRIBUTES ], ) with open(path, "w+") as file_h: file_h.write(self.impl_content)
parser.add_argument('--config', type=argparse.FileType('r'), help='Json configuration file to store template variables') parser.add_argument('--outfile', required=True, help='output file') parser.add_argument('markdown', type=argparse.FileType('r'), help='Markdown file to render') args = vars(parser.parse_args()) if 'config' in args: config_args = json.load(args.pop('config')) for k, v in config_args.items(): if k not in args: args[k] = v # Create CSS css_template_path = os.path.join(args['templates_path'], 'css.tpl') t = templite.Templite(open(css_template_path).read()) outdir = os.path.dirname(args['outfile']) with open(os.path.join(outdir, args['stylesheet']), 'w') as css: css.write(t.render(**args)) # Create HTML content args['content'] = markdown.markdown(args['markdown'].read(), extensions=['markdown.extensions.tables', 'pymdownx.inlinehilite', 'pymdownx.keys',]) html_template_path = os.path.join(args['templates_path'], 'html.tpl') t = templite.Templite(open(html_template_path).read()) with open(args['outfile'], 'w') as outfile: outfile.write(t.render(**args))