Esempio n. 1
0
    def getCachedImage(self, project, request, key):
        m = hashlib.md5()
        paramMap = request.parameters()
        urlParam = "&".join(
            ["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
        m.update(urlParam.encode('utf8'))

        if not os.path.exists(
                os.path.join(self._tile_cache_dir,
                             m.hexdigest() + ".png")):
            return QByteArray()

        img = QImage(m.hexdigest() + ".png")
        with open(os.path.join(self._tile_cache_dir,
                               m.hexdigest() + ".png"), "rb") as f:
            statusOK = img.loadFromData(f.read())
            if not statusOK:
                print(
                    "Could not read or find the contents document. Error at line %d, column %d:\n%s"
                    % (errorLine, errorColumn, errorStr))
                return QByteArray()

        ba = QByteArray()
        buff = QBuffer(ba)
        buff.open(QIODevice.WriteOnly)
        img.save(buff, 'PNG')
        return ba
Esempio n. 2
0
 def deleteCachedDocument(self, project, request, key):
     m = hashlib.md5()
     paramMap = request.parameters()
     urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
     m.update(urlParam.encode('utf8'))
     if os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml")):
         os.remove(os.path.join(self._cache_dir, m.hexdigest() + ".xml"))
     return not os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml"))
Esempio n. 3
0
 def setCachedImage(self, img, project, request, key):
     m = hashlib.md5()
     paramMap = request.parameters()
     urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
     m.update(urlParam.encode('utf8'))
     with open(os.path.join(self._tile_cache_dir, m.hexdigest() + ".png"), "wb") as f:
         f.write(img)
     return os.path.exists(os.path.join(self._tile_cache_dir, m.hexdigest() + ".png"))
 def deleteCachedDocument(self, project, request, key):
     m = hashlib.md5()
     paramMap = request.parameters()
     urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
     m.update(urlParam.encode('utf8'))
     if os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml")):
         os.remove(os.path.join(self._cache_dir, m.hexdigest() + ".xml"))
     return not os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml"))
 def setCachedImage(self, img, project, request, key):
     m = hashlib.md5()
     paramMap = request.parameters()
     urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
     m.update(urlParam.encode('utf8'))
     with open(os.path.join(self._tile_cache_dir, m.hexdigest() + ".png"), "wb") as f:
         f.write(img)
     return os.path.exists(os.path.join(self._tile_cache_dir, m.hexdigest() + ".png"))
Esempio n. 6
0
 def setCachedDocument(self, doc, project, request, key):
     if not doc:
         print("Could not cache None document")
         return False
     m = hashlib.md5()
     paramMap = request.parameters()
     urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
     m.update(urlParam.encode('utf8'))
     with open(os.path.join(self._cache_dir, m.hexdigest() + ".xml"), "w") as f:
         f.write(doc.toString())
     return os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml"))
 def setCachedDocument(self, doc, project, request, key):
     if not doc:
         print("Could not cache None document")
         return False
     m = hashlib.md5()
     paramMap = request.parameters()
     urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
     m.update(urlParam.encode('utf8'))
     with open(os.path.join(self._cache_dir, m.hexdigest() + ".xml"), "w") as f:
         f.write(doc.toString())
     return os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml"))
Esempio n. 8
0
    def getCachedDocument(self, project, request, key):
        m = hashlib.md5()
        paramMap = request.parameters()
        urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
        m.update(urlParam.encode('utf8'))

        if not os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml")):
            return QByteArray()

        doc = QDomDocument(m.hexdigest() + ".xml")
        with open(os.path.join(self._cache_dir, m.hexdigest() + ".xml"), "r") as f:
            statusOK, errorStr, errorLine, errorColumn = doc.setContent(f.read(), True)
            if not statusOK:
                print("Could not read or find the contents document. Error at line %d, column %d:\n%s" % (errorLine, errorColumn, errorStr))
                return QByteArray()

        return doc.toByteArray()
    def getCachedDocument(self, project, request, key):
        m = hashlib.md5()
        paramMap = request.parameters()
        urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
        m.update(urlParam.encode('utf8'))

        if not os.path.exists(os.path.join(self._cache_dir, m.hexdigest() + ".xml")):
            return QByteArray()

        doc = QDomDocument(m.hexdigest() + ".xml")
        with open(os.path.join(self._cache_dir, m.hexdigest() + ".xml"), "r") as f:
            statusOK, errorStr, errorLine, errorColumn = doc.setContent(f.read(), True)
            if not statusOK:
                print("Could not read or find the contents document. Error at line %d, column %d:\n%s" % (errorLine, errorColumn, errorStr))
                return QByteArray()

        return doc.toByteArray()
Esempio n. 10
0
    def getCachedImage(self, project, request, key):
        m = hashlib.md5()
        paramMap = request.parameters()
        urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
        m.update(urlParam.encode('utf8'))

        if not os.path.exists(os.path.join(self._tile_cache_dir, m.hexdigest() + ".png")):
            return QByteArray()

        img = QImage(m.hexdigest() + ".png")
        with open(os.path.join(self._tile_cache_dir, m.hexdigest() + ".png"), "rb") as f:
            statusOK = img.loadFromData(f.read())
            if not statusOK:
                print("Could not read or find the contents document. Error at line %d, column %d:\n%s" % (errorLine, errorColumn, errorStr))
                return QByteArray()

        ba = QByteArray()
        buff = QBuffer(ba)
        buff.open(QIODevice.WriteOnly)
        img.save(buff, 'PNG')
        return ba