* more magic: automatic read and write methods when XmlFile is a base
class :)
This commit is contained in:
+20
-44
@@ -196,46 +196,11 @@ class SpecFile(XmlFile):
|
||||
#ignore tag
|
||||
#XmlFile.__init__(self, tag)
|
||||
|
||||
def read(self, filename):
|
||||
def read_hook(self, errs):
|
||||
"""Read PSPEC file"""
|
||||
|
||||
self.readxml(filename)
|
||||
|
||||
errs = []
|
||||
self.decode(self.rootNode(), errs)
|
||||
if errs:
|
||||
raise Error(*errs)
|
||||
|
||||
self.merge_tags()
|
||||
self.override_tags()
|
||||
|
||||
self.unlink()
|
||||
|
||||
errs = self.check()
|
||||
if errs:
|
||||
errs.append(_("File '%s' has errors") % filename)
|
||||
raise Error(*errs)
|
||||
|
||||
def override_tags(self):
|
||||
"""Override tags from Source in Packages. Some tags in Packages
|
||||
overrides the tags from Source. There is a more detailed
|
||||
description in documents."""
|
||||
|
||||
tmp = []
|
||||
for pkg in self.packages:
|
||||
if not pkg.summary:
|
||||
pkg.summary = self.source.summary
|
||||
if not pkg.description:
|
||||
pkg.description = self.source.description
|
||||
if not pkg.partOf:
|
||||
pkg.partOf = self.source.partOf
|
||||
if not pkg.license:
|
||||
pkg.license = self.source.license
|
||||
if not pkg.icon:
|
||||
pkg.icon = self.source.icon
|
||||
tmp.append(pkg)
|
||||
self.packages = tmp
|
||||
|
||||
def merge_tags(self):
|
||||
"""Merge tags from Source in Packages. Some tags in Packages merged
|
||||
with the tags from Source. There is a more detailed
|
||||
@@ -260,11 +225,22 @@ class SpecFile(XmlFile):
|
||||
tmp.append(pkg)
|
||||
self.packages = tmp
|
||||
|
||||
def write(self, filename):
|
||||
"""Write PSPEC file"""
|
||||
errs = []
|
||||
self.newDOM()
|
||||
self.encode(self, self.rootNode(), errs)
|
||||
if errs:
|
||||
raise Error(*errs)
|
||||
self.writexml(filename)
|
||||
def override_tags(self):
|
||||
"""Override tags from Source in Packages. Some tags in Packages
|
||||
overrides the tags from Source. There is a more detailed
|
||||
description in documents."""
|
||||
|
||||
tmp = []
|
||||
for pkg in self.packages:
|
||||
if not pkg.summary:
|
||||
pkg.summary = self.source.summary
|
||||
if not pkg.description:
|
||||
pkg.description = self.source.description
|
||||
if not pkg.partOf:
|
||||
pkg.partOf = self.source.partOf
|
||||
if not pkg.license:
|
||||
pkg.license = self.source.license
|
||||
if not pkg.icon:
|
||||
pkg.icon = self.source.icon
|
||||
tmp.append(pkg)
|
||||
self.packages = tmp
|
||||
|
||||
@@ -221,6 +221,8 @@ class autoxml(oo.autosuper):
|
||||
# standard initialization
|
||||
super(autoxml, cls).__init__(name, bases, dict)
|
||||
|
||||
xmlfile_support = XmlFile in bases
|
||||
|
||||
#TODO: initialize class attribute __xml_tags
|
||||
#setattr(cls, 'xml_variables', [])
|
||||
|
||||
@@ -306,6 +308,38 @@ class autoxml(oo.autosuper):
|
||||
cls.print_text = print_text
|
||||
if not dict.has_key('__str__'):
|
||||
cls.__str__ = print_text
|
||||
|
||||
if xmlfile_support:
|
||||
def read(self, filename):
|
||||
self.readxml(filename)
|
||||
errs = []
|
||||
self.decode(self.rootNode(), errs)
|
||||
if hasattr(self, 'read_hook'):
|
||||
self.read_hook(errs)
|
||||
if errs:
|
||||
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
||||
raise Error(*errs)
|
||||
|
||||
self.unlink()
|
||||
|
||||
errs = self.check()
|
||||
if errs:
|
||||
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
||||
raise Error(*errs)
|
||||
|
||||
def write(self, filename):
|
||||
errs = []
|
||||
self.newDOM()
|
||||
self.encode(self, self.rootNode(), errs)
|
||||
if hasattr(self, 'write_hook'):
|
||||
self.write_hook(errs)
|
||||
if errs:
|
||||
errs.append(_("autoxml.write: File '%s' has errors") % filename)
|
||||
raise Error(*errs)
|
||||
self.writexml(filename)
|
||||
|
||||
cls.read = read
|
||||
cls.write = write
|
||||
|
||||
def gen_attr_member(cls, attr):
|
||||
"""generate readers and writers for an attribute member"""
|
||||
|
||||
Reference in New Issue
Block a user