/src/test/resources/qooxdoo-sdk/tool/pylib/generator/resource/CombinedImage.py

https://github.com/salmon-charles/qooxdoo-build-tool · Python · 79 lines · 37 code · 13 blank · 29 comment · 5 complexity · 8907195072c110daeba1f4c05e3960a3 MD5 · raw file

  1. #!/usr/bin/env python
  2. ################################################################################
  3. #
  4. # qooxdoo - the new era of web development
  5. #
  6. # http://qooxdoo.org
  7. #
  8. # Copyright:
  9. # 2006-2010 1&1 Internet AG, Germany, http://www.1und1.de
  10. #
  11. # License:
  12. # LGPL: http://www.gnu.org/licenses/lgpl.html
  13. # EPL: http://www.eclipse.org/org/documents/epl-v10.php
  14. # See the LICENSE file in the project's top-level directory for details.
  15. #
  16. # Authors:
  17. # * Thomas Herchenroeder (thron7)
  18. #
  19. ################################################################################
  20. ##
  21. # Class to represent a combined image to the generator, i.e. essentially
  22. # the information of the .meta file without exposing its file layout.
  23. ##
  24. import re, os, sys, types
  25. from misc import filetool, Path, json
  26. from generator import Context
  27. from generator.resource.Image import Image
  28. class CombinedImage(Image):
  29. def __init__(self, path=None):
  30. super(CombinedImage, self).__init__(path)
  31. self.embeds = [] # embedded images
  32. if path:
  33. self.parseMetaFile(path)
  34. def parseMetaFile(self, path):
  35. # Read the .meta file
  36. # it doesn't seem worth to apply caching here
  37. meta_fname = os.path.splitext(path)[0]+'.meta'
  38. meta_content = filetool.read(meta_fname)
  39. imgDict = json.loads(meta_content)
  40. # Loop through the images of the .meta file
  41. for imageId, imageSpec_ in imgDict.items():
  42. # sort of like this: imageId : [width, height, type, combinedUri, off-x, off-y]
  43. imageObject = Image()
  44. imageObject.id = imageId
  45. imageObject = imageObject.fromMeta(imageSpec_)
  46. self.embeds.append(imageObject)
  47. return
  48. def getEmbeddedImages(self):
  49. result = {}
  50. for img, imgObj in self.embeds.items():
  51. result[img] = imgObj
  52. return result
  53. @staticmethod
  54. def isCombinedImage(fpath):
  55. i = fpath.rfind(".")
  56. meta_fname = fpath[:i] + '.meta'
  57. return os.path.exists(meta_fname)
  58. ##
  59. # @overloaded
  60. def toResinfo(self):
  61. result = super(self.__class__, self).toResinfo()
  62. if self.format == "b64" and self.path:
  63. cont = filetool.read(self.path)
  64. cont = json.loads(cont)
  65. result.append(cont)
  66. return result