Python Library REQ-IF
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

parse.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import jinja2
  5. import optparse
  6. import os
  7. import sys
  8. BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
  9. sys.path.insert(0, BASEPATH)
  10. import reqif
  11. if __name__ == '__main__':
  12. parser = optparse.OptionParser("usage: %prog reqif_file")
  13. parser.add_option("-t", "--template", dest="template", default=os.path.join(BASEPATH, 'reqif', 'templates', 'tex', 'requirement_specification.tex'), help="path to the template")
  14. (options, args) = parser.parse_args()
  15. #
  16. # Check options and args
  17. if len(args) != 1 or not os.path.isfile(args[0]):
  18. parser.print_help()
  19. else:
  20. reqif_path = args[0]
  21. template_path = os.path.abspath(options.template)
  22. output_path = os.path.splitext(reqif_path)[0] + os.path.splitext(template_path)[1]
  23. if reqif_path == output_path:
  24. sys.exit('ERROR: Source and Destination would be the same file')
  25. #
  26. reqif_data = reqif.reqif_dict(reqif_path, 'Heading', 'Software Specification')
  27. #
  28. with open(output_path, 'w') as fh:
  29. jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(template_path)))
  30. template = jenv.get_template(os.path.basename(template_path))
  31. fh.write(template.render(data=reqif_data))