XML write-out improving.
Use existing catalog for static data, revision counting.
This commit is contained in:
parent
b4b5f665c1
commit
c20802b84f
1 changed files with 66 additions and 6 deletions
|
@ -12,10 +12,24 @@ import xml.etree.cElementTree as ET
|
||||||
rootPath = sys.argv[1]
|
rootPath = sys.argv[1]
|
||||||
outputDir = sys.argv[2]
|
outputDir = sys.argv[2]
|
||||||
|
|
||||||
shutil.rmtree(outputDir)
|
existingCatalogPath = os.path.join(outputDir, 'catalog.xml')
|
||||||
|
existingCatalog = None
|
||||||
|
if os.path.exists(existingCatalogPath):
|
||||||
|
existingCatalogPath = ET.parse(existingCatalogPath)
|
||||||
|
|
||||||
|
for file in os.listdir(outputDir):
|
||||||
|
if fnmatch.fnmatch(file, '*.tar.gz'):
|
||||||
|
os.remove(os.path.join(outputDir, file));
|
||||||
|
|
||||||
|
|
||||||
thumbsDir = os.path.join(outputDir, 'thumbs')
|
thumbsDir = os.path.join(outputDir, 'thumbs')
|
||||||
|
shutil.rmtree(thumbsDir)
|
||||||
os.makedirs(thumbsDir)
|
os.makedirs(thumbsDir)
|
||||||
|
|
||||||
|
def setProperty(node, id, value):
|
||||||
|
s = ET.SubElement(node, id)
|
||||||
|
s.text = value
|
||||||
|
|
||||||
def parse_setXml(path):
|
def parse_setXml(path):
|
||||||
tree = ET.parse(path)
|
tree = ET.parse(path)
|
||||||
|
|
||||||
|
@ -34,6 +48,7 @@ def parse_setXml(path):
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
|
|
||||||
|
d['desc'] = desc
|
||||||
d['ratings'] = ratings;
|
d['ratings'] = ratings;
|
||||||
d['status'] = tree.find('sim/status')
|
d['status'] = tree.find('sim/status')
|
||||||
d['authors'] = tree.findall('sim/author')
|
d['authors'] = tree.findall('sim/author')
|
||||||
|
@ -61,9 +76,11 @@ def process_aircraft(acft, path):
|
||||||
d['set'] = s[0:-8]
|
d['set'] = s[0:-8]
|
||||||
aircraft.append(d)
|
aircraft.append(d)
|
||||||
|
|
||||||
|
thumbnailNames = []
|
||||||
# copy thumbnails
|
# copy thumbnails
|
||||||
for t in thumbs:
|
for t in thumbs:
|
||||||
outThumb = os.path.join(thumbsDir, acft + "-" + t)
|
outThumb = os.path.join(thumbsDir, acft + "-" + t)
|
||||||
|
thumbnailNames.append(acft + "-" + t)
|
||||||
shutil.copyfile(os.path.join(path, t), outThumb)
|
shutil.copyfile(os.path.join(path, t), outThumb)
|
||||||
|
|
||||||
if len(aircraft) == 0:
|
if len(aircraft) == 0:
|
||||||
|
@ -77,21 +94,64 @@ def process_aircraft(acft, path):
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
digest = hashlib.md5(open(outTar, 'r').read()).hexdigest()
|
digest = hashlib.md5(open(outTar, 'r').read()).hexdigest()
|
||||||
|
revision = 1
|
||||||
|
|
||||||
|
# revision check
|
||||||
|
if acft in existingPackages:
|
||||||
|
previousMd5 = existingPackages[acft].find('md5').text
|
||||||
|
previousRevsion = int(existingPackages[acft].find('revision').text)
|
||||||
|
if digest != previousMd5:
|
||||||
|
print acft + ": MD5 has changed"
|
||||||
|
revision = previousRevsion + 1
|
||||||
|
else:
|
||||||
|
existingPackages[acft] = ET.Element('package')
|
||||||
|
|
||||||
|
setProperty(existingPackages[acft], 'id', acft)
|
||||||
|
setProperty(existingPackages[acft], 'revision', str(revision))
|
||||||
|
setProperty(existingPackages[acft], 'md5', digest)
|
||||||
|
setProperty(existingPackages[acft], 'description', aircraft[0]['desc'])
|
||||||
|
|
||||||
|
#setProperty(existingPackages[acft], 'thumbnails', thumbnailNames)
|
||||||
|
|
||||||
|
for t in thumbnailNames:
|
||||||
|
tn = ET.SubElement(existingPackages[acft], 'thumbnail')
|
||||||
|
tn.text = 'thumbs/' + t
|
||||||
|
|
||||||
|
existingPackages[acft].append(aircraft[0]['ratings'])
|
||||||
|
|
||||||
print "wrote tarfile, digest is " + digest
|
print "wrote tarfile, digest is " + digest
|
||||||
|
|
||||||
root = ET.Element('PropertyList')
|
root = ET.Element('PropertyList')
|
||||||
catalogTree = ET.ElementTree(root)
|
catalogTree = ET.ElementTree(root)
|
||||||
|
|
||||||
licenseElement = ET.SubElement(root, 'license')
|
existingPackages = dict()
|
||||||
licenseElement.text = 'gpl'
|
|
||||||
|
|
||||||
urlElement = ET.SubElement(root, 'url')
|
if (existingCatalog is not None):
|
||||||
urlElement.text = 'http://catalog.xml'
|
print 'have existing catalog data'
|
||||||
|
|
||||||
|
root.append(existingCatalog.find('license'))
|
||||||
|
root.append(existingCatalog.find('url'))
|
||||||
|
root.append(existingCatalog.find('description'))
|
||||||
|
root.append(existingCatalog.find('id'))
|
||||||
|
|
||||||
|
# existing data (for revision incrementing)
|
||||||
|
for n in existingCatalog.findall('package/id'):
|
||||||
|
existingPackages[n.text] = n;
|
||||||
|
|
||||||
|
#licenseElement = ET.SubElement(root, 'license')
|
||||||
|
#licenseElement.text = 'gpl'
|
||||||
|
|
||||||
|
#urlElement = ET.SubElement(root, 'url')
|
||||||
|
#urlElement.text = 'http://catalog.xml'
|
||||||
|
|
||||||
for acft in os.listdir(rootPath):
|
for acft in os.listdir(rootPath):
|
||||||
path = os.path.join(rootPath, acft);
|
path = os.path.join(rootPath, acft);
|
||||||
if (os.path.isdir(path)):
|
if (os.path.isdir(path)):
|
||||||
process_aircraft(acft, path)
|
process_aircraft(acft, path)
|
||||||
|
|
||||||
|
|
||||||
|
for ep in existingPackages:
|
||||||
|
root.append(existingPackages[ep])
|
||||||
|
|
||||||
catalogTree.write(os.path.join(outputDir, 'catalog.xml'), 'UTF-8')
|
catalogTree.write(os.path.join(outputDir, 'catalog.xml'), 'UTF-8')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue