|
8 | 8 | import os
|
9 | 9 | import os.path
|
10 | 10 | from functools import reduce
|
| 11 | +import sys |
| 12 | +import traceback |
11 | 13 |
|
12 | 14 | # Third-party
|
13 | 15 | import cairo
|
@@ -132,59 +134,76 @@ def genicon(
|
132 | 134 | return ctx
|
133 | 135 |
|
134 | 136 |
|
135 |
| -font_map = pangocairo.font_map_get_default() |
136 |
| -font_families = [family.get_name() for family in font_map.list_families()] |
137 |
| -if "CC Icons" not in font_families: |
138 |
| - raise Exception( |
139 |
| - "CC Icons font not installed. See" " <https://wiki.debian.org/Fonts>." |
140 |
| - ) |
| 137 | +def main(): |
| 138 | + font_map = pangocairo.font_map_get_default() |
| 139 | + font_families = [family.get_name() for family in font_map.list_families()] |
| 140 | + if "CC Icons" not in font_families: |
| 141 | + raise Exception( |
| 142 | + "CC Icons font not installed. See" |
| 143 | + " <https://wiki.debian.org/Fonts>." |
| 144 | + ) |
141 | 145 |
|
142 |
| -script_dir = os.path.dirname(__file__) |
143 |
| -basedir = os.path.realpath( |
144 |
| - os.path.abspath(os.path.join(script_dir, "..", "www", "i")) |
145 |
| -) |
146 |
| -print("# basedir:", basedir) |
147 |
| - |
148 |
| -for suite, licenses in SUITES.items(): |
149 |
| - for lic, module_chars in licenses.items(): |
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), |
| 146 | + script_dir = os.path.dirname(__file__) |
| 147 | + basedir = os.path.realpath( |
| 148 | + os.path.abspath(os.path.join(script_dir, "..", "www", "i")) |
| 149 | + ) |
| 150 | + print("# basedir:", basedir) |
| 151 | + |
| 152 | + for suite, licenses in SUITES.items(): |
| 153 | + for lic, module_chars in licenses.items(): |
| 154 | + for chars, dimensions, background, foreground in product( |
| 155 | + module_chars, DIMENSIONS, BACKGROUNDS, FOREGROUNDS |
| 156 | + ): |
| 157 | + # e.g. white on white |
| 158 | + if foreground == background: |
| 159 | + continue |
| 160 | + path = os.path.realpath( |
| 161 | + os.path.abspath( |
| 162 | + os.path.join( |
| 163 | + basedir, |
| 164 | + icon_path(suite, lic, background, foreground), |
| 165 | + ) |
| 166 | + ) |
| 167 | + ) |
| 168 | + filepath = os.path.realpath( |
| 169 | + os.path.abspath( |
| 170 | + os.path.join(path, icon_filename(dimensions, chars)) |
160 | 171 | )
|
161 | 172 | )
|
162 |
| - ) |
163 |
| - filepath = os.path.realpath( |
164 |
| - os.path.abspath( |
165 |
| - os.path.join(path, icon_filename(dimensions, chars)) |
| 173 | + if os.path.exists(filepath): |
| 174 | + continue |
| 175 | + width = dimensions[0] |
| 176 | + height = dimensions[1] |
| 177 | + font_size = dimensions[2] |
| 178 | + padding = dimensions[3] |
| 179 | + ctx = genicon( |
| 180 | + suite, |
| 181 | + chars, |
| 182 | + font_size, |
| 183 | + padding, |
| 184 | + width, |
| 185 | + height, |
| 186 | + background, |
| 187 | + foreground, |
166 | 188 | )
|
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) |
| 189 | + try: |
| 190 | + os.makedirs(path) |
| 191 | + except OSError as e: |
| 192 | + if e.errno != errno.EEXIST: |
| 193 | + raise |
| 194 | + # Will raise and exception on error |
| 195 | + ctx.get_target().write_to_png(filepath) |
| 196 | + |
| 197 | + |
| 198 | +if __name__ == "__main__": |
| 199 | + try: |
| 200 | + main() |
| 201 | + except SystemExit as e: |
| 202 | + sys.exit(e.code) |
| 203 | + except KeyboardInterrupt: |
| 204 | + print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr) |
| 205 | + sys.exit(130) |
| 206 | + except Exception: |
| 207 | + print("ERROR (1) Unhandled exception:", file=sys.stderr) |
| 208 | + print(traceback.print_exc(), file=sys.stderr) |
| 209 | + sys.exit(1) |
0 commit comments