make_icon_link.txt.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/python
  2. #
  3. # This file is part of the LibreOffice project.
  4. #
  5. # This Source Code Form is subject to the terms of the Mozilla Public
  6. # License, v. 2.0. If a copy of the MPL was not distributed with this
  7. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. #
  9. #
  10. # Generate XSL equivalent for Colibre icon images from link.txt
  11. #
  12. import sys
  13. try:
  14. # open file stream
  15. file_icon = open("../icon-themes/colibre/links.txt", "r")
  16. except IOError:
  17. print "There was an error reading", file_icon
  18. sys.exit()
  19. try:
  20. # open file stream
  21. file_xsl = open("help3xsl/links.txt.xsl", "w+")
  22. except IOError:
  23. print "There was an error writing", file_xsl
  24. sys.exit()
  25. file_xsl.write('<?xml version="1.0" encoding="UTF-8"?>\n');
  26. file_xsl.write('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n');
  27. file_xsl.write('<xsl:template name="linktxt">\n');
  28. file_xsl.write('<xsl:param name="src1"/>\n');
  29. file_xsl.write('<xsl:choose>\n')
  30. for line in file_icon:
  31. if line[0] != "#" :
  32. if line.find('png',0, len(line)) <> -1 :
  33. a = "\'" + line.split()[0] + "\'"
  34. b = line.split()[1]
  35. file_xsl.write('<xsl:when test="$src1=' + a + '"><xsl:text>'+ b + '</xsl:text></xsl:when>\n');
  36. file_xsl.write('<xsl:otherwise><xsl:value-of select="$src1"/></xsl:otherwise>\n');
  37. file_xsl.write('</xsl:choose>\n');
  38. file_xsl.write('</xsl:template>\n');
  39. file_xsl.write('</xsl:stylesheet>\n');
  40. file_xsl.close()
  41. file_icon.close()
  42. sys.exit()