From e54bec19b0a5e29df79b35d0f90574e22db538da Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 4 Jan 2010 05:47:18 +0100 Subject: Add reading of format/subpath/category from repositories.xml format --- layman/overlays/cvs.py | 9 ++++++--- layman/overlays/tar.py | 40 +++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py index d2bf5d3..5c8d376 100644 --- a/layman/overlays/cvs.py +++ b/layman/overlays/cvs.py @@ -26,7 +26,7 @@ __version__ = "$Id$" import xml.etree.ElementTree as ET # Python 2.5 -from layman.utils import path +from layman.utils import path, ensure_unicode from layman.overlays.overlay import Overlay #=============================================================================== @@ -45,8 +45,11 @@ class CvsOverlay(Overlay): Overlay.__init__(self, xml, config, ignore, quiet) - if 'subpath' in xml.attrib: - self.subpath = xml.attrib['subpath'] + _subpath = xml.find('subpath') + if _subpath != None: + self.subpath = ensure_unicode(_subpath.text.strip()) + elif 'subpath' in xml.attrib: + self.subpath = ensure_unicode(xml.attrib['subpath']) else: self.subpath = '' diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py index 05b8581..2f9f862 100644 --- a/layman/overlays/tar.py +++ b/layman/overlays/tar.py @@ -27,7 +27,7 @@ __version__ = "$Id: tar.py 310 2007-04-09 16:30:40Z wrobel $" import os, os.path, sys, urllib2, shutil import xml.etree.ElementTree as ET # Python 2.5 -from layman.utils import path +from layman.utils import path, ensure_unicode from layman.overlays.overlay import Overlay #=============================================================================== @@ -70,25 +70,30 @@ class TarOverlay(Overlay): Overlay.__init__(self, xml, config, ignore) - if 'format' in xml.attrib: - self.format = xml.attrib['format'] - else: - self.format = '' + # Handle attribute format of old layman-global.txt format + # See _set_source() for repositories.xml variant + if not self.format and 'format' in xml.attrib: + self.format = ensure_unicode(xml.attrib['format']) - if 'subpath' in xml.attrib: - self.subpath = xml.attrib['subpath'] + _subpath = xml.find('subpath') + if _subpath != None: + self.subpath = ensure_unicode(_subpath.text.strip()) + elif 'subpath' in xml.attrib: + self.subpath = ensure_unicode(xml.attrib['subpath']) else: self.subpath = '' - if 'category' in xml.attrib: - if self.subpath: - raise Exception('Cannot use "category" and "subpath" at the same' - ' time!') - - self.category = xml.attrib['category'] + _category = xml.find('category') + if _category != None: + self.category = ensure_unicode(_category.text.strip()) + elif 'category' in xml.attrib: + self.category = ensure_unicode(xml.attrib['category']) else: self.category = '' + if self.subpath and self.category: + raise Exception('Cannot use "category" and "subpath" at the same time!') + def __eq__(self, other): res = super(TarOverlay, self).__eq__(other) \ and self.format == other.format \ @@ -99,6 +104,15 @@ class TarOverlay(Overlay): def __ne__(self, other): return not self.__eq__(other) + # overrider + def _set_source(self, source_elem): + # Handle attribute format of new repositories.xml format + if 'format' in source_elem.attrib: + self.format = ensure_unicode(source_elem.attrib['format']) + else: + self.format = '' + super(TarOverlay, self)._set_source(source_elem) + # overrider def to_xml(self): repo = super(TarOverlay, self).to_xml() -- cgit v1.2.3-1-g7c22