Kaydet (Commit) 900b48a2 authored tarafından Faik Uygur's avatar Faik Uygur

* get metadata and files info from pisi package without extracting somewhere.

üst 578135a7
......@@ -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()
......
......@@ -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):
......
......@@ -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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment