diff --git a/pisi/package.py b/pisi/package.py index 34f9bae6..689a6d75 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -105,6 +105,18 @@ class Package: self.extract_files([ctx.const.metadata_xml, ctx.const.files_xml], outdir) self.extract_dir('config', outdir) + def get_metadata(self): + """reads metadata.xml from the PiSi package and returns MetaData object""" + md = MetaData() + md.parse(self.impl.read_file(ctx.const.metadata_xml)) + return md + + def get_files(self): + """reads files.xml from the PiSi package and returns Files object""" + files = Files() + files.parse(self.impl.read_file(ctx.const.files_xml)) + return files + def read(self, outdir = None): if not outdir: outdir = ctx.config.tmp_dir() diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index f02e0305..96fe6fd4 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -412,6 +412,24 @@ class autoxml(oo.autosuper, oo.autoprop): cls.__ne__ = notequal if xmlfile_support: + def parse(self, xml, keepDoc = False): + "parse XML string and decode it into a python object" + self.parsexml(xml) + errs = [] + self.decode(self.rootNode(), errs) + if errs: + errs.append(_("autoxml.parse: String '%s' has errors") % xml) + raise Error(*errs) + if hasattr(self, 'read_hook'): + self.read_hook(errs) + + if not keepDoc: + self.unlink() # get rid of the tree + + errs = self.errors() + if errs: + errs.append(_("autoxml.parse: String '%s' has errors") % xml) + def read(self, uri, keepDoc = False, tmpDir = '/tmp', sha1sum = False, compress = None, sign = None, copylocal = False): "read XML file and decode it into a python object" @@ -454,6 +472,7 @@ class autoxml(oo.autosuper, oo.autoprop): cls.read = read cls.write = write + cls.parse = parse def gen_attr_member(cls, attr): diff --git a/pisi/pxml/xmlfile.py b/pisi/pxml/xmlfile.py index 15355940..58e9883e 100644 --- a/pisi/pxml/xmlfile.py +++ b/pisi/pxml/xmlfile.py @@ -54,6 +54,14 @@ class XmlFile(object): def rootNode(self): """returns root document element""" return self.doc + + def parsexml(self, xml): + """parses xml string and returns DOM""" + try: + self.doc = iks.parseString(xml) + return self.doc + except Exception, e: + raise Error(_("String '%s' has invalid XML") % (xml)) def readxmlfile(self, file): raise Exception("not implemented")