diff --git a/catalog/catalogTags.py b/catalog/catalogTags.py index af785ff..9eff454 100644 --- a/catalog/catalogTags.py +++ b/catalog/catalogTags.py @@ -78,3 +78,6 @@ simFeatureTags = [ ] tags = aircraftTypeTags + manufacturerTags + eraTags + simFeatureTags + propulsionTags + featureTags + +def isValidTag(maybeTag): + return maybeTag in tags diff --git a/catalog/update-catalog.py b/catalog/update-catalog.py index b418588..2561a2a 100755 --- a/catalog/update-catalog.py +++ b/catalog/update-catalog.py @@ -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)