Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 3fd3624

Browse files
hkielOpenModelica-Hudson
authored andcommitted
make subdirs for hashed SVGs optional
Belonging to [master]: - #2747
1 parent 6571fe8 commit 3fd3624

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Examples/generate_icons.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ def getSvgFromGraphics(dwg, graphics, minX, maxY, includeInvisibleText, transfor
10371037

10381038
# generate svgs from graphics objects
10391039
def generateSvg(filename, iconGraphics, includeInvisibleText, warn_duplicates):
1040-
global element_id
1040+
global element_id, use_subdirs
10411041
element_id = 0
10421042

10431043
width = 100
@@ -1142,12 +1142,14 @@ def generateSvg(filename, iconGraphics, includeInvisibleText, warn_duplicates):
11421142

11431143
dwg.add(group)
11441144
hashName = hashlib.sha1(dwg.tostring().encode("utf-8")).hexdigest() + ".svg"
1145-
hashPath = os.path.join(os.path.dirname(filename),hashName[:1],hashName)
1145+
if use_subdirs:
1146+
hashName = os.path.join(hashName[:1],hashName)
1147+
hashPath = os.path.join(os.path.dirname(filename),hashName)
11461148
if not os.path.exists(hashPath):
11471149
dwg.saveas(hashPath)
11481150
if not os.path.islink(filename):
11491151
try:
1150-
os.symlink(hashPath, filename)
1152+
os.symlink(hashName, filename)
11511153
except OSError as e:
11521154
logger.error('Target file {0} already exists'.format(filename))
11531155
else:
@@ -1189,14 +1191,15 @@ def getBaseClasses(modelica_class, base_classes):
11891191

11901192

11911193
def main():
1192-
global baseDir
1194+
global baseDir, use_subdirs
11931195
t = time.time()
11941196
parser = OptionParser()
11951197
parser.add_option("--with-html", help="Generate an HTML report with all SVG-files", action="store_true", dest="with_html", default=False)
11961198
parser.add_option("--with-invisible-text", action="store_true", help="Includes invisible text containing the original text and bounding box, for debugging purposes", dest="includeInvisibleText", default=False)
11971199
parser.add_option("--output-dir", help="Directory to generate SVG-files in", type="string", dest="output_dir", default=os.path.abspath('ModelicaIcons'))
11981200
parser.add_option("--warn-dup", help="Warn about duplicate files instead of generating an error", action="store_true", dest="warn_duplicates", default=False)
11991201
parser.add_option("--with-json", help="Output icon annotation as json", action="store_true", dest="with_json", default=False)
1202+
parser.add_option("--with-subdirs", help="Output hashed icon files in subdirs", action="store_true", dest="use_subdirs", default=False)
12001203
parser.add_option("--quiet", help="Do not output to the console", action="store_true", dest="quiet", default=False)
12011204
(options, args) = parser.parse_args()
12021205
if len(args) == 0:
@@ -1208,6 +1211,7 @@ def main():
12081211
includeInvisibleText = options.includeInvisibleText
12091212
warn_duplicates = options.warn_duplicates
12101213
with_json = options.with_json
1214+
use_subdirs = options.use_subdirs
12111215

12121216
# create logger with 'spam_application'
12131217
global logger
@@ -1238,11 +1242,18 @@ def main():
12381242
logger.info('Output directory: ' + output_dir)
12391243
print("%s Generating SVGs for package(s) %s" % (datetime.datetime.now(),PACKAGES_TO_GENERATE))
12401244

1241-
for f in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']:
1242-
output_dirx = os.path.join(output_dir, f)
1243-
if not os.path.exists(output_dirx):
1245+
if use_subdirs:
1246+
for f in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']:
1247+
output_dirx = os.path.join(output_dir, f)
1248+
if not os.path.exists(output_dirx):
1249+
try:
1250+
os.makedirs(output_dirx)
1251+
except:
1252+
pass
1253+
else:
1254+
if not os.path.exists(output_dir):
12441255
try:
1245-
os.makedirs(output_dirx)
1256+
os.makedirs(output_dir)
12461257
except:
12471258
pass
12481259

0 commit comments

Comments
 (0)