in library/scripts/find_movable_strings.py [0:0]
def find_strings_used_in_xml(filename, safe_widgets):
result = set()
# Ignore the file if it throws an error while parsing
# Started seeing this in some of the xml files, that were not layout files. We do not expect
# this error to be thrown in layout files or files that we are interested in
try:
tree = ElementTree.parse(filename)
for node in tree.findall(".//"):
if node.tag in safe_widgets:
continue # Certain widgets can handle @string just fine
if node.text is not None:
for string in STRING_USAGE_RE.findall(node.text):
result.add(string)
for key, value in node.attrib.items():
string_usage_match = STRING_USAGE_RE.search(value)
if string_usage_match:
namespace, attrib = separate_namespace(key)
if namespace in OK_NAMESPACES:
continue # Certain namespace are safe to use @string in
result.add(string_usage_match.group(1))
except ElementTree.ParseError:
logging.warning(
SET_WARNING_COLOR
+ "Dropping the file becase of ParseError: "
+ filename
+ CLEAR_COLOR
)
finally:
return result