make.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # vim:fileencoding=utf-8
  3. # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
  4. import os
  5. import shutil
  6. import subprocess
  7. base = os.path.dirname(os.path.abspath(__file__))
  8. unframed_src = os.path.join(base, 'kitty.svg')
  9. framed_src = os.path.join(base, 'kitty-framed.svg')
  10. def abspath(x):
  11. return os.path.join(base, x)
  12. def run(*args):
  13. try:
  14. subprocess.check_call(args)
  15. except OSError:
  16. raise SystemExit(f'You are missing the {args[0]} program needed to generate the kitty logo')
  17. def render(output, sz=256, src=unframed_src):
  18. print(f'Rendering {os.path.basename(src)} at {sz}x{sz}...')
  19. run('rsvg-convert', '-w', str(sz), '-h', str(sz), '-o', output, src)
  20. run('optipng', '-quiet', '-o7', '-strip', 'all', output)
  21. def main():
  22. render(abspath('kitty.png'))
  23. render(abspath('kitty-128.png'), sz=128)
  24. iconset = abspath('kitty.iconset')
  25. if os.path.exists(iconset):
  26. shutil.rmtree(iconset)
  27. os.mkdir(iconset)
  28. os.chdir(iconset)
  29. for sz in (16, 32, 64, 128, 256, 512, 1024):
  30. iname = os.path.join(iconset, 'icon_{0}x{0}.png'.format(sz))
  31. iname2x = 'icon_{0}x{0}@2x.png'.format(sz // 2)
  32. render(iname, sz, src=framed_src)
  33. if sz > 16 and sz != 128:
  34. shutil.copy2(iname, iname2x)
  35. if sz in (64, 1024):
  36. os.remove(iname)
  37. if __name__ == '__main__':
  38. main()