diff options
author | Sunil Shetye | 2025-02-25 14:06:03 +0530 |
---|---|---|
committer | Sunil Shetye | 2025-02-25 16:03:12 +0530 |
commit | fcfe30578357da4716c59a9eaed6f80577f22bbc (patch) | |
tree | 875abfe62924f02141636a1f1a5e79881879809b | |
parent | f2cd0f16b9432fcb3c4af4d3cdadf7de33b14128 (diff) | |
download | Common-Interface-Project-fcfe30578357da4716c59a9eaed6f80577f22bbc.tar.gz Common-Interface-Project-fcfe30578357da4716c59a9eaed6f80577f22bbc.tar.bz2 Common-Interface-Project-fcfe30578357da4716c59a9eaed6f80577f22bbc.zip |
convert to classes now
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | blocks/.flake8 | 2 | ||||
-rw-r--r-- | blocks/Makefile | 80 | ||||
-rwxr-xr-x | blocks/Xcos/MxGraphParser.py | 2 | ||||
-rw-r--r-- | blocks/Xcos/ParserFunctions.py | 4 | ||||
-rwxr-xr-x | blocks/Xcos/XmlParser.py | 8 | ||||
-rw-r--r-- | blocks/Xcos/blocks/SUPER_f.py | 2 | ||||
-rw-r--r-- | blocks/Xcos/common/AAAAAA.py | 8 | ||||
-rw-r--r-- | blocks/Xcos/ports/CommandPort.py | 3 | ||||
-rw-r--r-- | blocks/Xcos/ports/ControlPort.py | 3 | ||||
-rw-r--r-- | blocks/Xcos/ports/ExplicitInputPort.py | 3 | ||||
-rw-r--r-- | blocks/Xcos/ports/ExplicitOutputPort.py | 3 | ||||
-rw-r--r-- | blocks/Xcos/ports/ImplicitInputPort.py | 3 | ||||
-rw-r--r-- | blocks/Xcos/ports/ImplicitOutputPort.py | 3 |
14 files changed, 74 insertions, 51 deletions
@@ -17,6 +17,7 @@ blocks/*.xcos blocks/*.xml blocks/*.xsl blocks/xcosblocks.py +blocks/xcosblocks.sed blocks/Xcos/xcosblocks.py blocks/blocks/xcosblocks/xcosblocks.py blocks/eda-frontend/public/xcos2xml.xsl diff --git a/blocks/.flake8 b/blocks/.flake8 index 26f8c94e..b6eca717 100644 --- a/blocks/.flake8 +++ b/blocks/.flake8 @@ -5,5 +5,5 @@ #ignore = E121,E123,E126,E226,E24,E704,W503,W504 ignore = F401,F403,W504 extend-exclude = docs,env*,migrations,node_modules,Xcos/common,Xcos/blocks,Xcos/ports,Xcos/links -max-complexity = 14 +max-complexity = 30 max-line-length = 275 diff --git a/blocks/Makefile b/blocks/Makefile index 61bf1378..e2d52a1a 100644 --- a/blocks/Makefile +++ b/blocks/Makefile @@ -2,10 +2,14 @@ SHELL := /bin/bash BLOCKDIR := blocks/xcosblocks -SRCFILES := $(sort $(wildcard Xcos/common/*.py)) -SRCFILES += $(sort $(wildcard Xcos/blocks/*.py)) -SRCFILES += $(sort $(wildcard Xcos/ports/*.py)) -SRCFILES += $(sort $(wildcard Xcos/links/*.py)) +COMMONSRCFILES := $(sort $(wildcard Xcos/common/*.py)) +SRCFILES := $(COMMONSRCFILES) +BLOCKSRCFILES := $(sort $(wildcard Xcos/blocks/*.py)) +SRCFILES += $(BLOCKSRCFILES) +PORTSRCFILES := $(sort $(wildcard Xcos/ports/*.py)) +SRCFILES += $(PORTSRCFILES) +LINKSRCFILES := $(sort $(wildcard Xcos/links/*.py)) +SRCFILES += $(LINKSRCFILES) XCOS2XMLFILES := $(sort $(wildcard xcos2xml/head.xsl)) XCOS2XMLFILES += $(sort $(wildcard xcos2xml/blocks/*.xsl)) @@ -13,42 +17,66 @@ XCOS2XMLFILES += $(sort $(wildcard xcos2xml/ports/*.xsl)) XCOS2XMLFILES += $(sort $(wildcard xcos2xml/links/*.xsl)) XCOS2XMLFILES += $(sort $(wildcard xcos2xml/foot.xsl)) -IMPORT := Xcos/xcosblocks.py -TARGET := xcosblocks.py -TARGET2 := $(BLOCKDIR)/$(TARGET) +SEDFILE := xcosblocks.sed +TARGET := Xcos/xcosblocks.py +TARGET2 := $(BLOCKDIR)/xcosblocks.py TARGET3 := eda-frontend/public/xcos2xml.xsl -all : $(IMPORT) $(TARGET) $(TARGET2) $(TARGET3) +all : $(SEDFILE) $(TARGET) $(TARGET2) $(TARGET3) -$(IMPORT) : $(SRCFILES) +$(SEDFILE) : Makefile $(BLOCKSRCFILES) $(PORTSRCFILES) $(LINKSRCFILES) @echo Making $@ ... - @for f in $^; do \ - g=$${f%.py}; \ - g=$${g#Xcos/}; \ - g=$${g//\//.}; \ - echo "from $$g import *"; \ - done > $@ + @( \ + sed -n 's/^def \([^(]*\).*/s,^\\( *\\(return\\)\\? \\)\\(\1(\\),\\1Blocks.\\3,/p' $(BLOCKSRCFILES); \ + sed -n 's/^def \([^(]*\).*/s,^\\( *\\(return\\)\\? \\)\\(\1(\\),\\1Ports.\\3,/p' $(PORTSRCFILES); \ + sed -n 's/^def \([^(]*\).*/s,^\\( *\\(return\\)\\? \\)\\(\1(\\),\\1Links.\\3,/p' $(LINKSRCFILES); \ + ) > $@ -$(TARGET) : $(SRCFILES) +$(TARGET) : xcosblocks.sed $(SRCFILES) @echo Making $@ ... - @for f in $^; do \ + @( \ + for f in $(COMMONSRCFILES); do \ echo "# BEGIN $$f"; \ - egrep -v "^from (blocks|common|links|ports)\\..* import " "$$f"; \ + sed -e '/^from \(blocks\|common\|links\|ports\)\..* import /d' "$$f"; \ echo; \ echo "# END $$f"; \ - done > $@ + done; \ + echo; \ + echo; \ + echo 'class Blocks:'; \ + for f in $(BLOCKSRCFILES); do \ + echo; \ + echo " # BEGIN $$f"; \ + sed -e '/^from \(blocks\|common\|links\|ports\)\..* import /d' -e '/^$$/N;/^\n$$/D' "$$f" | sed 's/^\(.\)/ \1/'; \ + echo " # END $$f"; \ + done; \ + echo; \ + echo; \ + echo 'class Ports:'; \ + for f in $(PORTSRCFILES); do \ + echo; \ + echo " # BEGIN $$f"; \ + sed -e '/^from \(blocks\|common\|links\|ports\)\..* import /d' -e '/^$$/N;/^\n$$/D' "$$f" | sed 's/^\(.\)/ \1/'; \ + echo " # END $$f"; \ + done; \ + echo; \ + echo; \ + echo 'class Links:'; \ + for f in $(LINKSRCFILES); do \ + echo; \ + echo " # BEGIN $$f"; \ + sed -e '/^from \(blocks\|common\|links\|ports\)\..* import /d' -e '/^$$/N;/^\n$$/D' "$$f" | sed 's/^\(.\)/ \1/'; \ + echo " # END $$f"; \ + done; \ + ) > $@ + @sed -i -f $< $@ flake8 : $(TARGET) flake8 --statistics -.xcosblocks.txt : $(TARGET) Xcos/parsexcosblocks.awk - @echo Making $@ ... - @Xcos/parsexcosblocks.awk $(TARGET) > $@ - -.srcflake8 : $(TARGET) .xcosblocks.txt Xcos/usexcosblocks.awk +.srcflake8 : $(TARGET) @echo 'flake8 common/*.py blocks/*.py ports/*.py links/*.py' - @flake8 $(TARGET) | Xcos/usexcosblocks.awk .xcosblocks.txt -; \ - exit $${PIPESTATUS[0]} + @flake8 $(TARGET) touch $@ $(TARGET2) : .srcflake8 diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py index b050c834..4fba21f3 100755 --- a/blocks/Xcos/MxGraphParser.py +++ b/blocks/Xcos/MxGraphParser.py @@ -13,7 +13,7 @@ from xcosblocks import * # from ParserFunctions import addPort1ForSplit, addPort2ForSplit, addPort3ForSplit # from ParserFunctions import createOutnode, checkModelTag, checkRootTag # from ParserFunctions import getComponentGeometry, get_int, getLinkStyle, getNextAttribId, getOrdering, getorderingname, getParameters, getPinGeometry, getSplitPoints, getWaypoints, getSuperblock -from xcosblocks import remove_hyphen_number # identify_segment, +from xcosblocks import remove_hyphen_number # identify_segment, from xcosblocks import process_xcos_model diff --git a/blocks/Xcos/ParserFunctions.py b/blocks/Xcos/ParserFunctions.py index a30680c7..cb0a6748 100644 --- a/blocks/Xcos/ParserFunctions.py +++ b/blocks/Xcos/ParserFunctions.py @@ -573,7 +573,7 @@ from xcosblocks import SplitBlock # "blocks": [], # "parameters": [] # } - + # mxGraphModel = cell.find(".//mxGraphModel/root") # if mxGraphModel is not None: # for subcell in mxGraphModel.findall("mxCell"): @@ -588,7 +588,7 @@ from xcosblocks import SplitBlock # superblock_data["parameters"].append(parameter_values[parameter]) # else: # break - + # return superblock_data # return None diff --git a/blocks/Xcos/XmlParser.py b/blocks/Xcos/XmlParser.py index 017321dc..d425338e 100755 --- a/blocks/Xcos/XmlParser.py +++ b/blocks/Xcos/XmlParser.py @@ -10,10 +10,10 @@ import defusedxml.ElementTree as goodET import uuid from xcosblocks import num2str, style_to_object -from ParserFunctions import addtolinklist -from ParserFunctions import create_mxCell, create_mxCell_edge, create_mxCell_port, checkModelTag, check_point_on_array, checkRootTag -from ParserFunctions import getComponentGeometry, getlinkdetails, getLinkStyle, getNextAttribId, getPinGeometry, getSplitPoints, getWaypoints -from ParserFunctions import identify_segment, initLinks, mergeLinks, portType1, portType2, portType3, remove_hyphen_number +from xcosblocks import addtolinklist +from xcosblocks import create_mxCell, create_mxCell_edge, create_mxCell_port, checkModelTag, check_point_on_array, checkRootTag +from xcosblocks import getComponentGeometry, getlinkdetails, getLinkStyle, getNextAttribId, getPinGeometry, getSplitPoints, getWaypoints +from xcosblocks import identify_segment, initLinks, mergeLinks, portType1, portType2, portType3, remove_hyphen_number if len(sys.argv) != 2: diff --git a/blocks/Xcos/blocks/SUPER_f.py b/blocks/Xcos/blocks/SUPER_f.py index fe608502..44a1348e 100644 --- a/blocks/Xcos/blocks/SUPER_f.py +++ b/blocks/Xcos/blocks/SUPER_f.py @@ -60,7 +60,7 @@ def SUPER_f(outroot, attribid, ordering, geometry, parameters, parent=1, style=N # addmxCellNode(root, TYPE_MXCELL, # id=block_id[1], # parent=block_id[0]) - + # CLOCK_c(root, block_id[2], ordering, geometry, ['0', '0'], parent=block_id[1]) # CommandPort # CLOCK_c diff --git a/blocks/Xcos/common/AAAAAA.py b/blocks/Xcos/common/AAAAAA.py index ee67eaf9..1d5321e0 100644 --- a/blocks/Xcos/common/AAAAAA.py +++ b/blocks/Xcos/common/AAAAAA.py @@ -776,6 +776,7 @@ def style_to_object(style): return style_object + # parserfunction def remove_hyphen_number(s): return re.sub(r'-\d+$', '', s) @@ -1333,7 +1334,7 @@ def getParameters(cell): def getSuperblock(cell): if "style" in cell.attrib and "SUPER_f" in cell.attrib["style"]: mxGraphModel = cell.find(".//mxGraphModel") - + return mxGraphModel return None @@ -1452,7 +1453,7 @@ def process_xcos_model(model, title, rootattribid, parentattribid): stylename = style_dict.get('default', 'TEXT_f') print('globals:', locals()) # locals()[stylename](outroot, attribid, componentOrdering, componentGeometry, parameters, parent=parentattribid, style=style, superblock=superblock) - eval(stylename + "(outroot, attribid, componentOrdering, componentGeometry, parameters, parent=parentattribid, style=style, superblock=superblock)" ) + eval(stylename + "(outroot, attribid, componentOrdering, componentGeometry, parameters, parent=parentattribid, style=style, superblock=superblock)") IDLIST[attribid] = cell_type blkgeometry[attribid] = componentGeometry @@ -1566,7 +1567,6 @@ def process_xcos_model(model, title, rootattribid, parentattribid): nextAttribForSplit += 1 LINKTOPORT[linkid] = port3 - for key, newEdges in newEdgeDict.items(): for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point, split_point2) in newEdges: try: @@ -1583,7 +1583,7 @@ def process_xcos_model(model, title, rootattribid, parentattribid): attribid = nextattribid nextattribid += 1 globals()[style](outroot, attribid, sourceVertex, targetVertex, - waypoints[1:-1], parent=parentattribid) + waypoints[1:-1], parent=parentattribid) outnode = ET.SubElement(outdiagram, 'mxCell') outnode.set('as', 'defaultParent') diff --git a/blocks/Xcos/ports/CommandPort.py b/blocks/Xcos/ports/CommandPort.py index e708037c..425a9b76 100644 --- a/blocks/Xcos/ports/CommandPort.py +++ b/blocks/Xcos/ports/CommandPort.py @@ -31,8 +31,7 @@ def addCommandPortForSplit(outroot, splitBlock, sourceVertex, targetVertex, geometry['height'] = 8 geometry['x'] = 7 geometry['y'] = -4 - CommandPort(outroot, nextAttrib, splitBlock, outputCount, geometry, - forSplitBlock=True) + CommandPort(outroot, nextAttrib, splitBlock, outputCount, geometry, forSplitBlock=True) nextAttrib += 1 nextAttribForSplit += 1 return (inputCount, outputCount, nextAttrib, nextAttribForSplit) diff --git a/blocks/Xcos/ports/ControlPort.py b/blocks/Xcos/ports/ControlPort.py index eccb3ecf..684bf605 100644 --- a/blocks/Xcos/ports/ControlPort.py +++ b/blocks/Xcos/ports/ControlPort.py @@ -31,8 +31,7 @@ def addControlPortForSplit(outroot, splitBlock, sourceVertex, targetVertex, geometry['height'] = 8 geometry['x'] = -8 geometry['y'] = -4 - ControlPort(outroot, nextAttrib, splitBlock, inputCount, geometry, - forSplitBlock=True) + ControlPort(outroot, nextAttrib, splitBlock, inputCount, geometry, forSplitBlock=True) nextAttrib += 1 nextAttribForSplit += 1 return (inputCount, outputCount, nextAttrib, nextAttribForSplit) diff --git a/blocks/Xcos/ports/ExplicitInputPort.py b/blocks/Xcos/ports/ExplicitInputPort.py index 1178c3f6..39ead3f0 100644 --- a/blocks/Xcos/ports/ExplicitInputPort.py +++ b/blocks/Xcos/ports/ExplicitInputPort.py @@ -36,8 +36,7 @@ def addExplicitInputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex geometry['height'] = 8 geometry['x'] = -8 geometry['y'] = -4 - ExplicitInputPort(outroot, nextAttrib, splitBlock, inputCount, geometry, - forSplitBlock=True) + ExplicitInputPort(outroot, nextAttrib, splitBlock, inputCount, geometry, forSplitBlock=True) nextAttrib += 1 nextAttribForSplit += 1 return (inputCount, outputCount, nextAttrib, nextAttribForSplit) diff --git a/blocks/Xcos/ports/ExplicitOutputPort.py b/blocks/Xcos/ports/ExplicitOutputPort.py index c2fcecdb..2a7d2437 100644 --- a/blocks/Xcos/ports/ExplicitOutputPort.py +++ b/blocks/Xcos/ports/ExplicitOutputPort.py @@ -37,8 +37,7 @@ def addExplicitOutputPortForSplit(outroot, splitBlock, sourceVertex, targetVerte geometry['height'] = 8 geometry['x'] = 7 geometry['y'] = -4 - ExplicitOutputPort(outroot, nextAttrib, splitBlock, outputCount, geometry, - forSplitBlock=True) + ExplicitOutputPort(outroot, nextAttrib, splitBlock, outputCount, geometry, forSplitBlock=True) nextAttrib += 1 nextAttribForSplit += 1 return (inputCount, outputCount, nextAttrib, nextAttribForSplit) diff --git a/blocks/Xcos/ports/ImplicitInputPort.py b/blocks/Xcos/ports/ImplicitInputPort.py index fdbac9f9..d1e5e592 100644 --- a/blocks/Xcos/ports/ImplicitInputPort.py +++ b/blocks/Xcos/ports/ImplicitInputPort.py @@ -39,8 +39,7 @@ def addImplicitInputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex geometry['height'] = 8 geometry['x'] = -8 geometry['y'] = -4 - ImplicitInputPort(outroot, nextAttrib, splitBlock, inputCount, geometry, - forSplitBlock=True) + ImplicitInputPort(outroot, nextAttrib, splitBlock, inputCount, geometry, forSplitBlock=True) nextAttrib += 1 nextAttribForSplit += 1 return (inputCount, outputCount, nextAttrib, nextAttribForSplit) diff --git a/blocks/Xcos/ports/ImplicitOutputPort.py b/blocks/Xcos/ports/ImplicitOutputPort.py index 6e8eff52..e5dc7e0d 100644 --- a/blocks/Xcos/ports/ImplicitOutputPort.py +++ b/blocks/Xcos/ports/ImplicitOutputPort.py @@ -38,8 +38,7 @@ def addImplicitOutputPortForSplit(outroot, splitBlock, sourceVertex, targetVerte geometry['height'] = 8 geometry['x'] = 7 geometry['y'] = -4 - ImplicitOutputPort(outroot, nextAttrib, splitBlock, outputCount, geometry, - forSplitBlock=True) + ImplicitOutputPort(outroot, nextAttrib, splitBlock, outputCount, geometry, forSplitBlock=True) nextAttrib += 1 nextAttribForSplit += 1 return (inputCount, outputCount, nextAttrib, nextAttribForSplit) |