-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduction of Requirements in pumla docs-as-code approach.
First step with Weather Station example. Creating the reqs_repo file and an overview diagram.
- Loading branch information
1 parent
1a8cfa1
commit a8b1ee2
Showing
9 changed files
with
291 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"""The pumla command line tool functions for requirements parsing.""" | ||
|
||
import json | ||
import os | ||
import yaml | ||
from pathlib import Path | ||
from pumla.control.cmd_utils import isInBlacklist, readBlacklist | ||
|
||
|
||
def parsePUMLAReqFile(file): | ||
""" parse the PUMLA Requirements file and read it | ||
into a dictionary.""" | ||
reqsdict = yaml.safe_load(Path(file).read_text()) | ||
return reqsdict | ||
|
||
|
||
def findAllPUMLAReqFiles(path): | ||
"""" find all pumla files in given path """ | ||
pumlareqfiles = [] | ||
blacklist = [] | ||
|
||
blacklistfilename = path + "/pumla_blacklist.txt" | ||
|
||
blacklist = readBlacklist(path, blacklistfilename) | ||
|
||
# walk through the file and folder structure | ||
# and put all PUMLA req files into a list | ||
for dirpath, dirs, files in os.walk(path): | ||
for filename in files: | ||
if not isInBlacklist(dirpath, blacklist): | ||
#print(dirpath) | ||
fname = os.path.join(dirpath, filename) | ||
# a PUMLA req. file must end with '.yml' (see Modelling Guideline) | ||
if fname.endswith('.yaml'): | ||
with open(fname) as myfile: | ||
line = myfile.read() | ||
# a PUMLA file must have that first comment line (see Modelling Guideline) | ||
if line.startswith("#PUMLARR"): | ||
pumlareqfiles.append(fname) | ||
|
||
#return the list of PUMLA req files found | ||
return pumlareqfiles | ||
|
||
def updatePUMLAReqRepo(path, mrefilename): | ||
"""create, update/overwrite the PUMLA requirements repository json file | ||
with current state of the source code repository""" | ||
# traverse down the path and find all | ||
# pumla req. files. | ||
pumlareqfiles = findAllPUMLAReqFiles(path) | ||
|
||
# parse each pumla file and create | ||
# a PUMLA Elements, Connections and | ||
# relations out of it, that | ||
# get put into dict. | ||
pumlareqslist = [] | ||
|
||
# sum up information from all files in common list | ||
for f in pumlareqfiles: | ||
reqs = parsePUMLAReqFile(f) | ||
for r in reqs: | ||
r.update({"derived to": "not yet derived"}) | ||
pumlareqslist.append(r) | ||
|
||
|
||
# make it accessible from within PlantUML. | ||
# $allreqs is the preprocessor variable that | ||
# allows access by PlantUML pumla marcros. | ||
pumlareqdict = {"reqsrepopath": path, "reqsrepofile": mrefilename, "reqs": pumlareqslist} | ||
reqjsontxt = json.dumps(pumlareqdict) | ||
jsontxt = "!$allreqs = " + reqjsontxt | ||
|
||
pumltxt = "@startjson\n" + reqjsontxt + "\n@endjson\n" | ||
pumltxtlines = pumltxt.split("},") | ||
|
||
# split text to make the resulting file more readable; | ||
# one element definition per line. | ||
txt_lines = jsontxt.split("},") | ||
|
||
# write the lines to the model element repo file | ||
with open(mrefilename, "w") as fil: | ||
for i in range(len(txt_lines) - 1): | ||
fil.write(txt_lines[i] + "},\n") | ||
fil.write(txt_lines[len(txt_lines) - 1] + "\n\n") | ||
fil.close() | ||
|
||
# write the lines to the model element repo file | ||
with open("reqs_json_diagram.puml", "w") as fil: | ||
for i in range(len(pumltxtlines) - 1): | ||
fil.write(pumltxtlines[i] + "},\n") | ||
fil.write(pumltxtlines[len(pumltxtlines) - 1] + "\n\n") | ||
fil.close() | ||
|
||
return True, mrefilename, pumlareqslist | ||
|
||
|
||
fn = "reqsrepo_json.puml" | ||
|
||
updatePUMLAReqRepo("../../../test/examples/WeatherStation/", fn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
all features: | ||
- HMI: | ||
- display | ||
- buttons | ||
- Housing: | ||
- Color | ||
- Measurement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
!$allelems = {"modelrepopath": "/Users/mvoss/Desktop/git/github/pumla/test/examples/WeatherStation", "modelrepofile": "help", "elements": [{"name": "Temperature System", "alias": "tempSys", "type": "node", "stereotypes": ["block"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "-", "path": "./", "filename": "tempSys.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]}, | ||
{"tag": "Arch Level", "values": ["0"]}]}, | ||
{"name": "MyNewClass1", "alias": "MyNewClass1", "type": "class", "stereotypes": ["Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "-", "path": "./", "filename": "reusableClass1.puml"}, | ||
{"name": "tSys1 professional", "alias": "tSys1", "type": "node", "stereotypes": ["instance", "block"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "tempSys", "path": "./", "filename": "tempSysInstances.puml"}, | ||
{"name": "tSys2", "alias": "tSys2", "type": "node", "stereotypes": ["instance", "block"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "tempSys", "path": "./", "filename": "tempSysInstances.puml"}, | ||
{"name": "Temperature Sensor B", "alias": "tempSensorB", "type": "component", "stereotypes": ["block", "external System"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "-", "path": "./tempSensorB/", "filename": "tempSensorB.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B1", "B2"]}, | ||
{"tag": "Vendor", "values": ["B Inc."]}, | ||
{"tag": "Arch Level", "values": ["1"]}]}, | ||
{"name": "Public State", "alias": "publicState", "type": "state", "stereotypes": [], "ports": [], "typed_ifs": [], "kind": "dynamic", "parent": "tempSensorB", "instclassalias": "-", "path": "./tempSensorB/", "filename": "publicState.puml"}, | ||
{"name": "anotherClass", "alias": "anotherClass", "type": "class", "stereotypes": ["Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "-", "path": "./anotherClass/", "filename": "anotherClass.puml"}, | ||
{"name": "CWeather", "alias": "CWeather", "type": "class", "stereotypes": ["Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "-", "path": "./CWeather/", "filename": "CWeather.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]}]}, | ||
{"name": "w3", "alias": "w3", "type": "class", "stereotypes": ["instance", "Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "CWeather", "path": "./CWeather/", "filename": "FurtherWeatherInstances.puml"}, | ||
{"name": "w4", "alias": "w4", "type": "class", "stereotypes": ["instance", "Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "CWeather", "path": "./CWeather/", "filename": "FurtherWeatherInstances.puml"}, | ||
{"name": "Weather Data Instance 1", "alias": "w1", "type": "class", "stereotypes": ["instance", "Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "CWeather", "path": "./CWeather/", "filename": "WeatherInstances.puml"}, | ||
{"name": "Weather Data Instance 2", "alias": "w2", "type": "class", "stereotypes": ["instance", "Python"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "CWeather", "path": "./CWeather/", "filename": "WeatherInstances.puml"}, | ||
{"name": "Wireless Unit", "alias": "wirelessUnit", "type": "rectangle", "stereotypes": ["block", "external System"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "-", "instclassalias": "-", "path": "./wirelessUnit/", "filename": "wirelessUnit.puml", "taggedvalues": [{"tag": "Vendor", "values": ["XY"]}, | ||
{"tag": "SecurityClass", "values": ["Alpha"]}, | ||
{"tag": "Frequency Range", "values": ["5 GHz"]}, | ||
{"tag": "Arch Level", "values": ["0"]}]}, | ||
{"name": "Temperature Sensor A", "alias": "tempSensorA", "type": "component", "stereotypes": ["block"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./tempSensorA/", "filename": "tempSensorA.puml", "taggedvalues": [{"tag": "Vendor", "values": ["A GmbH"]}, | ||
{"tag": "Arch Level", "values": ["1"]}]}, | ||
{"name": "**Internal Sequence**", "alias": "internalSequence", "type": "participant", "stereotypes": [], "ports": [], "typed_ifs": [], "kind": "dynamic", "parent": "tempSensorA", "instclassalias": "-", "path": "./tempSensorA/", "filename": "internalSequence.puml"}, | ||
{"name": "Temperature Sensor B (dC)", "alias": "tempSensorBdC", "type": "component", "stereotypes": ["block"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]}, | ||
{"tag": "Arch Level", "values": ["1"]}]}, | ||
{"name": "displayTemp", "alias": "displayTemp", "type": "component", "stereotypes": ["block"], "ports": [{"name": "tempDc", "interfacetype": "tempinterface", "type": "inout", "alias": "porttempdc", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]}, | ||
{"tag": "Arch Level", "values": ["2", "3"]}, | ||
{"tag": "SysVariant", "values": ["B"]}]}, | ||
{"name": "tempdF", "interfacetype": "tempinterface", "type": "in", "alias": "porttempdF", "taggedvalues": []}], "typed_ifs": [{"name": "temp_dC_RUA", "interfacetype": "hello", "type": "inout", "alias": "temp_dC_displayTemp_RUA", "taggedvalues": []}], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./displayTemp/", "filename": "displayTemp.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]}, | ||
{"tag": "Brightness", "values": ["300 Nits"]}, | ||
{"tag": "Arch Level", "values": ["1"]}]}, | ||
{"name": "Temp. Converter", "alias": "tempConverter", "type": "component", "stereotypes": ["block"], "ports": [], "typed_ifs": [], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./tempConv/", "filename": "tempConverter.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]}, | ||
{"tag": "Arch Level", "values": ["1"]}]}]} | ||
|
||
!$allrelations = {"modelrelationrepopath": "/Users/mvoss/Desktop/git/github/pumla/test/examples/WeatherStation", "modelrelationrepofile": "help", "relations": [{"id": "REL#tSys1tempSys", "start": "tSys1", "end": "tempSys", "reltype": "..>", "reltxt": "instance of", "techntxt": "", "path": "./", "filename": "tempSysInstances.puml"}, | ||
{"id": "REL#tSys2tempSys", "start": "tSys2", "end": "tempSys", "reltype": "..>", "reltxt": "instance of", "techntxt": "", "path": "./", "filename": "tempSysInstances.puml"}, | ||
{"id": "REL#publicStateToIF", "start": "publicState", "end": "temp_dF_tempSensorB", "reltype": "..>", "reltxt": "provides", "techntxt": "", "path": "./tempSensorB/", "filename": "tempSensorB.puml"}, | ||
{"id": "REL#w3CWeather", "start": "w3", "end": "CWeather", "reltype": "..>", "reltxt": "instance of", "techntxt": "", "path": "./CWeather/", "filename": "FurtherWeatherInstances.puml"}, | ||
{"id": "REL#w4CWeather", "start": "w4", "end": "CWeather", "reltype": "..>", "reltxt": "instance of", "techntxt": "", "path": "./CWeather/", "filename": "FurtherWeatherInstances.puml"}, | ||
{"id": "REL#w1CWeather", "start": "w1", "end": "CWeather", "reltype": "..>", "reltxt": "instance of", "techntxt": "", "path": "./CWeather/", "filename": "WeatherInstances.puml"}, | ||
{"id": "REL#w2CWeather", "start": "w2", "end": "CWeather", "reltype": "..>", "reltxt": "instance of", "techntxt": "", "path": "./CWeather/", "filename": "WeatherInstances.puml"}, | ||
{"id": "tempSensorBdCRel#1", "start": "tempSensorBdC", "end": "tempSensorB", "reltype": "..>", "reltxt": "use", "techntxt": "", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B2"]}]}, | ||
{"id": "tempSensorBdCRel#2", "start": "tempSensorBdC", "end": "tempConverter", "reltype": "..>", "reltxt": "use", "techntxt": "", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B2"]}]}, | ||
{"id": "tempSensorBdCRel#3", "start": "tempSensorBdC", "end": "tempSensorB", "reltype": "..>", "reltxt": "useForB3", "techntxt": "", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B3"]}]}, | ||
{"id": "tempSensorBdCRel#4", "start": "tempSensorBdC", "end": "tempConverter", "reltype": "..>", "reltxt": "useForB3", "techntxt": "", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B3"]}]}]} | ||
|
||
!$allconnections = {"modelconnectionrepopath": "/Users/mvoss/Desktop/git/github/pumla/test/examples/WeatherStation", "modelconnectionrepofile": "help", "connections": [{"id": "CON#_SYS_VAR_B", "start": "temp_dC_tempSensorBdC", "end": "temp_dC_displayTemp", "contype": "--", "contxt": "", "path": "./connections/", "filename": "connections_tempSys_Var_B.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B1", "B2"]}]}, | ||
{"id": "CON#_SYS_VAR_A", "start": "temp_dC_tempSensorA", "end": "temp_dC_displayTemp", "contype": "--", "contxt": "", "path": "./connections/", "filename": "connections_tempSys_Var_A.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["A"]}]}, | ||
{"id": "CON#_SYS_VAR_B2", "start": "temp_dC_tempSensorBdC", "end": "temp_dC_displayTemp", "contype": "--", "contxt": "", "path": "./connections/", "filename": "connections_tempSys_Var_B2.puml", "taggedvalues": [{"tag": "SysVariant", "values": ["B2"]}]}, | ||
{"id": "C#2", "start": "temp_dC_tempConverter", "end": "temp_dC_tempSensorBdC", "contype": "--", "contxt": "", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml"}, | ||
{"id": "C#3", "start": "temp_dF_tempSensorB", "end": "temp_dF_tempConverter", "contype": "--", "contxt": "", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml"}]} | ||
|
Oops, something went wrong.