-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmaster-render.py
executable file
·271 lines (236 loc) · 7.06 KB
/
master-render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/python3
"""
# This file is part of the Pop Icon Theme and is free software; you can
# redistribute it and/or modify it under the terms of the GNU Lesser General
# Public License as published by the Free Software Foundation; version 3.
#
# This file is part of the Pop Icon Theme and is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <https://www.gnu.org/licenses/lgpl-3.0.txt>
"""
import argparse
from ast import parse
import os
import shutil
import subprocess
from pathlib import Path
from importlib_metadata import sys
THEMENAME:str = 'Pop'
BINDIR = Path('/usr/bin')
BASEDIR = Path(os.getcwd())
SRCDIR = BASEDIR / 'src'
THEMEDIR = BASEDIR / THEMENAME
SIZES = (
'8x8',
'16x16',
'24x24',
'32x32',
'48x48',
'64x64',
'128x128',
'256x256',
'512x512'
)
## Rendering Functions
def render_fullcolor() -> None:
print(' -- Rendering bitmap icons...')
os.chdir(SRCDIR / 'fullcolor')
try:
subprocess.run('./render-fullcolor.py', check=True)
except subprocess.CalledProcessError:
print('Failed to render fullcolor icons. See output above.')
sys.exit(1)
def render_symbolics() -> None:
print(' -- Rendering symbolic icons...')
os.chdir(SRCDIR / 'scalable')
try:
subprocess.run('./extract-symbolic-icons.rb', check=True)
except subprocess.CalledProcessError:
print('Failed to render symbolic icons. See output above.')
sys.exit(1)
def cleanup_unoptomized_renders() -> None:
print(' -- Cleaning up any unoptimized output')
def generate_symlinks() -> None:
print(' -- Generating symbolic links...')
os.chdir(SRCDIR / 'symlinks')
try:
subprocess.run('./generate-symlinks.sh', check=True)
except subprocess.CalledProcessError:
print('Failed to generate fullcolor symlinks. See output above.')
sys.exit(1)
os.chdir(SRCDIR / 'scalable')
try:
subprocess.run('./generate-symbolic-symlinks.sh', check=True)
except subprocess.CalledProcessError:
print('Failed to generate sylbolic symlinks. See output above.')
sys.exit(1)
def render_cursors() -> None:
print(' -- Rendering cursors...')
cursors_dir = SRCDIR / 'cursors'
template_dir = cursors_dir / 'templates'
output_dir = cursors_dir / 'bitmaps'
os.chdir(cursors_dir)
if output_dir.exists():
print(' -- Output dir exists, use --clean to re-render')
return
shutil.copytree(template_dir, output_dir)
print(' -- Rendering cursor fullcolor')
subprocess.run(['./render-cursors.py', '-n 0', 'source-cursors.svg'])
print(' -- Generatig cursor files')
subprocess.run('./x11-make.sh')
subprocess.run('./w32-make.sh')
def install_metadata() -> None:
print(' -- Installing theme Metadata...')
for file in ('index.theme', 'cursor.theme'):
file_path = BASEDIR / f'{file}.in'
shutil.copyfile(file_path, f'{THEMEDIR}/{file}')
## Artifact Cleanup/Removal Functions
def clean_fullcolor() -> None:
print(' -- Removing Fullcolor Icons')
for size in SIZES:
size_dir = THEMEDIR / size
if size_dir.exists():
print(f' -- Removing {size_dir}')
shutil.rmtree(size_dir)
else:
print(f' ** Skipping {size_dir}')
def clean_symbolics() -> None:
scalable_dir = THEMEDIR / 'scalable'
if scalable_dir.exists():
print(' -- Removing symbolic icons')
shutil.rmtree(scalable_dir)
def clean_cursors() -> None:
cursor_dir = THEMEDIR / 'cursors'
cursors_dir = SRCDIR / 'cursors'
template_dir = cursors_dir / 'templates'
output_dir = cursors_dir / 'bitmaps'
if cursor_dir.exists():
print(' -- Removing cursors')
shutil.rmtree(cursor_dir)
if output_dir.exists():
print(' -- Cleaning up old render')
shutil.rmtree(output_dir)
def clean_metadata() -> None:
print(' -- Removing Metadata')
for file in ('index.theme', 'cursor.theme'):
file_path = THEMEDIR / file
try:
file_path.unlink()
print(f' -- Removed {file}')
except FileNotFoundError:
print(f' ** Skipping {file}')
def clean_dirs(**kwargs) -> None:
print('\n-- Cleaning up previous renders')
os.chdir(THEMEDIR)
if kwargs['everything']:
print(' -- Performing Full Cleanup')
clean_fullcolor()
clean_symbolics()
clean_cursors()
clean_metadata()
return
# Cleanup Fullcolors
if kwargs['fullcolor']:
clean_fullcolor()
else:
print(' ** Skipping removing fullcolor')
# Cleanup Symbolics
if kwargs['symbolics']:
clean_symbolics()
else:
print(' ** Skipping removing symbolic icons')
# Cleanup Cursors
if kwargs['cursors']:
clean_cursors()
else:
print(' ** Skipping removing Cursors')
# Cleanup Metadata
if kwargs['metadata']:
clean_metadata()
else:
print(' ** Skipping removing Metadata')
print('\n\n')
def do_render(args) -> None:
if args.clean:
clean_dirs(
everything=args.all,
fullcolor=args.fullcolor,
symbolics=args.symbolics,
cursors=args.cursors,
metadata=args.metadata
)
print('\n--Rendering icons')
if args.all:
render_fullcolor()
render_symbolics()
render_cursors()
generate_symlinks()
install_metadata()
return
if args.fullcolor:
render_fullcolor()
if args.symbolics:
render_symbolics()
if args.cursors:
render_cursors()
if args.links:
generate_symlinks()
if args.metadata:
install_metadata()
parser = argparse.ArgumentParser(description='Render icons for the Pop Icon Theme')
parser.add_argument(
'-c',
'--clean',
action='store_true',
help='Remove existing files before rendering (takes a long time to render)'
)
parser.add_argument(
'-a',
'--all',
action='store_true',
help='Render all items (Default)'
)
parser.add_argument(
'-f',
'--fullcolor',
action='store_true',
help='Render fullcolor icons'
)
parser.add_argument(
'-s',
'--symbolics',
action='store_true',
help='Render Symbolic Icons'
)
parser.add_argument(
'-x',
'--cursors',
action='store_true',
help='Render Cursors'
)
parser.add_argument(
'-l',
'--links',
action='store_true',
help='Generate Theme Symlinks'
)
parser.add_argument(
'-m',
'--metadata',
action='store_true',
help='Generate Metadata'
)
args = parser.parse_args()
if not True in (args.fullcolor,
args.symbolics,
args.cursors,
args.links,
args.metadata):
args.all = True
else:
args.all = False
do_render(args)