diff options
author | Brian Orr <brianorr@google.com> | 2021-06-15 12:47:53 -0700 |
---|---|---|
committer | Daniel Norman <danielnorman@google.com> | 2021-06-17 13:37:54 -0700 |
commit | 71c831703ae59baf47e0afe611fecd714c481cdf (patch) | |
tree | 06731a987032723085b9e1a65951cf96abbc19cf /tools/finalize_res/finalize_res.py | |
parent | 065c9e9a6e9d61d4383a91721eb56a3de253bdbe (diff) | |
parent | 81833820d54b9a6b27894f9f8dfd72222d416992 (diff) |
Merge SP1A.210604.001
Change-Id: I5200ee05285ae422d5e9c1c00f45709a5d6188be
Diffstat (limited to 'tools/finalize_res/finalize_res.py')
-rwxr-xr-x | tools/finalize_res/finalize_res.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/finalize_res/finalize_res.py b/tools/finalize_res/finalize_res.py new file mode 100755 index 000000000000..aaf01875024e --- /dev/null +++ b/tools/finalize_res/finalize_res.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +#-*- coding: utf-8 -*- + +# Copyright (C) 2021 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Finalize resource values in <staging-public-group> tags + +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)) + +def finalize_group(raw): + global _type, _id + _type = raw.group(1) + _id = int(raw.group(2), 16) + return re.sub(r'<public name="(.+?)" */>', finalize_item, raw.group(3)) + +with open(sys.argv[1]) as f: + raw = f.read() + raw = re.sub(r'<staging-public-group type="(.+?)" first-id="(.+?)">(.+?)</staging-public-group>', finalize_group, raw, flags=re.DOTALL) + with open(sys.argv[2], "w") as f: + f.write(raw) |