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

Unified Diff: third_party/chrome/ppapi/generators/idl_option.py

Issue 12300042: Update idlsync.py to pull in dependencies required for chrome api generation. (Closed) Base URL: git://github.com/dart-lang/bleeding_edge.git@master
Patch Set: From another checkout Created 7 years, 10 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 | « third_party/chrome/ppapi/generators/idl_node.py ('k') | third_party/chrome/ppapi/generators/idl_outfile.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/chrome/ppapi/generators/idl_option.py
diff --git a/third_party/chrome/ppapi/generators/idl_option.py b/third_party/chrome/ppapi/generators/idl_option.py
new file mode 100644
index 0000000000000000000000000000000000000000..54ac4cf25fce1004fec3f29a3a5177e3c3d7465c
--- /dev/null
+++ b/third_party/chrome/ppapi/generators/idl_option.py
@@ -0,0 +1,108 @@
+# Copyright (c) 2012 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.
+
+import getopt
+import sys
+
+from idl_log import ErrOut, InfoOut, WarnOut
+
+OptionMap = { }
+
+
+def GetOption(name):
+ if name not in OptionMap:
+ raise RuntimeError('Could not find option "%s".' % name)
+ return OptionMap[name].Get()
+
+class Option(object):
+ def __init__(self, name, desc, default = None, callfunc = None,
+ testfunc = None, cookie = None):
+
+ # Verify this option is not a duplicate
+ if name in OptionMap:
+ raise RuntimeError('Option "%s" already exists.' % name)
+ self.name = name
+ self.desc = desc
+ self.default = default
+ self.value = default
+ self.callfunc = callfunc
+ self.testfunc = testfunc
+ self.cookie = cookie
+ OptionMap[name] = self
+
+ def Set(self, value):
+ if self.testfunc:
+ if not self.testfunc(self, value): return False
+ # If this is a boolean option, set it to true
+ if self.default is None:
+ self.value = True
+ else:
+ self.value = value
+ if self.callfunc:
+ self.callfunc(self)
+ return True
+
+ def Get(self):
+ return self.value
+
+
+def DumpOption(option):
+ if len(option.name) > 1:
+ out = ' --%-15.15s\t%s' % (option.name, option.desc)
+ else:
+ out = ' -%-15.15s\t%s' % (option.name, option.desc)
+ if option.default:
+ out = '%s\n\t\t\t(Default: %s)\n' % (out, option.default)
+ InfoOut.Log(out)
+
+def DumpHelp(option=None):
+ InfoOut.Log('Usage:')
+ for opt in sorted(OptionMap.keys()):
+ DumpOption(OptionMap[opt])
+ sys.exit(0)
+
+#
+# Default IDL options
+#
+# -h : Help, prints options
+# --verbose : use verbose output
+# --test : test this module
+#
+Option('h', 'Help', callfunc=DumpHelp)
+Option('help', 'Help', callfunc=DumpHelp)
+Option('verbose', 'Verbose')
+Option('test', 'Test the IDL scripts')
+
+def ParseOptions(args):
+ short_opts= ""
+ long_opts = []
+
+ # Build short and long option lists
+ for name in sorted(OptionMap.keys()):
+ option = OptionMap[name]
+ if len(name) > 1:
+ if option.default is None:
+ long_opts.append('%s' % name)
+ else:
+ long_opts.append('%s=' % name)
+ else:
+ if option.default is None:
+ short_opts += name
+ else:
+ short_opts += '%s:' % name
+
+ try:
+ opts, filenames = getopt.getopt(args, short_opts, long_opts)
+
+ for opt, val in opts:
+ if len(opt) == 2: opt = opt[1:]
+ if opt[0:2] == '--': opt = opt[2:]
+ OptionMap[opt].Set(val)
+
+ except getopt.error, e:
+ ErrOut.Log('Illegal option: %s\n' % str(e))
+ DumpHelp()
+ sys.exit(-1)
+
+ return filenames
« no previous file with comments | « third_party/chrome/ppapi/generators/idl_node.py ('k') | third_party/chrome/ppapi/generators/idl_outfile.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698