summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2014-10-27 10:19:59 +0200
committerToma┼ż Vajngerl <tomaz.vajngerl@collabora.com>2014-12-04 23:04:24 +0100
commit7c77a44ced27975499132b80322fdaeefa7f2287 (patch)
tree946170bbe0170b7122e38229abbd7555bb2edb13
parentebd868076b3b0aca660275b830b387eb96e30fee (diff)
Beware of modifying a list being iterated
Change-Id: Ib9cf1a47eb20bd28d954ddcded89f67cf6865f1c
-rwxr-xr-xandroid/mobile-config.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/android/mobile-config.py b/android/mobile-config.py
index ff2fd533dbd1..cdf0afc6583a 100755
--- a/android/mobile-config.py
+++ b/android/mobile-config.py
@@ -54,18 +54,26 @@ if __name__ == '__main__':
tree = ET.parse(sys.argv[1])
root = tree.getroot()
- saved = 0
total = 0
for child in root:
- section = child.attrib['{http://openoffice.org/2001/registry}name']
- package = child.attrib['{http://openoffice.org/2001/registry}package']
- size = len(ET.tostring(child));
- total = total + size
- key = '%s/%s' % (package, section)
- if key in main_xcd_discard:
- root.remove(child)
- print 'removed %s - saving %d' % (key, size)
- saved = saved + size
+ total += len(ET.tostring(child))
+
+ saved = 0
+ restarted = True
+
+ while restarted:
+ restarted = False
+ for child in root:
+ section = child.attrib['{http://openoffice.org/2001/registry}name']
+ package = child.attrib['{http://openoffice.org/2001/registry}package']
+ size = len(ET.tostring(child));
+ key = '%s/%s' % (package, section)
+ if key in main_xcd_discard:
+ root.remove(child)
+ print 'removed %s - saving %d' % (key, size)
+ saved = saved + size
+ restarted = True
+ break
print "saved %d of %d bytes: %2.f%%" % (saved, total, saved*100.0/total)