crowdin: Fix removing invalid product strings
* Removing items from a list while iterating it is not a good idea
and results in unexpected results
* Instead of removing them, add them to an ignore list and check the
current item against it
Change-Id: I6395f78d8ace3da6f5c443bdf12e4da9ae032026
diff --git a/crowdin_sync.py b/crowdin_sync.py
index ba4a5fc..f64e1d4 100755
--- a/crowdin_sync.py
+++ b/crowdin_sync.py
@@ -152,8 +152,12 @@
# Remove strings with 'product=*' attribute but no 'product=default'
# This will ensure aapt2 will not throw an error when building these
+ alreadyRemoved = []
productStrings = tree.xpath("//string[@product]")
for ps in productStrings:
+ # if we already removed the items, don't process them
+ if ps in alreadyRemoved:
+ continue
stringName = ps.get('name')
stringsWithSameName = tree.xpath("//string[@name='{0}']"
.format(stringName))
@@ -173,7 +177,7 @@
.format(path, stringName))
for string in stringsWithSameName:
tree.remove(string)
- productStrings.remove(string)
+ alreadyRemoved.append(string)
header = ''
comments = tree.xpath('//comment()')