Skip to content

Commit

Permalink
Eliminated unnecessary start and done statements to prevent confusion.
Browse files Browse the repository at this point in the history
  • Loading branch information
autobuild committed Jan 12, 2025
1 parent 41cdf4d commit aa0998f
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 55 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Notable changes:

## 3.0.4

### Features

- Eliminated unnecessary start and done statements to prevent confusion.

## 3.0.3

### Features
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/ibmdiagrams.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Maintainer-email: Jay Warfield <[email protected]>
Expand Down
13 changes: 4 additions & 9 deletions src/ibmdiagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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":
Expand Down
13 changes: 5 additions & 8 deletions src/ibmdiagrams/ibmbase/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ 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)

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

Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions src/ibmdiagrams/ibmbase/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/ibmdiagrams/ibmbase/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
43 changes: 22 additions & 21 deletions src/ibmdiagrams/ibmbase/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class Options:
iconType = ''
labelType = ''
codeType = ''
fontFamily = ''
fontname = ''
quietmode = ''
icons = None
direction = ''
alternate = None
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ibmdiagrams/ibmcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=""):
Expand Down
4 changes: 2 additions & 2 deletions src/ibmdiagrams/ibmcloud/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 9 additions & 7 deletions src/ibmdiagrams/ibmscripts/ibmdiagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
labeltype = ''
codetype = ''
#direction = ''
#fontname = ''
fontname = ''
#fontsize = ''

outputtype = 'drawio'
Expand All @@ -43,27 +43,27 @@ 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()

inputfile = args.inputfile
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()
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit aa0998f

Please sign in to comment.