Commit a0608df7 by Calen Pennington

Merge pull request #621 from MITx/feature/victor/fewer-xml-warnings

Remove lots of loud warnings about duplicate url names for things which ...
parents 2f3f9e5c c23b31c6
...@@ -62,6 +62,9 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem): ...@@ -62,6 +62,9 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
""" """
# VS[compat]. Take this out once course conversion is done (perhaps leave the uniqueness check) # VS[compat]. Take this out once course conversion is done (perhaps leave the uniqueness check)
# tags that really need unique names--they store (or should store) state.
need_uniq_names = ('problem', 'sequence', 'video', 'course', 'chapter')
attr = xml_data.attrib attr = xml_data.attrib
tag = xml_data.tag tag = xml_data.tag
id = lambda x: x id = lambda x: x
...@@ -86,12 +89,15 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem): ...@@ -86,12 +89,15 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
orig_name = "_" + orig_name if orig_name is not None else "" orig_name = "_" + orig_name if orig_name is not None else ""
return tag + orig_name + "_" + hashlib.sha1(xml).hexdigest()[:12] return tag + orig_name + "_" + hashlib.sha1(xml).hexdigest()[:12]
def looks_like_fallback(tag, url_name):
"""Does this look like something that came from fallback_name()?"""
return url_name.startswith(tag) and re.search('[0-9a-fA-F]{12}$', url_name)
# Fallback if there was nothing we could use: # Fallback if there was nothing we could use:
if url_name is None or url_name == "": if url_name is None or url_name == "":
url_name = fallback_name() url_name = fallback_name()
# Don't log a warning--we don't need this in the log. Do # Don't log a warning--we don't need this in the log. Do
# put it in the error tracker--content folks need to see it. # put it in the error tracker--content folks need to see it.
need_uniq_names = ('problem', 'sequence', 'video', 'course', 'chapter')
if tag in need_uniq_names: if tag in need_uniq_names:
error_tracker("PROBLEM: no name of any kind specified for {tag}. Student " error_tracker("PROBLEM: no name of any kind specified for {tag}. Student "
...@@ -105,20 +111,24 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem): ...@@ -105,20 +111,24 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
# Make sure everything is unique # Make sure everything is unique
if url_name in self.used_names[tag]: if url_name in self.used_names[tag]:
msg = ("Non-unique url_name in xml. This may break state tracking for content." # Always complain about modules that store state. If it
" url_name={0}. Content={1}".format(url_name, xml[:100])) # doesn't store state, don't complain about things that are
error_tracker("PROBLEM: " + msg) # hashed.
log.warning(msg) if tag in need_uniq_names or not looks_like_fallback(tag, url_name):
# Just set name to fallback_name--if there are multiple things with the same fallback name, msg = ("Non-unique url_name in xml. This may break state tracking for content."
# they are actually identical, so it's fragile, but not immediately broken. " url_name={0}. Content={1}".format(url_name, xml[:100]))
error_tracker("PROBLEM: " + msg)
# TODO (vshnayder): if the tag is a pointer tag, this will log.warning(msg)
# break the content because we won't have the right link. # Just set name to fallback_name--if there are multiple things with the same fallback name,
# That's also a legitimate attempt to reuse the same content # they are actually identical, so it's fragile, but not immediately broken.
# from multiple places. Once we actually allow that, we'll
# need to update this to complain about non-unique names for # TODO (vshnayder): if the tag is a pointer tag, this will
# definitions, but allow multiple uses. # break the content because we won't have the right link.
url_name = fallback_name(url_name) # That's also a legitimate attempt to reuse the same content
# from multiple places. Once we actually allow that, we'll
# need to update this to complain about non-unique names for
# definitions, but allow multiple uses.
url_name = fallback_name(url_name)
self.used_names[tag].add(url_name) self.used_names[tag].add(url_name)
xml_data.set('url_name', url_name) xml_data.set('url_name', url_name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment