From 0e58cebcaac26ab648c950b54037dbbc298650fc Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 18 Sep 2025 17:02:29 +0200 Subject: [PATCH] Rework requirement_specification --- __init__.py | 41 ++++++++--------------------------------- rspec.mk | 4 ++-- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/__init__.py b/__init__.py index 857aa10..948a896 100644 --- a/__init__.py +++ b/__init__.py @@ -14,6 +14,11 @@ BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__))) sys.path.insert(0, BASEPATH) +ITYPE_SEC = "SEC" +ITYPE_REQ = "REQ" + + + class rspec(dict): KEY_MAIN_TITLE = "title" KEY_MAIN_ENTRIES = "entries" @@ -49,13 +54,13 @@ class rspec(dict): try: parent = kwargs.pop("parent") except KeyError: - if not uuid.lower().startswith("sec"): + if not uuid.lower().startswith(ITYPE_SEC.lower()): raise KeyError( "You need to specify a parent for non sec entries") # # Create Structure # - if uuid.lower().startswith("sec"): + if uuid.lower().startswith(ITYPE_SEC.lower()): # Create section self[self.KEY_MAIN_SECTIONS].append(uuid) else: @@ -65,39 +70,9 @@ class rspec(dict): # # Add item to itemlist # - if uuid.lower().startswith("sec"): + if uuid.lower().startswith(ITYPE_SEC.lower()): kwargs[self.KEY_SEC_CHILDS] = [] self[self.KEY_MAIN_ENTRIES][uuid] = kwargs # 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)) diff --git a/rspec.mk b/rspec.mk index 204eeb1..84e85de 100644 --- a/rspec.mk +++ b/rspec.mk @@ -19,8 +19,8 @@ head: echo -e "╚══════════════╝\033[00m" -$(TARGET).tex: $(MODULE_NAME)/_requirements_/$(TARGET).py - venv/bin/python rspec/__init__.py $(MODULE_NAME)/_requirements_/$(TARGET).py > $(TARGET).tex +$(TARGET).tex: specification.py + venv/bin/python specification.py > $(TARGET).tex tex: $(TARGET).tex