def updateChildrenWithPK(self, dataobject, pk="name"):
    """ add all children from dataobject
    if they are not already there.
    pk is used as primary key.
    Also adds all Attributes from dataobject if the are not present.
    """
    XmlTools.merge_trees_with_pk(dataobject.getElement(), self.element, self.document, pk)
Exemplo n.º 2
0
 def getPartNames(self):
     schema = XmlTools().getXsdDoc()
     return [
         e.get("name")
         for e in filter(lambda x: x.get("type") == "depsListType",
                         schema.findall('/{%s}element' % XmlTools.xsd_uri))
     ]
Exemplo n.º 3
0
    def __init__(self, configfile):
        UserDict.__init__(self)
        XmlTools().init(configfile)
        self.xmldoc = XmlTools().getXmlDoc()
        self.depsFactory = DependsFactory(self.xmldoc)

        self.__validate__()
 def searchReference(self, element, doc):
     name = "unnamed"
     try:
         if element.hasAttribute("name"):
             name = element.getAttribute("name")
         __xquery = "//"
         #            __xquery+=element.tagName
         __xquery += "*"
         __xquery += '[@id="'
         __xquery += element.getAttribute("refid")
         __xquery += '"]'
         # cloneNode to be safe
         __element = XmlTools.evaluateXPath(__xquery, doc)[0]
         ComLog.getLogger("DataObject").debug("found refid " + element.getAttribute("refid"))
         __childs = XmlTools.evaluateXPath("./*", element)
         __new = __element.cloneNode(True)
         self.appendChildren(__new, __childs)
         return __new
     except exceptions.Exception:
         raise ComException(
             "Element "
             + element.tagName
             + " with name "
             + name
             + " and id "
             + element.getAttribute("refid")
             + " not found. Query: "
             + __xquery
         )
Exemplo n.º 5
0
 def getRelationNames(self):
     schema = XmlTools().getXsdDoc()
     complexType = filter(
         lambda x: x.get("name") == "depsListType",
         schema.findall('{%s}complexType' % XmlTools.xsd_uri))[0]
     return [
         e.get("ref") for e in complexType.find(
             '{%s}sequence' % XmlTools.xsd_uri).findall('{%s}element' %
                                                        XmlTools.xsd_uri)
     ]
