aboutsummaryrefslogtreecommitdiff
path: root/tools/java-event-log-tags.py
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-12-03 16:58:40 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-12-03 16:58:40 -0800
commit485847e4c47e1504ddf8b830d557211d02a76e57 (patch)
tree935c833b5ed121e6b3d4dafb5fd69cbf317130e6 /tools/java-event-log-tags.py
parente4ea0ab8bd1ceef94399ac028e4fed1c18333b98 (diff)
parent9bd4962af87257c6a97e9026af7e4764394412c2 (diff)
Merge change I6f85805b into eclair-mr2
* changes: break up event-log-tags; generate java source files with constants
Diffstat (limited to 'tools/java-event-log-tags.py')
-rwxr-xr-xtools/java-event-log-tags.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/tools/java-event-log-tags.py b/tools/java-event-log-tags.py
new file mode 100755
index 0000000000..f8374b07ad
--- /dev/null
+++ b/tools/java-event-log-tags.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2009 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.
+
+"""
+Usage: java-event-log-tags.py [-o output_file] <input_file>
+
+Generate a java class containing constants for each of the event log
+tags in the given input file.
+
+-h to display this usage message and exit.
+"""
+
+import cStringIO
+import getopt
+import os
+import sys
+
+import event_log_tags
+
+output_file = None
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "ho:")
+except getopt.GetoptError, err:
+ print str(err)
+ print __doc__
+ sys.exit(2)
+
+for o, a in opts:
+ if o == "-h":
+ print __doc__
+ sys.exit(2)
+ elif o == "-o":
+ output_file = a
+ else:
+ print >> sys.stderr, "unhandled option %s" % (o,)
+ sys.exit(1)
+
+if len(args) != 1:
+ print "need exactly one input file, not %d" % (len(args),)
+ print __doc__
+ sys.exit(1)
+
+fn = args[0]
+tagfile = event_log_tags.TagFile(fn)
+
+if "java_package" not in tagfile.options:
+ tagfile.AddError("java_package option not specified", linenum=0)
+
+if tagfile.errors:
+ for fn, ln, msg in tagfile.errors:
+ print >> sys.stderr, "%s:%d: error: %s" % (fn, ln, msg)
+ sys.exit(1)
+
+buffer = cStringIO.StringIO()
+buffer.write("/* This file is auto-generated. DO NOT MODIFY.\n"
+ " * Source file: %s\n"
+ " */\n\n" % (fn,))
+
+buffer.write("package %s;\n\n" % (tagfile.options["java_package"][0],))
+
+basename, _ = os.path.splitext(os.path.basename(fn))
+buffer.write("public class %s {\n" % (basename,))
+buffer.write(" private %s() { } // don't instantiate\n" % (basename,))
+
+for t in tagfile.tags:
+ if t.description:
+ buffer.write("\n /** %d %s %s */\n" % (t.tagnum, t.tagname, t.description))
+ else:
+ buffer.write("\n /** %d %s */\n" % (t.tagnum, t.tagname))
+
+ buffer.write(" public static final int %s = %d;\n" %
+ (t.tagname.upper(), t.tagnum))
+buffer.write("}\n");
+
+event_log_tags.WriteOutput(output_file, buffer)