diff options
Diffstat (limited to 'tools/finalize_res/finalize_res.py')
-rwxr-xr-x | tools/finalize_res/finalize_res.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/tools/finalize_res/finalize_res.py b/tools/finalize_res/finalize_res.py index aaf01875024e..724443c01852 100755 --- a/tools/finalize_res/finalize_res.py +++ b/tools/finalize_res/finalize_res.py @@ -17,6 +17,7 @@ """ Finalize resource values in <staging-public-group> tags +and convert those to <staging-public-group-final> Usage: finalize_res.py core/res/res/values/public.xml public_finalized.xml """ @@ -24,18 +25,40 @@ Usage: finalize_res.py core/res/res/values/public.xml public_finalized.xml import re, sys, codecs def finalize_item(raw): - global _type, _id - _id += 1 - return '<public type="%s" name="%s" id="%s" />' % (_type, raw.group(1), '0x{0:0{1}x}'.format(_id-1,8)) + global _type_ids, _type + id = _type_ids[_type] + _type_ids[_type] += 1 + name = raw.group(1) + val = '<public type="%s" name="%s" id="%s" />' % (_type, name, '0x{0:0{1}x}'.format(id,8)) + if re.match(r'_*removed.+', name): + val = '<!-- ' + val.replace('<public', '< public') + ' -->' + return val def finalize_group(raw): - global _type, _id + global _type_ids, _type _type = raw.group(1) - _id = int(raw.group(2), 16) - return re.sub(r'<public name="(.+?)" */>', finalize_item, raw.group(3)) + id = int(raw.group(2), 16) + _type_ids[_type] = _type_ids.get(_type, id) + (res, count) = re.subn(r' {0,2}<public name="(.+?)" */>', finalize_item, raw.group(3)) + if count > 0: + res = raw.group(0).replace("staging-public-group", "staging-public-group-final") + '\n' + res + return res + +def collect_ids(raw): + global _type_ids + for m in re.finditer(r'<public type="(.+?)" name=".+?" id="(.+?)" />', raw): + type = m.group(1) + id = int(m.group(2), 16) + _type_ids[type] = max(id + 1, _type_ids.get(type, 0)) with open(sys.argv[1]) as f: + global _type_ids, _type + _type_ids = {} raw = f.read() + collect_ids(raw) raw = re.sub(r'<staging-public-group type="(.+?)" first-id="(.+?)">(.+?)</staging-public-group>', finalize_group, raw, flags=re.DOTALL) + raw = re.sub(r' *\n', '\n', raw) + raw = re.sub(r'\n{3,}', '\n\n', raw) with open(sys.argv[2], "w") as f: f.write(raw) + |