From a46fbcd563f6b4f43cf9071abbd5fcc24e2cf3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Thu, 3 Nov 2005 15:19:43 +0000 Subject: [PATCH] * automxl: inheritance support * make metadata use inheritance --- TODO | 6 ++++-- pisi/metadata.py | 25 ++++--------------------- pisi/xmlfile.py | 27 ++++++++++++++++++++------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/TODO b/TODO index f142dc54..c0c52afa 100644 --- a/TODO +++ b/TODO @@ -85,8 +85,10 @@ Legend: + improved error handling, check routines, hooks, format/print routines + xmlfile support (read/write) + string member, in addition to tag/attribute members - / replace specfile with new specfile using autoxml - - revise writing, error checking, printing and tests + + replace specfile with new specfile using autoxml + + autoxmlize: metadata, index, dependency and related code paths + + inheritance support + / revise writing, error checking, printing and tests / components and distribution (eray) + requirements / xml format diff --git a/pisi/metadata.py b/pisi/metadata.py index 3c9d2a71..c2f15037 100644 --- a/pisi/metadata.py +++ b/pisi/metadata.py @@ -35,26 +35,9 @@ class Source: t_Homepage = [xmlfile.String, xmlfile.optional] t_Packager = [specfile.Packager, xmlfile.mandatory] -# FIXME: make inheritance work with autoxml (specfile.Package) -class Package: +class Package(specfile.Package): __metaclass__ = xmlfile.autoxml - # FIXME: copied attributes - t_Name = [ xmlfile.String, xmlfile.mandatory ] - t_Summary = [ xmlfile.LocalText, xmlfile.optional ] - t_Description = [ xmlfile.LocalText, xmlfile.optional ] - t_IsA = [ [xmlfile.String], xmlfile.optional] - t_PartOf = [xmlfile.String, xmlfile.optional] - t_License = [ [xmlfile.String], xmlfile.optional] - t_Icon = [ xmlfile.String, xmlfile.optional] - t_RuntimeDependencies = [ [specfile.Dependency], xmlfile.optional] - t_Files = [ [specfile.Path], xmlfile.optional] - t_Conflicts = [ [xmlfile.String], xmlfile.optional, "Conflicts/Package"] - t_ProvidesComar = [ [specfile.ComarProvide], xmlfile.optional, "Provides/COMAR"] - #t_RequiresComar = [ [xmlfile.String], xmlfile.mandatory, "Requires/COMAR"] - t_AdditionalFiles = [ [specfile.AdditionalFile], xmlfile.optional] - t_History = [ [specfile.Update], xmlfile.optional] - t_Build = [ xmlfile.Integer, xmlfile.optional] t_Distribution = [ xmlfile.String, xmlfile.mandatory] t_DistributionRelease = [ xmlfile.String, xmlfile.mandatory] @@ -66,9 +49,9 @@ class Package: self.version = self.history[0].version self.release = self.history[0].release - def __str__(self): - s = specfile.Package.__str__(self) - return s + #def __str__(self): + #s = specfile.Package.__str__(self) + #return s def pkg_dir(self): packageDir = self.name + '-' \ diff --git a/pisi/xmlfile.py b/pisi/xmlfile.py index 60bce4d0..f58d0b38 100644 --- a/pisi/xmlfile.py +++ b/pisi/xmlfile.py @@ -226,6 +226,8 @@ class autoxml(oo.autosuper, oo.autoprop): xmlfile_support = XmlFile in bases + cls.autoxml_bases = filter(lambda base: isinstance(base, autoxml), bases) + #TODO: initialize class attribute __xml_tags #setattr(cls, 'xml_variables', []) @@ -266,9 +268,12 @@ class autoxml(oo.autosuper, oo.autoprop): #FIXME: what the hell is spec? :( if not tag: tag = cls.tag - #self.__super.__init__(tag = tag) #FIXME: doesn't work, why? :( - super(cls, self).__init__(tag = tag) # tag for XmlFile support - for init in self.__class__.initializers: + if xmlfile_support: + XmlFile.__init__(self, tag = tag) + for base in cls.autoxml_bases: + base.__init__(self) + #super(cls, self).__init__(tag = tag) cooperative shit disabled for now + for init in inits:#self.__class__.initializers: init(self) # init hook if hasattr(self, 'init'): @@ -278,7 +283,9 @@ class autoxml(oo.autosuper, oo.autoprop): cls.decoders = decoders def decode(self, node, errs, where = unicode()): - for decode_member in self.__class__.decoders: + for base in cls.autoxml_bases: + base.decode(self, node, errs, where) + for decode_member in decoders:#self.__class__.decoders: decode_member(self, node, errs, where) if hasattr(self, 'decode_hook'): self.decode_hook(node, errs, where) @@ -286,7 +293,9 @@ class autoxml(oo.autosuper, oo.autoprop): cls.encoders = encoders def encode(self, xml, node, errs): - for encode_member in self.__class__.encoders: + for base in cls.autoxml_bases: + base.encode(self, xml, node, errs) + for encode_member in encoders:#self.__class__.encoders: encode_member(self, xml, node, errs) if hasattr(self, 'encode_hook'): self.encode_hook(xml, node, errs) @@ -295,7 +304,9 @@ class autoxml(oo.autosuper, oo.autoprop): cls.errorss = errorss def errors(self, where = unicode()): errs = [] - for errors in self.__class__.errorss: + for base in cls.autoxml_bases: + errs.extend(base.errors(self, where)) + for errors in errorss:#self.__class__.errorss: errs.extend(errors(self, where)) if hasattr(self, 'errors_hook'): errs.extend(self.errors_hook(where)) @@ -304,7 +315,9 @@ class autoxml(oo.autosuper, oo.autoprop): cls.formatters = formatters def format(self, f, errs): - for formatter in self.__class__.formatters: + for base in cls.autoxml_bases: + base.format(self, f, errs) + for formatter in formatters:#self.__class__.formatters: formatter(self, f, errs) cls.format = format def print_text(self, file = sys.stdout):