From aa0998f8e1d9693b5a65ed5f9b799fc1885b12da Mon Sep 17 00:00:00 2001 From: autobuild Date: Sat, 11 Jan 2025 20:45:45 -0500 Subject: [PATCH] Eliminated unnecessary start and done statements to prevent confusion. --- CHANGELOG.md | 6 ++++ pyproject.toml | 2 +- src/ibmdiagrams.egg-info/PKG-INFO | 2 +- src/ibmdiagrams/__init__.py | 13 +++---- src/ibmdiagrams/ibmbase/build.py | 13 +++---- src/ibmdiagrams/ibmbase/common.py | 4 +-- src/ibmdiagrams/ibmbase/compose.py | 9 +++-- src/ibmdiagrams/ibmbase/options.py | 43 ++++++++++++----------- src/ibmdiagrams/ibmcloud/__init__.py | 4 +-- src/ibmdiagrams/ibmcloud/diagram.py | 4 +-- src/ibmdiagrams/ibmscripts/ibmdiagrams.py | 16 +++++---- 11 files changed, 61 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 801136c..2677bcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Notable changes: +## 3.0.4 + +### Features + +- Eliminated unnecessary start and done statements to prevent confusion. + ## 3.0.3 ### Features diff --git a/pyproject.toml b/pyproject.toml index ce00bca..e0f1b1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ibmdiagrams" -version = "3.0.3" +version = "3.0.4" description = "Generate architecture diagrams following IBM Diagram Standard" readme = "README.md" requires-python = ">=3.11.0" diff --git a/src/ibmdiagrams.egg-info/PKG-INFO b/src/ibmdiagrams.egg-info/PKG-INFO index 4bb9b02..f790c79 100644 --- a/src/ibmdiagrams.egg-info/PKG-INFO +++ b/src/ibmdiagrams.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.2 Name: ibmdiagrams -Version: 3.0.3 +Version: 3.0.4 Summary: Generate architecture diagrams following IBM Diagram Standard Author-email: Jay Warfield Maintainer-email: Jay Warfield diff --git a/src/ibmdiagrams/__init__.py b/src/ibmdiagrams/__init__.py index 8aad66f..281f2af 100644 --- a/src/ibmdiagrams/__init__.py +++ b/src/ibmdiagrams/__init__.py @@ -82,20 +82,15 @@ class Diagrams: common = None properties = {} diagramid = None - fontname = None def __init__(self, name = "", - filename = "", - fontname = "IBM Plex Sans"): + filename = ""): self.common = Common() self.common.setInputPython() self.diagramid = randomid() - self.fontname = fontname - self.common.setFontName(self.fontname) - - self.properties = _data.getDiagramsProperties(name=name, filename=filename, fontname=self.ffontname) + self.properties = _data.getDiagramsProperties(name=name, filename=filename) _data.addSheets(self.diagramid, self.properties) return @@ -123,14 +118,14 @@ def __init__(self, output = "", #input = "", #icontype = "STATIC", - fontname = "IBM Plex Sans", + font = "IBM Plex Sans", direction = "LR"): self.common = Common() self.common.setInputPython() self.diagramid = randomid() self.name = name - self.fontname = fontname + self.fontname = font self.common.setFontName(self.fontname) if direction.upper() == "LR": diff --git a/src/ibmdiagrams/ibmbase/build.py b/src/ibmdiagrams/ibmbase/build.py index 85e3a30..eaed507 100644 --- a/src/ibmdiagrams/ibmbase/build.py +++ b/src/ibmdiagrams/ibmbase/build.py @@ -101,10 +101,8 @@ def buildSheets(self, properties, diagrams): outputfile = outputfile if outputfile != "" else diagramname + ".drawio" outputfolder = self.common.getOutputFolder() - if (self.common.isInputPython()): - self.common.printStartDiagram(diagramname + ".py", provider) - else: - self.common.printStartDiagram(diagramname, provider) + if self.common.isInputPython(): + self.common.printStartDiagram(diagramname + ".py", provider) for name, diagram in diagrams.items(): self.shapes.buildXML(diagram, name) @@ -112,7 +110,8 @@ def buildSheets(self, properties, diagrams): self.shapes.dumpXML(outputfile, outputfolder) self.shapes.resetXML() - self.common.printDone(path.join(outputfolder, outputfile), provider) + if self.common.isInputPython(): + self.common.printDone(path.join(outputfolder, outputfile), provider) return @@ -131,10 +130,8 @@ def buildDiagrams(self): if properties["filename"] != "*": outputfile = properties["filename"] + ".drawio" diagramname = properties["name"] - if (self.common.isInputPython()): + if self.common.isInputPython(): self.common.printStartDiagram(diagramname + ".py", provider) - else: - self.common.printStartDiagram(diagramname, provider) self.setupAll() diff --git a/src/ibmdiagrams/ibmbase/common.py b/src/ibmdiagrams/ibmbase/common.py index ef56d77..1da2fd7 100644 --- a/src/ibmdiagrams/ibmbase/common.py +++ b/src/ibmdiagrams/ibmbase/common.py @@ -148,8 +148,8 @@ def getOutputBase(self): def getFontName(self): return self.options.getFontName() - def setFontName(self, fontName): - self.options.setFontName(fontName) + def setFontName(self, fontname): + self.options.setFontName(fontname) def isCustomLabels(self): return self.labelType == LabelTypes.CUSTOM diff --git a/src/ibmdiagrams/ibmbase/compose.py b/src/ibmdiagrams/ibmbase/compose.py index 49cacda..a22898e 100644 --- a/src/ibmdiagrams/ibmbase/compose.py +++ b/src/ibmdiagrams/ibmbase/compose.py @@ -22,6 +22,8 @@ # ibmdiagrams/ibmbase/elements.py - build drawio objects import pandas as pd +import subprocess +import sys from os import path, remove from math import isnan @@ -67,7 +69,10 @@ def composeDiagrams(self): self.composeResources(self.top, True, pythonfile) pythonfile.close() if self.common.isDrawioCode(): - exec(open(filelocation).read()) + #exec(open(filelocation).read()) + result = subprocess.run([sys.executable, filelocation], capture_output=True, text=True) + #print(result.stdout) + #print(result.stderr) remove(filelocation) return @@ -194,7 +199,7 @@ def composeResources(self, parent, useCustomLabel, pythonfile): if fontname == None: fontname = "" else: - fontname = ", fontname='" + fontname + "'" + fontname = ", font='" + fontname + "'" index = name.find("Group") if index != -1: diff --git a/src/ibmdiagrams/ibmbase/options.py b/src/ibmdiagrams/ibmbase/options.py index d721367..7341719 100644 --- a/src/ibmdiagrams/ibmbase/options.py +++ b/src/ibmdiagrams/ibmbase/options.py @@ -84,7 +84,8 @@ class Options: iconType = '' labelType = '' codeType = '' - fontFamily = '' + fontname = '' + quietmode = '' icons = None direction = '' alternate = None @@ -100,7 +101,7 @@ def __init__(self): self.labelType = LabelTypes.CUSTOM self.codeType = CodeTypes.DRAWIO self.direction = Directions.LR - self.fontName = FontNames.IBM_PLEX_SANS + self.fontname = FontNames.IBM_PLEX_SANS #self.inputFile = 'input.json' #self.inputFolder = path.join(path.expanduser('~'), 'Documents', toolName) #self.outputFile = 'diagram.xml' @@ -258,26 +259,26 @@ def setDrawioCode(self): self.codeType = CodeTypes.DRAWIO def getFontName(self): - return self.fontName.value - - def setFontName(self, fontName): - fontName = fontName.upper() - if fontName == 'IBM PLEX SANS': - self.fontName = FontNames.IBM_PLEX_SANS - elif fontName == 'IBM PLEX SANS ARABIC': - self.fontName = FontNames.IBM_PLEX_SANS_ARABIC - elif fontName == 'IBM PLEX SANS DEVANAGARI': - self.fontName = FontNames.IBM_PLEX_SANS_DEVANAGARI - elif fontName == 'IBM PLEX SANS HEBREW': - self.fontName = FontNames.IBM_PLEX_SANS_HEBREW - elif fontName == 'IBM PLEX SANS JP': - self.fontName = FontNames.IBM_PLEX_SANS_JP - elif fontName == 'IBM PLEX SANS KR': - self.fontName = FontNames.IBM_PLEX_SANS_KR - elif fontName == 'IBM PLEX SANS THAI': - self.fontName = FontNames.IBM_PLEX_SANS_THAI + return self.fontname.value + + def setFontName(self, fontname): + fontname = fontname.upper() + if fontname == 'IBM PLEX SANS': + self.fontname = FontNames.IBM_PLEX_SANS + elif fontname == 'IBM PLEX SANS ARABIC': + self.fontname = FontNames.IBM_PLEX_SANS_ARABIC + elif fontname == 'IBM PLEX SANS DEVANAGARI': + self.fontname = FontNames.IBM_PLEX_SANS_DEVANAGARI + elif fontname == 'IBM PLEX SANS HEBREW': + self.fontname = FontNames.IBM_PLEX_SANS_HEBREW + elif fontname == 'IBM PLEX SANS JP': + self.fontname = FontNames.IBM_PLEX_SANS_JP + elif fontname == 'IBM PLEX SANS KR': + self.fontname = FontNames.IBM_PLEX_SANS_KR + elif fontname == 'IBM PLEX SANS THAI': + self.fontname = FontNames.IBM_PLEX_SANS_THAI else: - self.fontName = FontNames.IBM_PLEX_SANS + self.fontname = FontNames.IBM_PLEX_SANS def getIcons(self): return self.icons diff --git a/src/ibmdiagrams/ibmcloud/__init__.py b/src/ibmdiagrams/ibmcloud/__init__.py index e351bfd..7388b85 100644 --- a/src/ibmdiagrams/ibmcloud/__init__.py +++ b/src/ibmdiagrams/ibmcloud/__init__.py @@ -16,9 +16,9 @@ from ibmdiagrams import Diagram, Group, Item, Connector class _IBMDiagram(Diagram): - def __init__(self, name, filename="", direction="", output="", fontname="IBM Plex Sans", provider="ibm"): + def __init__(self, name, filename="", direction="", output="", font="IBM Plex Sans"): super(_IBMDiagram, self).__init__(name=name, filename=filename, output=output, - fontname=fontname, direction=direction) + font=font, direction=direction) class _IBMGrouping(Group): def __init__(self, label, sublabel="", linecolor="", fillcolor="", shape="", icon="", direction=""): diff --git a/src/ibmdiagrams/ibmcloud/diagram.py b/src/ibmdiagrams/ibmcloud/diagram.py index 5a7d4c7..279bde8 100644 --- a/src/ibmdiagrams/ibmcloud/diagram.py +++ b/src/ibmdiagrams/ibmcloud/diagram.py @@ -17,12 +17,12 @@ from .colors import Colors class IBMDiagram(_IBMDiagram): - def __init__(self, name, filename="", output="", fontname="IBM Plex Sans", direction=""): + def __init__(self, name, filename="", output="", font="IBM Plex Sans", direction=""): if filename == "": filename = name super(IBMDiagram, self).__init__(name=name, filename=filename, output=output, - fontname=fontname, direction=direction) + font=font, direction=direction) # Aliases Diagram = IBMDiagram diff --git a/src/ibmdiagrams/ibmscripts/ibmdiagrams.py b/src/ibmdiagrams/ibmscripts/ibmdiagrams.py index 07f9bb0..a04a76f 100644 --- a/src/ibmdiagrams/ibmscripts/ibmdiagrams.py +++ b/src/ibmdiagrams/ibmscripts/ibmdiagrams.py @@ -31,7 +31,7 @@ def main(): labeltype = '' codetype = '' #direction = '' - #fontname = '' + fontname = '' #fontsize = '' outputtype = 'drawio' @@ -43,13 +43,13 @@ def main(): description='Generate architecture diagrams following IBM Diagram Standard.', epilog='https://github.com/IBM/ibmdiagrams') + parser.add_argument('inputfile', help='required input file name (terraform file)') parser.add_argument('-output', dest='outputfolder', default='', help='output folder') #parser.add_argument('-direction', dest='direction', default='LR', help='layout direction (LR or TB)') parser.add_argument('--general', dest='labeltype', action='store_const', const='GENERAL', default='CUSTOM', help='general labels (default: custom labels)') parser.add_argument('--python', dest='codetype', action='store_const', const='PYTHON', default='DRAWIO', help='code type (default: drawio)') - #parser.add_argument('-fontname', dest='fontname', default=common.getFontName(), help='font name') - #parser.add_argument('-fontsize', dest='fontsize', default=common.getFpntSize()', help='font size') + parser.add_argument('-font', dest='fontname', default='IBM Plex Sans', help='font name') args = parser.parse_args() @@ -57,13 +57,13 @@ def main(): outputfolder = args.outputfolder labeltype = args.labeltype codetype = args.codetype - #direction = args.direction - #fontname = args.fontname + fontname = args.fontname #fontsize = args.fontsize outputtype = 'drawio' common.setInputFile(inputfile) common.setOutputFolder(outputfolder) + common.setFontName(fontname) if labeltype.upper() == "GENERAL": common.setGeneralLabels() @@ -101,14 +101,16 @@ def main(): else: common.printExit() elif inputtype == 'tfstate': - if common.isDrawioCode(): - common.printStartFile(inputfile, common.getProvider().value.upper()) + common.printStartFile(inputfile, common.getProvider().value.upper()) data = Load(common) if data.loadData(): compose = Compose(common, data) compose.composeDiagrams() if common.isDrawioCode(): common.printDone(path.join(outputfolder, outputfile), common.getProvider().value.upper()) + elif common.isPythonCode(): + splitfile = path.splitext(outputfile) + common.printDone(path.join(outputfolder, splitfile[0] + ".py"), common.getProvider().value.upper()) else: common.printExit()