Rework requirement_specification
This commit is contained in:
parent
871ea528c0
commit
0e58cebcaa
41
__init__.py
41
__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))
|
||||
|
4
rspec.mk
4
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user