Skip to content

Commit

Permalink
Do not crash when Bitmap file is not found
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2714
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Oct 10, 2018
1 parent 89692f5 commit b7aefa7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Examples/generate_icons.py
Expand Up @@ -290,12 +290,14 @@ def getGraphicsForClass(modelicaClass):
graphicsObj['href'] = "data:image;base64,"+g[9].strip('"')
else:
fname = ask_omc('uriToFilename', g[8], parsed=False).strip().strip('"')
if not os.path.exists(fname):
fname = os.path.join(baseDir, g[8].strip('"'))
if os.path.exists(fname):
fdata = open(fname, "rb").read()
graphicsObj['href'] = "data:image;base64,"+base64.b64encode(fdata)
else:
fname = os.path.join(baseDir, g[8].strip('"'))
fdata = open(fname, "rb").read()
graphicsObj['href'] = "data:image;base64,"+base64.b64encode(fdata)
logger.error("Could not find bitmap file {0}".format(g[8]))
graphicsObj['href'] = g[8].strip('"')

if not 'type' in graphicsObj:
r = regex_any.search(icon_line)
Expand Down Expand Up @@ -1142,11 +1144,11 @@ def generateSvg(filename, iconGraphics, includeInvisibleText, warn_duplicates):
hashPath = os.path.join(os.path.dirname(filename),hashName[:1],hashName)
if not os.path.exists(hashPath):
dwg.saveas(hashPath)
if not os.path.exists(filename):
if not os.path.islink(filename):
try:
os.symlink(hashName, filename)
except OSError as e:
logger.error(filename + " already exists")
logger.error('Target file {0} already exists'.format(filename))
else:
if warn_duplicates:
logger.warning('Target file {0} already exists'.format(filename))
Expand Down

0 comments on commit b7aefa7

Please sign in to comment.