summaryrefslogtreecommitdiff
path: root/tools/finalize_res/finalize_res.py
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2021-05-27 13:12:27 -0600
committerJeff Sharkey <jsharkey@android.com>2021-06-01 06:48:52 -0600
commitde062e478c37e98ac61540c9e68af717d95ca9cf (patch)
tree0819afdf941e2541ed455df938904152946decb6 /tools/finalize_res/finalize_res.py
parent7c5f4337fd0b1fbcfe94b035601c67b1e7f47a2e (diff)
Finalize resource IDs; script to help in future.
Bug: 171506470 Test: Build Change-Id: I7b7360475ff0f6f4d4c8b8872eefc4e80fd9640e
Diffstat (limited to 'tools/finalize_res/finalize_res.py')
-rwxr-xr-xtools/finalize_res/finalize_res.py41
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)