From 186bfada9f1d21c0f6f3cce9cebfc4bc80819f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Tue, 19 Jan 2010 12:08:10 +0000 Subject: [PATCH] Pisi error message sanitization * pisi/specfile.py (_set_i18n): Handle parsing errors during translations.xml reading. * pisi/specfile.py (read_translations): Ignore source package translations if is empty in translations.xml. --- ChangeLog | 6 ++++++ pisi/specfile.py | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4249465..431a3e92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-19 Ozan Çağlayan + * pisi/specfile.py (_set_i18n): Handle parsing errors during + translations.xml reading. + * pisi/specfile.py (read_translations): Ignore source package + translations if is empty in translations.xml. + 2010-01-12 Ozan Çağlayan * pisi/actionsapi/get.py: Add ARCH() for getting host architecture. Thanks to 64-bit team for pointing out this requirement. diff --git a/pisi/specfile.py b/pisi/specfile.py index edad05b9..d9bdf3ff 100644 --- a/pisi/specfile.py +++ b/pisi/specfile.py @@ -310,10 +310,14 @@ class SpecFile(xmlfile.XmlFile): self.source.description["en"] = self.source.summary["en"] def _set_i18n(self, tag, inst): - for summary in tag.tags("Summary"): - inst.summary[summary.getAttribute("xml:lang")] = summary.firstChild().data() - for desc in tag.tags("Description"): - inst.description[desc.getAttribute("xml:lang")] = desc.firstChild().data() + try: + for summary in tag.tags("Summary"): + inst.summary[summary.getAttribute("xml:lang")] = summary.firstChild().data() + for desc in tag.tags("Description"): + inst.description[desc.getAttribute("xml:lang")] = desc.firstChild().data() + except AttributeError: + raise Error(_("translations.xml file is badly formed.")) + def read_translations(self, path): if not os.path.exists(path): @@ -323,7 +327,10 @@ class SpecFile(xmlfile.XmlFile): except Exception, e: raise Error(_("File '%s' has invalid XML") % (path) ) - self._set_i18n(doc.getTag("Source"), self.source) + if doc.getTag("Source").getTagData("Name") == self.source.name: + # Set source package translations + self._set_i18n(doc.getTag("Source"), self.source) + for pak in doc.tags("Package"): for inst in self.packages: if inst.name == pak.getTagData("Name"):