* 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
|
#ignore tag
|
||||||
#XmlFile.__init__(self, tag)
|
#XmlFile.__init__(self, tag)
|
||||||
|
|
||||||
def read(self, filename):
|
def read_hook(self, errs):
|
||||||
"""Read PSPEC file"""
|
"""Read PSPEC file"""
|
||||||
|
|
||||||
self.readxml(filename)
|
|
||||||
|
|
||||||
errs = []
|
|
||||||
self.decode(self.rootNode(), errs)
|
|
||||||
if errs:
|
|
||||||
raise Error(*errs)
|
|
||||||
|
|
||||||
self.merge_tags()
|
self.merge_tags()
|
||||||
self.override_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):
|
def merge_tags(self):
|
||||||
"""Merge tags from Source in Packages. Some tags in Packages merged
|
"""Merge tags from Source in Packages. Some tags in Packages merged
|
||||||
with the tags from Source. There is a more detailed
|
with the tags from Source. There is a more detailed
|
||||||
@@ -260,11 +225,22 @@ class SpecFile(XmlFile):
|
|||||||
tmp.append(pkg)
|
tmp.append(pkg)
|
||||||
self.packages = tmp
|
self.packages = tmp
|
||||||
|
|
||||||
def write(self, filename):
|
def override_tags(self):
|
||||||
"""Write PSPEC file"""
|
"""Override tags from Source in Packages. Some tags in Packages
|
||||||
errs = []
|
overrides the tags from Source. There is a more detailed
|
||||||
self.newDOM()
|
description in documents."""
|
||||||
self.encode(self, self.rootNode(), errs)
|
|
||||||
if errs:
|
tmp = []
|
||||||
raise Error(*errs)
|
for pkg in self.packages:
|
||||||
self.writexml(filename)
|
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
|
# standard initialization
|
||||||
super(autoxml, cls).__init__(name, bases, dict)
|
super(autoxml, cls).__init__(name, bases, dict)
|
||||||
|
|
||||||
|
xmlfile_support = XmlFile in bases
|
||||||
|
|
||||||
#TODO: initialize class attribute __xml_tags
|
#TODO: initialize class attribute __xml_tags
|
||||||
#setattr(cls, 'xml_variables', [])
|
#setattr(cls, 'xml_variables', [])
|
||||||
|
|
||||||
@@ -306,6 +308,38 @@ class autoxml(oo.autosuper):
|
|||||||
cls.print_text = print_text
|
cls.print_text = print_text
|
||||||
if not dict.has_key('__str__'):
|
if not dict.has_key('__str__'):
|
||||||
cls.__str__ = print_text
|
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):
|
def gen_attr_member(cls, attr):
|
||||||
"""generate readers and writers for an attribute member"""
|
"""generate readers and writers for an attribute member"""
|
||||||
|
|||||||
Reference in New Issue
Block a user