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

Side by Side 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, 8 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Remove strings by name from a GRD file."""
7
8 import optparse
9 import re
10 import sys
11
12
13 def RemoveStrings(grd_path, string_names):
14 """Removes strings with the given names from a GRD file. Overwrites the file.
15
16 Args:
17 grd_path: path to the GRD file.
18 string_names: a list of string names to be removed.
19 """
20 with open(grd_path, 'r') as f:
21 grd = f.read()
22 names_pattern = '|'.join(map(re.escape, string_names))
23 pattern = r'<message [^>]*name="(%s)".*?</message>\s*' % names_pattern
24 grd = re.sub(pattern, '', grd, flags=re.DOTALL)
25 with open(grd_path, 'w') as f:
26 f.write(grd)
27
28
29 def ParseArgs(args):
30 usage = 'usage: %prog GRD_PATH...'
31 parser = optparse.OptionParser(
32 usage=usage, description='Remove strings from GRD files. Reads string '
33 'names from stdin, and removes strings with those names from the listed '
34 'GRD files.')
35 options, args = parser.parse_args(args=args)
36 if not args:
37 parser.error('must provide GRD_PATH argument(s)')
38 return args
39
40
41 def main(args=None):
42 grd_paths = ParseArgs(args)
43 strings_to_remove = filter(None, map(str.strip, sys.stdin.readlines()))
44 for grd_path in grd_paths:
45 RemoveStrings(grd_path, strings_to_remove)
46
47
48 if __name__ == '__main__':
49 main()
OLDNEW
« 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