Exemplo n.º 6
0
class ConfigXml(UserDict):
# Implementation of the config.xml parser.

    xmldoc = None
    depsFactory = None
    dist = None

    nameRe = re.compile(r'^[a-z0-9][a-z0-9+-\.]+$')

    def __init__(self, configfile):
        UserDict.__init__(self)
        XmlTools().init(configfile)
        self.xmldoc = XmlTools().getXmlDoc()
        self.depsFactory = DependsFactory(self.xmldoc)

        #print self.xmldoc.findall("class")

        self.__validate__()

    def __validate__(self):
        XmlTools().validate()
        if not self.nameRe.match(self['name']):
            raise OpkgSyntaxException('Incorrect package name syntax (pattern: [a-z0-9][a-z0-9+-\.]+)')

    def __getitem__(self, key):
        if key == 'version':
            return self.xmldoc.find('changelog/versionEntry').get('version').strip()
        else:
            return self.xmldoc.findtext('/%s' % key).strip()

    def getAuthors(self, cat=None):
        al = [ Author(e) for e in self.xmldoc.findall("authors/author")]
        if cat:
            al = [ a for a in al if a['cat'] == cat ]
        return al

    def getDeps(self, relation, part, arch, dist):
        return self.depsFactory.getDeps(relation, part, arch, dist)

    def getChangelog(self):
        return [ ChangelogVEntry(e) for e in self.xmldoc.findall('/changelog/versionEntry') ]

    def getGlobalDistFilters(self):
        (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters'))
        return dists

    def getNbArchFilters(self):
        (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters'))
        l = self.xmldoc.findall('serverDeps/requires/filters/arch')
        return len(l)

    def getGlobalArchFilters(self):
        (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters'))
        for a in arch:
            Logger().debug ("-> Arch " + a)
        for d in dists:
            Logger().debug ("-> Dist " + d['name'])
        l = self.xmldoc.findall('serverDeps/requires/filters/arch')
        Logger().info("Number of arch filters: %d" % len(l))
        return arch
 def __init__(self, *params):
    """
    __init__(xmlasstring|node, [doc])
    Creates a new DataObject.
    @param xmlasstring: the xml to be parsed as DataObject as string
    @type xmlasstring: string
    @param node: node as xml.dom.Element to be taken as base element
    @type node: xml.dom.Element
    @param doc: the document to be taken as basedocument for the given element
    @type doc: xml.dom.DocuementElement 
    """
    element=None
    doc=None
    if len(params) >= 1:
       if isinstance(params[0], basestring):
          element=XmlTools.parseXMLFile(params[0])
          element=element.documentElement
       else:
          element=params[0]
    if len(params) == 2:
       doc=params[1]
    if element and element.hasAttribute("refid"):
       __newelement=self.searchReference(element, doc)
       element.parentNode.replaceChild(__newelement, element)
       self.element=__newelement
    else:
       self.element=element
    self.document=doc
    self.properties=None
    if element:
       from comoonics.ComProperties import Properties as Props
       properties=element.getElementsByTagName(Props.TAGNAME)
       if len(properties) > 0:
          self.properties=Props(properties[0], self.document)
Exemplo n.º 8
0
class ConfigSchema(object):

    schemaTree = None

    def __init__(self):
        self.schemaTree = XmlTools().getXsdDoc()        
    
    def getArchs(self):
        """ Return list of authorized arch filters
        """
        complexType = filter(lambda x: x.get("name") == "archType",
                             self.schemaTree.findall("{%s}simpleType" % XmlTools.xsd_uri))[0]
        archs = [e.get("value")
                 for e in complexType.find("{%s}restriction" % XmlTools.xsd_uri).findall("{%s}enumeration" % XmlTools.xsd_uri)]

        return archs
Exemplo n.º 9
0
class ConfigXml(UserDict):

    xmldoc = None
    depsFactory = None
    dist = None

    nameRe = re.compile(r'^[a-z0-9][a-z0-9+-\.]+$')

    def __init__(self, configfile):
        UserDict.__init__(self)
        XmlTools().init(configfile)
        self.xmldoc = XmlTools().getXmlDoc()
        self.depsFactory = DependsFactory(self.xmldoc)

        self.__validate__()

    def __validate__(self):
        XmlTools().validate()
        if not self.nameRe.match(self['name']):
            raise OpkgSyntaxException(
                'Incorrect package name syntax (pattern: [a-z0-9][a-z0-9+-\.]+)'
            )

    def __getitem__(self, key):
        if key == 'version':
            return self.xmldoc.find('changelog/versionEntry').get(
                'version').strip()
        else:
            return self.xmldoc.findtext('/%s' % key).strip()

    def getAuthors(self, cat=None):
        al = [Author(e) for e in self.xmldoc.findall("authors/author")]
        if cat:
            al = [a for a in al if a['cat'] == cat]
        return al

    def getDeps(self, relation, part, arch, dist):
        return self.depsFactory.getDeps(relation, part, arch, dist)

    def getChangelog(self):
        return [
            ChangelogVEntry(e)
            for e in self.xmldoc.findall('/changelog/versionEntry')
        ]

    def getGlobalDistFilters(self):
        (dists,
         arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters'))
        return dists

    def getGlobalArchFilters(self):
        (dists,
         arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters'))
        return arch
Exemplo n.º 10
0
 def __init__(self):
     self.schemaTree = XmlTools().getXsdDoc()
Exemplo n.º 11
0
 def __validate__(self):
     XmlTools().validate()
     if not self.nameRe.match(self['name']):
         raise OpkgSyntaxException(
             'Incorrect package name syntax (pattern: [a-z0-9][a-z0-9+-\.]+)'
         )