Skip to content

Commit 3fe3ae2

Browse files
authored
Merge pull request #18 from keshav2212/master
Removed nesting of for loops
2 parents d77c325 + 36098d8 commit 3fe3ae2

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

scripts/genicons.py

+45-49
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
# Standard library
55
import errno
6+
from itertools import product
67
import math
78
import os
89
import os.path
910

1011
# Third-party
1112
import cairo
1213
import gi
13-
gi.require_version('PangoCairo', '1.0')
14+
15+
gi.require_version("PangoCairo", "1.0")
1416
from gi.repository import PangoCairo as pangocairo
1517
from functools import reduce
1618

@@ -40,7 +42,7 @@
4042
STEPS = ["00", "11", "22", "33", "66", "99", "ff"]
4143

4244
FOREGROUNDS = [
43-
"%s%s%s" % (r, g, b) for r in STEPS for g in STEPS for b in STEPS
45+
"%s%s%s" % (r, g, b) for r, g, b in product(STEPS, STEPS, STEPS)
4446
]
4547

4648
HEX_TO_FLOAT = 1.0 / 255.0
@@ -145,50 +147,44 @@ def genicon(
145147

146148
for suite, licenses in SUITES.items():
147149
for lic, module_chars in licenses.items():
148-
for chars in module_chars:
149-
for dimensions in DIMENSIONS:
150-
for background in BACKGROUNDS:
151-
for foreground in FOREGROUNDS:
152-
# e.g. white on white
153-
if foreground == background:
154-
continue
155-
path = os.path.realpath(
156-
os.path.abspath(
157-
os.path.join(
158-
basedir,
159-
icon_path(
160-
suite, lic, background, foreground
161-
),
162-
)
163-
)
164-
)
165-
filepath = os.path.realpath(
166-
os.path.abspath(
167-
os.path.join(
168-
path, icon_filename(dimensions, chars)
169-
)
170-
)
171-
)
172-
if os.path.exists(filepath):
173-
continue
174-
width = dimensions[0]
175-
height = dimensions[1]
176-
font_size = dimensions[2]
177-
padding = dimensions[3]
178-
ctx = genicon(
179-
suite,
180-
chars,
181-
font_size,
182-
padding,
183-
width,
184-
height,
185-
background,
186-
foreground,
187-
)
188-
try:
189-
os.makedirs(path)
190-
except OSError as e:
191-
if e.errno != errno.EEXIST:
192-
raise
193-
# Will raise and exception on error
194-
ctx.get_target().write_to_png(filepath)
150+
for chars, dimensions, background, foreground in product(
151+
module_chars, DIMENSIONS, BACKGROUNDS, FOREGROUNDS
152+
):
153+
# e.g. white on white
154+
if foreground == background:
155+
continue
156+
path = os.path.realpath(
157+
os.path.abspath(
158+
os.path.join(
159+
basedir, icon_path(suite, lic, background, foreground),
160+
)
161+
)
162+
)
163+
filepath = os.path.realpath(
164+
os.path.abspath(
165+
os.path.join(path, icon_filename(dimensions, chars))
166+
)
167+
)
168+
if os.path.exists(filepath):
169+
continue
170+
width = dimensions[0]
171+
height = dimensions[1]
172+
font_size = dimensions[2]
173+
padding = dimensions[3]
174+
ctx = genicon(
175+
suite,
176+
chars,
177+
font_size,
178+
padding,
179+
width,
180+
height,
181+
background,
182+
foreground,
183+
)
184+
try:
185+
os.makedirs(path)
186+
except OSError as e:
187+
if e.errno != errno.EEXIST:
188+
raise
189+
# Will raise and exception on error
190+
ctx.get_target().write_to_png(filepath)

0 commit comments

Comments
 (0)