3 # Copyright (C) 2009 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 Usage: merge-event-log-tags.py [-o output_file] [input_files...]
20 Merge together zero or more event-logs-tags files to produce a single
21 output file, stripped of comments. Checks that no tag numbers conflict
24 -h to display this usage message and exit.
40 opts, args = getopt.getopt(sys.argv[1:], "ho:")
41 except getopt.GetoptError, err:
53 print >> sys.stderr, "unhandled option %s" % (o,)
57 tagfile = event_log_tags.TagFile(fn)
59 for t in tagfile.tags:
62 description = t.description
64 if t.tagnum in by_tagnum:
65 orig = by_tagnum[t.tagnum]
67 if (t.tagname == orig.tagname and
68 t.description == orig.description):
69 # if the name and description are identical, issue a warning
70 # instead of failing (to make it easier to move tags between
71 # projects without breaking the build).
72 tagfile.AddWarning("tag %d \"%s\" duplicated in %s:%d" %
73 (t.tagnum, t.tagname, orig.filename, orig.linenum),
76 tagfile.AddError("tag %d used by conflicting \"%s\" from %s:%d" %
77 (t.tagnum, orig.tagname, orig.filename, orig.linenum),
81 by_tagnum[t.tagnum] = t
83 errors.extend(tagfile.errors)
84 warnings.extend(tagfile.warnings)
87 for fn, ln, msg in errors:
88 print >> sys.stderr, "%s:%d: error: %s" % (fn, ln, msg)
92 for fn, ln, msg in warnings:
93 print >> sys.stderr, "%s:%d: warning: %s" % (fn, ln, msg)
95 buffer = cStringIO.StringIO()
96 for n in sorted(by_tagnum):
99 buffer.write("%d %s %s\n" % (t.tagnum, t.tagname, t.description))
101 buffer.write("%d %s\n" % (t.tagnum, t.tagname))
103 event_log_tags.WriteOutput(output_file, buffer)