forked from esphome/esphome-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg2png.py
31 lines (25 loc) · 998 Bytes
/
svg2png.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
import os
import shlex
import subprocess
path = '_build/html/_images/'
for from_ in os.listdir(path):
if not from_.endswith('.svg'):
continue
to_ = from_[:-len('.svg')] + '.png'
from_ = os.path.abspath(os.path.join(path, from_))
to_ = os.path.abspath(os.path.join(path, to_))
if os.path.exists(to_):
to_mtime = os.path.getmtime(to_)
from_mtime = os.path.getmtime(from_)
if to_mtime > from_mtime:
# Let's not re-convert files if we've already converted them
# Yes, mtime is not great but it's better than having the builds take
# ages
continue
args = ['inkscape', '-z', '-e', to_, '-w', '800',
'-background', 'white', from_]
print("Running: {}".format(' '.join(shlex.quote(x) for x in args)))
proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if b'Bitmap saved as' not in proc.stdout:
print("Error!")
print(proc.stdout)