Rework requirement_specification

This commit is contained in:
Dirk Alders 2025-09-18 17:02:29 +02:00
parent 871ea528c0
commit 0e58cebcaa
2 changed files with 10 additions and 35 deletions

View File

@ -14,6 +14,11 @@ BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__)))
sys.path.insert(0, BASEPATH) sys.path.insert(0, BASEPATH)
ITYPE_SEC = "SEC"
ITYPE_REQ = "REQ"
class rspec(dict): class rspec(dict):
KEY_MAIN_TITLE = "title" KEY_MAIN_TITLE = "title"
KEY_MAIN_ENTRIES = "entries" KEY_MAIN_ENTRIES = "entries"
@ -49,13 +54,13 @@ class rspec(dict):
try: try:
parent = kwargs.pop("parent") parent = kwargs.pop("parent")
except KeyError: except KeyError:
if not uuid.lower().startswith("sec"): if not uuid.lower().startswith(ITYPE_SEC.lower()):
raise KeyError( raise KeyError(
"You need to specify a parent for non sec entries") "You need to specify a parent for non sec entries")
# #
# Create Structure # Create Structure
# #
if uuid.lower().startswith("sec"): if uuid.lower().startswith(ITYPE_SEC.lower()):
# Create section # Create section
self[self.KEY_MAIN_SECTIONS].append(uuid) self[self.KEY_MAIN_SECTIONS].append(uuid)
else: else:
@ -65,39 +70,9 @@ class rspec(dict):
# #
# Add item to itemlist # Add item to itemlist
# #
if uuid.lower().startswith("sec"): if uuid.lower().startswith(ITYPE_SEC.lower()):
kwargs[self.KEY_SEC_CHILDS] = [] kwargs[self.KEY_SEC_CHILDS] = []
self[self.KEY_MAIN_ENTRIES][uuid] = kwargs self[self.KEY_MAIN_ENTRIES][uuid] = kwargs
# #
return uuid return uuid
def rs_by_spec_file(spec_file):
spec = importlib.util.spec_from_file_location("specification", spec_file)
s = importlib.util.module_from_spec(spec)
sys.modules["specification"] = s
spec.loader.exec_module(s)
#
rs = rspec()
s.specification(rs)
return rs
if __name__ == '__main__':
parser = optparse.OptionParser("usage: %prog reqif_file")
parser.add_option("-t", "--template", dest="template", default=os.path.join(BASEPATH,
'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:
rs = rs_by_spec_file(args[0])
#
template_path = os.path.abspath(options.template)
jenv = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(template_path)))
template = jenv.get_template(os.path.basename(template_path))
print(template.render(data=rs))

View File

@ -19,8 +19,8 @@ head:
echo -e "╚══════════════╝\033[00m" echo -e "╚══════════════╝\033[00m"
$(TARGET).tex: $(MODULE_NAME)/_requirements_/$(TARGET).py $(TARGET).tex: specification.py
venv/bin/python rspec/__init__.py $(MODULE_NAME)/_requirements_/$(TARGET).py > $(TARGET).tex venv/bin/python specification.py > $(TARGET).tex
tex: $(TARGET).tex tex: $(TARGET).tex