Dont use chdir() in logo/make.py

This commit is contained in:
Kovid Goyal 2019-06-28 13:44:42 +05:30
parent 9dadd91887
commit a56475e32f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -6,8 +6,12 @@ import os
import subprocess
import shutil
os.chdir(os.path.dirname(os.path.abspath(__file__)))
src = os.path.abspath('kitty.svg')
base = os.path.dirname(os.path.abspath(__file__))
src = os.path.join(base, 'kitty.svg')
def abspath(x):
return os.path.join(base, x)
def run(*args):
@ -23,18 +27,23 @@ def render(output, sz=256):
run('optipng', '-quiet', '-o7', '-strip', 'all', output)
render('kitty.png')
run('convert', 'kitty.png', '-depth', '8', 'kitty.rgba')
iconset = 'kitty.iconset'
if os.path.exists(iconset):
shutil.rmtree(iconset)
os.mkdir(iconset)
os.chdir(iconset)
for sz in (16, 32, 64, 128, 256, 512, 1024):
iname = 'icon_{0}x{0}.png'.format(sz)
iname2x = 'icon_{0}x{0}@2x.png'.format(sz // 2)
render(iname, sz)
if sz > 16 and sz != 128:
shutil.copy2(iname, iname2x)
if sz in (64, 1024):
os.remove(iname)
def main():
render(abspath('kitty.png'))
run('convert', abspath('kitty.png'), '-depth', '8', abspath('kitty.rgba'))
iconset = abspath('kitty.iconset')
if os.path.exists(iconset):
shutil.rmtree(iconset)
os.mkdir(iconset)
os.chdir(iconset)
for sz in (16, 32, 64, 128, 256, 512, 1024):
iname = os.path.join(iconset, 'icon_{0}x{0}.png'.format(sz))
iname2x = 'icon_{0}x{0}@2x.png'.format(sz // 2)
render(iname, sz)
if sz > 16 and sz != 128:
shutil.copy2(iname, iname2x)
if sz in (64, 1024):
os.remove(iname)
if __name__ == '__main__':
main()