Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: tools/android/remove_strings.py

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/android/purge_ashmem/purge_ashmem.c ('k') | tools/android/run_pie/run_pie.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/remove_strings.py
diff --git a/tools/android/remove_strings.py b/tools/android/remove_strings.py
new file mode 100755
index 0000000000000000000000000000000000000000..b8c4807d88e76e15e04a2fdd447d55f27efd44c5
--- /dev/null
+++ b/tools/android/remove_strings.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Remove strings by name from a GRD file."""
+
+import optparse
+import re
+import sys
+
+
+def RemoveStrings(grd_path, string_names):
+ """Removes strings with the given names from a GRD file. Overwrites the file.
+
+ Args:
+ grd_path: path to the GRD file.
+ string_names: a list of string names to be removed.
+ """
+ with open(grd_path, 'r') as f:
+ grd = f.read()
+ names_pattern = '|'.join(map(re.escape, string_names))
+ pattern = r'<message [^>]*name="(%s)".*?</message>\s*' % names_pattern
+ grd = re.sub(pattern, '', grd, flags=re.DOTALL)
+ with open(grd_path, 'w') as f:
+ f.write(grd)
+
+
+def ParseArgs(args):
+ usage = 'usage: %prog GRD_PATH...'
+ parser = optparse.OptionParser(
+ usage=usage, description='Remove strings from GRD files. Reads string '
+ 'names from stdin, and removes strings with those names from the listed '
+ 'GRD files.')
+ options, args = parser.parse_args(args=args)
+ if not args:
+ parser.error('must provide GRD_PATH argument(s)')
+ return args
+
+
+def main(args=None):
+ grd_paths = ParseArgs(args)
+ strings_to_remove = filter(None, map(str.strip, sys.stdin.readlines()))
+ for grd_path in grd_paths:
+ RemoveStrings(grd_path, strings_to_remove)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « tools/android/purge_ashmem/purge_ashmem.c ('k') | tools/android/run_pie/run_pie.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698