From 4abdf82598cfc32b0f22baa23fb2838caaaf707b Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 1 Jun 2014 20:45:41 +0100 Subject: [PATCH] Closer to working catalog creation. --- create_catalog.py | 32 +++++++++++++++++++++++++------- sgprops.py | 29 +++++++++++++++++++---------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/create_catalog.py b/create_catalog.py index e572746..06ffd5f 100755 --- a/create_catalog.py +++ b/create_catalog.py @@ -21,12 +21,12 @@ de = catalogProps.addChild('de') fr = catalogProps.addChild('fr') urls = [ - "http://flightgear.wo0t.de/Aircraft-3.0/{acft}_20140116.zip", - "http://ftp.icm.edu.pl/packages/flightgear/Aircraft-3.0/{acft}_20140216.zip", - "http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Aircraft-3.0/{acft}_20140216.zip", - "http://ftp.igh.cnrs.fr/pub/flightgear/ftp/Aircraft-3.0/{acft}_20140116.zip", - "http://ftp.linux.kiev.ua/pub/fgfs/Aircraft-3.0/{acft}_20140116.zip", - "http://fgfs.physra.net/ftp/Aircraft-3.0/{acft}_20130225.zip" + "http://flightgear.wo0t.de/", + "http://ftp.icm.edu.pl/packages/flightgear/", + "http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/", + "http://ftp.igh.cnrs.fr/pub/flightgear/ftp/", + "http://ftp.linux.kiev.ua/pub/fgfs/", + "http://fgfs.physra.net/ftp/" ] thumbs = [ @@ -56,6 +56,8 @@ for d in os.listdir(aircraftDir): sim = props.getNode("sim") pkgNode = catalogProps.addChild('package') + + # basic / mandatory values pkgNode.addChild('id').value = d pkgNode.addChild('name').value = sim.getValue('description') @@ -63,14 +65,30 @@ for d in os.listdir(aircraftDir): if longDesc is not None: pkgNode.addChild('description').value = longDesc + # copy all the standard values + for p in ['status', 'author', 'license']: + v = sim.getValue(p) + if v is not None: + pkgNode.addChild(p).value = v + + # ratings + if sim.hasChild('rating'): + pkgRatings = pkgNode.addChild('rating') + for r in ['FDM', 'systems', 'cockpit', 'model']: + pkgRatings.addChild(r).value = sim.getValue('rating/' + r, 0) + # copy tags if sim.hasChild('tags'): for c in sim.getChild('tags').getChildren('tag'): pkgNode.addChild('tag').value = c.value + pkgNode.addChild("md5").value = 'ffffffffff' + # create download and thumbnail URLs + date = '0000000' + s = "{url}Aircraft-3.0/{acft}_{date}.zip" for u in urls: - pkgNode.addChild("url").value = u.format(acft=d) + pkgNode.addChild("url").value = s.format(url=u,acft=d, date=date) for t in thumbs: pkgNode.addChild("thumbnail").value = t.format(acft=d) diff --git a/sgprops.py b/sgprops.py index 1b4a210..29a131d 100644 --- a/sgprops.py +++ b/sgprops.py @@ -100,7 +100,7 @@ class Node(object): root = self._createXMLElement('PropertyList') t = ET.ElementTree(root) - t.write(path, 'UTF-8') + t.write(path, 'utf-8') def _createXMLElement(self, nm = None): if nm is None: @@ -109,15 +109,24 @@ class Node(object): n = ET.Element(nm) # value and type specification - if self._value is not None: - n.text = str(self._value) - if isinstance(self._value, int): - n.set('type', 'int') - elif isinstance(self._value, float): - n.set('type', 'double') - elif isinstance(self._value, bool): - n.set('type', "bool") - + try: + if self._value is not None: + if isinstance(self._value, basestring): + # don't call str() on strings, breaks the + # encoding + n.text = self._value + else: + # use str() to turn non-string types into text + n.text = str(self._value) + if isinstance(self._value, int): + n.set('type', 'int') + elif isinstance(self._value, float): + n.set('type', 'double') + elif isinstance(self._value, bool): + n.set('type', "bool") + except UnicodeEncodeError: + print "Encoding error with", self._value, type(self._value) + # index in parent if (self.index != 0): n.set('n', self.index)