Re-add tag validation and support to catalog.
Tags are copied to the catalog.xml again, and validated against catalogTags.py
This commit is contained in:
parent
7a64df78e3
commit
8e22064b71
2 changed files with 27 additions and 0 deletions
|
@ -78,3 +78,6 @@ simFeatureTags = [
|
|||
]
|
||||
|
||||
tags = aircraftTypeTags + manufacturerTags + eraTags + simFeatureTags + propulsionTags + featureTags
|
||||
|
||||
def isValidTag(maybeTag):
|
||||
return maybeTag in tags
|
||||
|
|
|
@ -11,6 +11,7 @@ import subprocess
|
|||
import time
|
||||
import sgprops
|
||||
import sys
|
||||
import catalogTags
|
||||
|
||||
CATALOG_VERSION = 4
|
||||
|
||||
|
@ -89,6 +90,9 @@ def scan_set_file(aircraft_dir, set_file):
|
|||
variant['rating_cockpit'] = rating_node.getValue("cockpit", 0)
|
||||
variant['rating_model'] = rating_node.getValue("model", 0)
|
||||
|
||||
if sim_node.hasChild('tags'):
|
||||
variant['tags'] = extract_tags(sim_node.getChild('tags'), set_file)
|
||||
|
||||
variant['variant-of'] = sim_node.getValue("variant-of", None)
|
||||
#print ' ', variant
|
||||
return variant
|
||||
|
@ -108,6 +112,17 @@ def extract_previews(previews_node, aircraft_dir):
|
|||
|
||||
return result
|
||||
|
||||
def extract_tags(tags_node, set_path):
|
||||
result = []
|
||||
for node in tags_node.getChildren("tag"):
|
||||
tag = node.value
|
||||
# check tag is in the allowed list
|
||||
if not catalogTags.isValidTag(tag):
|
||||
print "Unknown tag value:", tag, " in ", set_path
|
||||
result.append(tag)
|
||||
|
||||
return result
|
||||
|
||||
# scan all the -set.xml files in an aircraft directory. Returns a
|
||||
# package dict and a list of variants.
|
||||
def scan_aircraft_dir(aircraft_dir):
|
||||
|
@ -234,6 +249,13 @@ def copy_previews_for_package(package, variants, package_name, package_dir, prev
|
|||
for v in variants:
|
||||
copy_previews_for_variant(v, package_name, package_dir, previews_dir)
|
||||
|
||||
def append_tag_nodes(node, variant):
|
||||
if not 'tags' in variant:
|
||||
return
|
||||
|
||||
for tag in variant['tags']:
|
||||
node.append(make_xml_leaf('tag', tag))
|
||||
|
||||
#def get_file_stats(file):
|
||||
# f = open(file, 'r')
|
||||
# md5 = hashlib.md5(f.read()).hexdigest()
|
||||
|
@ -378,6 +400,7 @@ for scm in scm_list:
|
|||
variant_node.append( make_xml_leaf('author', variant['author']) )
|
||||
|
||||
append_preview_nodes(variant_node, variant, download_base, name)
|
||||
append_tag_nodes(variant_node, variant)
|
||||
|
||||
package_node.append( make_xml_leaf('dir', name) )
|
||||
if not download_base.endswith('/'):
|
||||
|
@ -388,6 +411,7 @@ for scm in scm_list:
|
|||
package_node.append( make_xml_leaf('thumbnail', thumbnail_url) )
|
||||
|
||||
append_preview_nodes(package_node, package, download_base, name)
|
||||
append_tag_nodes(package_node, package)
|
||||
|
||||
# todo: url (download), thumbnail (download url)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue