Skip to content

Commit

Permalink
Merge 76c56bc into 28cd9d8
Browse files Browse the repository at this point in the history
  • Loading branch information
james-strauss-uwa committed Sep 29, 2022
2 parents 28cd9d8 + 76c56bc commit 54b2a88
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create-palettes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- name: Install system dependencies
run: |
sudo apt-get update && sudo apt-get install -y doxygen xsltproc
pip install BlockDAG
- name: Configure git
run: |
Expand Down
57 changes: 41 additions & 16 deletions tools/xml2palette/xml2palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import re
from enum import Enum

from blockdag import build_block_dag

next_key = -1

# NOTE: not sure if all of these are actually required
Expand Down Expand Up @@ -93,6 +95,14 @@
tuple: "Json"
}

BLOCKDAG_DATA_FIELDS = [
"inputPorts",
"outputPorts",
"applicationArgs",
"category",
"fields"
]

class Language(Enum):
UNKNOWN = 0
C = 1
Expand All @@ -111,7 +121,7 @@ def get_args():
action="store_true")
parser.add_argument("-r", "--recursive", help="Traverse sub-directories",
action="store_true")
parser.add_argument("-s", "--parse_all",
parser.add_argument("-s", "--parse_all",
help="Try to parse non DAliuGE compliant functions and methods",
action="store_true")
parser.add_argument("-v", "--verbose", help="increase output verbosity",
Expand Down Expand Up @@ -411,8 +421,6 @@ def create_palette_node_from_params(params):
outputLocalPorts = []
fields = []
applicationArgs = []
gitrepo = os.environ.get("GIT_REPO")
version = os.environ.get("PROJECT_VERSION")

# process the params
for param in params:
Expand Down Expand Up @@ -549,13 +557,20 @@ def create_palette_node_from_params(params):
"outputAppFields": [],
"fields": fields,
"applicationArgs": applicationArgs,
"git_url": gitrepo,
"sha": version,
"repositoryUrl": gitrepo,
"commitHash": version,
"paletteDownloadUrl": "",
"dataHash": "",
},
)


def write_palette_json(outputfile, nodes, gitrepo, version):
def write_palette_json(outputfile, nodes, gitrepo, version, block_dag):
# add hashes from block_dag to the nodes
for i in range(len(nodes)):
nodes[i]['dataHash'] = block_dag[i]['data_hash'];

# create the palette object
palette = {
"modelData": {
"fileType": "palette",
Expand All @@ -564,13 +579,16 @@ def write_palette_json(outputfile, nodes, gitrepo, version):
"repo": "ICRAR/EAGLE_test_repo",
"readonly": True,
"filePath": outputfile,
"sha": version,
"git_url": gitrepo,
"repositoryUrl": gitrepo,
"commitHash": version,
"downloadUrl": "",
"signature": block_dag['signature'],
},
"nodeDataArray": nodes,
"linkDataArray": [],
}

# write palette to file
with open(outputfile, "w") as outfile:
json.dump(palette, outfile, indent=4)

Expand Down Expand Up @@ -689,7 +707,7 @@ def process_compounddef_default(compounddef, language):
if child.tag == "compoundname":
if child.text.find('casatasks:') == 0:
casa_mode = True
hold_name = child.text.split('::')[1]
hold_name = child.text.split('::')[1]
else:
casa_mode = False
hold_name = "Unknown"
Expand Down Expand Up @@ -822,7 +840,7 @@ def process_compounddef_default(compounddef, language):
vt = str
except SyntaxError:
vt = str

value_type = VALUE_TYPES[vt] if vt in VALUE_TYPES else "String"
if value_type == "String":
# if it is String we need to do a few more tests
Expand All @@ -848,7 +866,7 @@ def process_compounddef_default(compounddef, language):

# TODO: change
# add the param

if str(value_type) == "String":
default_value = str(default_value).replace("'", "")
if default_value.find("/") >=0:
Expand Down Expand Up @@ -883,7 +901,7 @@ def process_compounddef_default(compounddef, language):
continue
# logging.debug("Appending members: %s", member)
result.append(member)

return result


Expand Down Expand Up @@ -937,10 +955,12 @@ def create_construct_node(node_type, node):
+ " component.",
"fields": [],
"applicationArgs": [],
"git_url": gitrepo,
"repositoryUrl": gitrepo,
"commitHash": version,
"paletteDownloadUrl": "",
"dataHash": "",
"key": get_next_key(),
"precious": False,
"sha": version,
"streaming": False,
"text": node_type + "/" + node["text"],
}
Expand Down Expand Up @@ -1031,7 +1051,7 @@ def parseCasaDocs(dStr:str) -> dict:
paramsList = dList[start_ind:end_ind]
paramsSidx = [idx+1 for idx, p in enumerate(paramsList) if len(p) > 0 and p[0] != ' ']
paramsEidx = paramsSidx[1:] + [len(paramsList) - 1]
paramFirstLine = [(p.strip().split(' ',1)[0], p.strip().split(' ',1)[1].strip())
paramFirstLine = [(p.strip().split(' ',1)[0], p.strip().split(' ',1)[1].strip())
for p in paramsList if len(p) > 0 and p[0] != ' ']
paramNames = [p[0] for p in paramFirstLine]
paramDocs = [p[1].strip() for p in paramFirstLine]
Expand Down Expand Up @@ -1161,9 +1181,14 @@ def parseCasaDocs(dStr:str) -> dict:
if not alreadyPresent:
nodes.append(n)

# add signature for whole palette using BlockDAG
vertices = {}
for i in range(len(nodes)):
vertices[i] = nodes[i]
block_dag = build_block_dag(vertices, [], data_fields=BLOCKDAG_DATA_FIELDS)

# write the output json file
write_palette_json(outputfile, nodes, gitrepo, version)
write_palette_json(outputfile, nodes, gitrepo, version, block_dag)
logging.info("Wrote " + str(len(nodes)) + " component(s)")

# cleanup the output directory
Expand Down

0 comments on commit 54b2a88

Please sign in to comment.