You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.8 KiB

  1. #!/usr/bin/env python
  2. # Regenerate the icons in resources/linux/mime based on the mime files
  3. # and the original icons in bitmaps_png. Must be run from the scripts
  4. # folder for the relative paths to work.
  5. #
  6. # This script assumes Inkscape is installed and in the PATH
  7. import os, glob
  8. import xml.etree.ElementTree as ET
  9. from shutil import copyfile, rmtree
  10. from subprocess import call
  11. ICON_SOURCES = "../bitmaps_png/sources/"
  12. DEST_FOLDER = "../resources/linux/mime"
  13. def icon_sourcename(icon):
  14. return ICON_SOURCES+"/icon_%s.svg" % icon
  15. # Get a list of the applications we will install, their icons and mimes
  16. app_icons = {}
  17. for desktopfile in glob.glob(DEST_FOLDER+"/applications/*.desktop"):
  18. icon = None
  19. mimes = []
  20. for line in open(desktopfile):
  21. keypair = map(str.strip, line.split("="))
  22. if len(keypair) != 2: continue
  23. key, value = keypair
  24. if key == "Icon":
  25. icon = value
  26. elif key == "MimeType":
  27. mimes = [x.strip() for x in value.split(";") if str.strip(x)]
  28. if icon is None:
  29. print "WARNING: file '", desktopfile, "' contains no Icon entry, corrupted?"
  30. continue
  31. else:
  32. app_icons[icon] = mimes;
  33. # Obtain the mime types we provide from the mime package XML
  34. MIME_PACKAGE = DEST_FOLDER+"/mime/packages/kicad-kicad.xml"
  35. mimepkg_root = ET.parse(MIME_PACKAGE).getroot()
  36. mimepkg_mimetypes = [n.attrib['type'] for n in mimepkg_root]
  37. # Reconcile mime types
  38. mime_icons = {}
  39. for mime in mimepkg_mimetypes:
  40. for icon, mimes in app_icons.iteritems():
  41. if mime in mimes:
  42. mime_icons[mime.replace('/','-')] = icon
  43. break
  44. else:
  45. print "WARNING: mimetype'", mime,"' is provided in the package, but no app is associated with it."
  46. RESOLUTIONS = [16,22,24,32,48,64,128]
  47. rmtree(DEST_FOLDER+'/icons')
  48. os.makedirs(DEST_FOLDER+'/icons/hicolor/scalable/apps')
  49. os.makedirs(DEST_FOLDER+'/icons/hicolor/scalable/mimetypes')
  50. for r in RESOLUTIONS:
  51. os.makedirs(DEST_FOLDER+'/icons/hicolor/%ix%i/apps' % (r,r))
  52. os.makedirs(DEST_FOLDER+'/icons/hicolor/%ix%i/mimetypes' % (r,r))
  53. for icon in app_icons.keys():
  54. copyfile(icon_sourcename(icon),
  55. DEST_FOLDER+"/icons/hicolor/scalable/apps/%s.svg" % icon)
  56. for r in RESOLUTIONS:
  57. call(['inkscape', '-f', icon_sourcename(icon),
  58. '-e', DEST_FOLDER+'/icons/hicolor/%ix%i/apps/%s.png' % (r, r, icon),
  59. '-w', str(r), '-h', str(r), '--export-area-snap'])
  60. for mime, icon in mime_icons.iteritems():
  61. copyfile(icon_sourcename(icon),
  62. DEST_FOLDER+"/icons/hicolor/scalable/mimetypes/%s.svg" % mime)
  63. for r in RESOLUTIONS:
  64. call(['inkscape', '-f', icon_sourcename(icon),
  65. '-e', DEST_FOLDER+'/icons/hicolor/%ix%i/mimetypes/%s.png' % (r, r, mime),
  66. '-w', str(r), '-h', str(r), '--export-area-snap'])