Esempio n. 1
0
def _updateXml(repositoryDir, returnCachedDoc=False):
    addOnsInRepo = _addOnsInRepo(repositoryDir)
    cacheFile = os.path.join(repositoryDir, ".cache.xml")
    global _addOnsInCache
    if (repositoryDir not in _addOnsInCache) or (addOnsInRepo != _addOnsInCache[repositoryDir]) or (not os.path.isfile(cacheFile)):
        impl = xml.dom.minidom.getDOMImplementation()
        cacheDoc = impl.createDocument(None, "OrangeAddOnRepository", None)
        xmlRepo = cacheDoc.documentElement
        for addOn in addOnsInRepo.keys():
            try:
                pack = ZipFile(addOn, 'r')
                try:
                    manifest = fileutil._zip_open(pack, 'addon.xml')
                    addOnXmlDoc = xml.dom.minidom.parse(manifest)
                    addOnXml = addOnXmlDoc.documentElement
                    addOnXml.setAttribute("filename", os.path.split(addOn)[1])
                    addOnXml.appendChild(widgetParser.widgetsXml(pack))   # Temporary: this should be done at upload.
                    addOnXml.normalize()
                    xmlRepo.appendChild(addOnXml)
                finally:
                    pack.close()
            except Exception, e:
                xmlRepo.appendChild(cacheDoc.createComment("Ignoring add-on %s: %s" % (addOn, e)))
        try:
            cacheDoc.writexml(codecs.open(cacheFile, 'w', "utf-8"), encoding="UTF-8")
            _addOnsInCache[repositoryDir] = addOnsInRepo
            return (True, cacheDoc)
        except Exception, e:
            print "Cannot write add-on cache! %s" % e
            return (False, cacheDoc)
Esempio n. 2
0
def widgetsXml(oaoZip):
    files = oaoZip.namelist()
    widgetsTag = xml.dom.minidom.Element("widgets")
    for file in files:
        if re.match(_widgetModuleName, file):
            try:
                filename = file[8:]
                meta = WidgetMetaData(_zip_open(oaoZip, file).read(), "None", filename=filename, hasDoc="1" if ("doc/widgets/%s.htm" % (os.path.splitext(filename)[0][2:]) in files) else "0")
            except:
                continue   # Probably not an Orange widget module
            widgetsTag.appendChild(meta.toXml())
    return widgetsTag
Esempio n. 3
0
def widgetsXml(oaoZip):
    files = oaoZip.namelist()
    widgetsTag = xml.dom.minidom.Element("widgets")
    for file in files:
        if re.match(_widgetModuleName, file):
            try:
                filename = file[8:]
                meta = WidgetMetaData(
                    _zip_open(oaoZip, file).read(),
                    "None",
                    filename=filename,
                    hasDoc="1" if
                    ("doc/widgets/%s.htm" %
                     (os.path.splitext(filename)[0][2:]) in files) else "0")
            except:
                continue  # Probably not an Orange widget module
            widgetsTag.appendChild(meta.toXml())
    return widgetsTag
Esempio n. 4
0
def _updateXml(repositoryDir, returnCachedDoc=False):
    addOnsInRepo = _addOnsInRepo(repositoryDir)
    cacheFile = os.path.join(repositoryDir, ".cache.xml")
    global _addOnsInCache
    if (repositoryDir not in _addOnsInCache) or (
            addOnsInRepo !=
            _addOnsInCache[repositoryDir]) or (not os.path.isfile(cacheFile)):
        impl = xml.dom.minidom.getDOMImplementation()
        cacheDoc = impl.createDocument(None, "OrangeAddOnRepository", None)
        xmlRepo = cacheDoc.documentElement
        for addOn in addOnsInRepo.keys():
            try:
                pack = ZipFile(addOn, 'r')
                try:
                    manifest = fileutil._zip_open(pack, 'addon.xml')
                    addOnXmlDoc = xml.dom.minidom.parse(manifest)
                    addOnXml = addOnXmlDoc.documentElement
                    addOnXml.setAttribute("filename", os.path.split(addOn)[1])
                    addOnXml.appendChild(widgetParser.widgetsXml(
                        pack))  # Temporary: this should be done at upload.
                    addOnXml.normalize()
                    xmlRepo.appendChild(addOnXml)
                finally:
                    pack.close()
            except Exception, e:
                xmlRepo.appendChild(
                    cacheDoc.createComment("Ignoring add-on %s: %s" %
                                           (addOn, e)))
        try:
            cacheDoc.writexml(codecs.open(cacheFile, 'w', "utf-8"),
                              encoding="UTF-8")
            _addOnsInCache[repositoryDir] = addOnsInRepo
            return (True, cacheDoc)
        except Exception, e:
            print "Cannot write add-on cache! %s" % e
            return (False, cacheDoc)