2013-02-17 12:03:46 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
import os, sys, re
|
2014-06-12 09:34:31 +00:00
|
|
|
import urllib
|
2014-06-01 21:44:35 +00:00
|
|
|
import hashlib # for MD5
|
2013-02-17 12:03:46 +00:00
|
|
|
|
2014-06-01 21:44:35 +00:00
|
|
|
import catalogFilenames
|
2014-06-12 09:34:31 +00:00
|
|
|
import catalogTags
|
2014-06-01 14:44:52 +00:00
|
|
|
import sgprops
|
2013-02-17 12:03:46 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
fgRoot = sys.argv[1]
|
|
|
|
aircraftDir = os.path.join(fgRoot, 'Aircraft')
|
2013-02-17 12:03:46 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
catalogProps = sgprops.Node()
|
|
|
|
catalogProps.addChild('version').value = '3.1.0'
|
|
|
|
catalogProps.addChild('id').value = 'org.flightgear.default'
|
|
|
|
catalogProps.addChild('license').value = 'GPL'
|
|
|
|
catalogProps.addChild('url').value = "http://fgfs.goneabitbursar.com/pkg/3.1.0/default-catalog.xml"
|
2013-02-19 09:40:08 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
catalogProps.addChild('description').value = "Aircraft developed and maintained by the FlightGear project"
|
2013-02-19 09:40:08 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
de = catalogProps.addChild('de')
|
|
|
|
# de.addChild('description').value = "<German translation of catalog description>"
|
2013-02-19 09:40:08 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
fr = catalogProps.addChild('fr')
|
2013-02-17 12:03:46 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
urls = [
|
2014-06-01 19:45:41 +00:00
|
|
|
"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/"
|
2014-06-01 14:44:52 +00:00
|
|
|
]
|
2013-02-19 09:40:08 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
thumbs = [
|
|
|
|
"http://www.flightgear.org/thumbs/v3.0/{acft}.jpg"
|
|
|
|
]
|
2014-06-01 21:44:35 +00:00
|
|
|
|
2014-06-12 09:34:31 +00:00
|
|
|
standardTagSet = frozenset(catalogTags.tags)
|
|
|
|
def isNonstandardTag(t):
|
|
|
|
return t not in standardTagSet
|
|
|
|
|
|
|
|
# create the download cache dir if require
|
|
|
|
|
|
|
|
cacheDir = '.catalog_cache'
|
|
|
|
if not os.path.isdir(cacheDir):
|
|
|
|
print "Creating catalog cache dir"
|
|
|
|
os.mkdir(cacheDir)
|
|
|
|
|
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
for d in os.listdir(aircraftDir):
|
|
|
|
acftDirPath = os.path.join(aircraftDir, d)
|
|
|
|
if not os.path.isdir(acftDirPath):
|
|
|
|
continue
|
2013-02-17 12:03:46 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
setFilePath = None
|
|
|
|
|
|
|
|
# find the first set file
|
|
|
|
# FIXME - way to designate the primary file
|
|
|
|
for f in os.listdir(acftDirPath):
|
|
|
|
if f.endswith("-set.xml"):
|
|
|
|
setFilePath = os.path.join(acftDirPath, f)
|
|
|
|
break
|
2013-02-17 12:03:46 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
if setFilePath is None:
|
|
|
|
print "No -set.xml file found in",acftDirPath,"will be skipped"
|
|
|
|
continue
|
2013-02-19 09:40:08 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
try:
|
|
|
|
props = sgprops.readProps(setFilePath, dataDirPath = fgRoot)
|
|
|
|
sim = props.getNode("sim")
|
|
|
|
|
|
|
|
pkgNode = catalogProps.addChild('package')
|
2014-06-01 19:45:41 +00:00
|
|
|
|
|
|
|
# basic / mandatory values
|
2014-06-01 14:44:52 +00:00
|
|
|
pkgNode.addChild('id').value = d
|
|
|
|
pkgNode.addChild('name').value = sim.getValue('description')
|
2013-02-20 15:29:02 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
longDesc = sim.getValue('long-description')
|
|
|
|
if longDesc is not None:
|
|
|
|
pkgNode.addChild('description').value = longDesc
|
2013-02-20 15:29:02 +00:00
|
|
|
|
2014-06-01 19:45:41 +00:00
|
|
|
# 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)
|
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
# copy tags
|
|
|
|
if sim.hasChild('tags'):
|
|
|
|
for c in sim.getChild('tags').getChildren('tag'):
|
2014-06-12 09:34:31 +00:00
|
|
|
if isNonstandardTag(c.value):
|
|
|
|
print "Skipping non-standard tag:", c.value
|
|
|
|
else:
|
|
|
|
pkgNode.addChild('tag').value = c.value
|
2014-06-01 21:44:35 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
# create download and thumbnail URLs
|
2014-06-01 21:44:35 +00:00
|
|
|
s = "{url}Aircraft-3.0/"
|
|
|
|
if d not in catalogFilenames.aircraft:
|
|
|
|
print "filename not found for:",d
|
|
|
|
raise RuntimeError("filename not found for:" + d)
|
|
|
|
s += catalogFilenames.aircraft[d]
|
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
for u in urls:
|
2014-06-12 09:34:31 +00:00
|
|
|
pkgNode.addChild("url").value = s.format(url=u)
|
2014-06-01 14:44:52 +00:00
|
|
|
|
|
|
|
for t in thumbs:
|
|
|
|
pkgNode.addChild("thumbnail").value = t.format(acft=d)
|
|
|
|
|
2014-06-12 09:34:31 +00:00
|
|
|
cachedZip = os.path.join(cacheDir, catalogFilenames.aircraft[d])
|
|
|
|
if not os.path.exists(cachedZip):
|
|
|
|
# download the zip
|
|
|
|
url = s.format(url=urls[0])
|
|
|
|
print "Downloading ", url
|
|
|
|
urllib.urlretrieve(url, cachedZip)
|
|
|
|
#else:
|
|
|
|
# print "Using cached zip for", d
|
|
|
|
|
|
|
|
zipFile = open(cachedZip, 'r')
|
2014-06-01 21:44:35 +00:00
|
|
|
|
2014-06-12 09:34:31 +00:00
|
|
|
digest = hashlib.md5(zipFile.read()).hexdigest()
|
|
|
|
pkgNode.addChild("md5").value = digest
|
|
|
|
pkgNode.addChild("file-size-bytes").value = os.path.getsize(cachedZip)
|
2014-06-01 14:44:52 +00:00
|
|
|
except:
|
|
|
|
print "Failure processing:", setFilePath
|
2014-06-12 09:34:31 +00:00
|
|
|
|
2014-06-01 14:44:52 +00:00
|
|
|
catalogProps.write("catalog.xml")
|