#!/usr/bin/env python # -*- coding: utf-8 -*- # import jinja2 import optparse import os import sys BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) sys.path.insert(0, BASEPATH) import reqif if __name__ == '__main__': parser = optparse.OptionParser("usage: %prog reqif_file") parser.add_option("-t", "--template", dest="template", default=os.path.join(BASEPATH, 'reqif', 'templates', 'tex', 'requirement_specification.tex'), help="path to the template") (options, args) = parser.parse_args() # # Check options and args if len(args) != 1 or not os.path.isfile(args[0]): parser.print_help() else: reqif_path = args[0] template_path = os.path.abspath(options.template) output_path = os.path.splitext(reqif_path)[0] + os.path.splitext(template_path)[1] if reqif_path == output_path: sys.exit('ERROR: Source and Destination would be the same file') # reqif_data = reqif.reqif_dict(reqif_path, 'Heading', 'Software Specification') # with open(output_path, 'w') as fh: jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(template_path))) template = jenv.get_template(os.path.basename(template_path)) fh.write(template.render(data=reqif_data))