blob: 6395fff5eae094e1850d6dae369e89d6417ccd03 [file] [log] [blame]
Andreas Wundsam76db0062013-11-15 13:34:41 -08001# Copyright 2013, Big Switch Networks, Inc.
2#
3# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4# the following special exception:
5#
6# LOXI Exception
7#
8# As a special exception to the terms of the EPL, you may distribute libraries
9# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10# that copyright and licensing notices generated by LoxiGen are not altered or removed
11# from the LoxiGen Libraries and the notice provided below is (i) included in
12# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13# documentation for the LoxiGen Libraries, if distributed in binary form.
14#
15# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16#
17# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18# a copy of the EPL at:
19#
20# http://www.eclipse.org/legal/epl-v10.html
21#
22# Unless required by applicable law or agreed to in writing, software
23# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25# EPL for the specific language governing permissions and limitations
26# under the EPL.
27
28from optparse import OptionParser
29
30from loxi_globals import OFVersions
31
Andreas Wundsam76db0062013-11-15 13:34:41 -080032##@var config_default
33# The default configuration dictionary for LOXI code generation
34options_default = {
35 "lang" : "c",
36 "version-list" : "1.0 1.1 1.2 1.3",
37 "install-dir" : "loxi_output",
38}
39
40def lang_normalize(lang):
41 """
42 Normalize the representation of the language
43 """
44 return lang.lower()
45
46def version_list_normalize(vlist):
47 """
48 Normalize the version list and return as an array
49 """
50 out_list = []
51 # @fixme Map to OF version references
52 if vlist.find(',') > 0:
53 vlist = vlist.split(',')
54 else:
55 vlist = vlist.split()
56 vlist.sort()
57 for ver in vlist:
58 try:
59 out_list.append(OFVersions.from_string(ver))
60 except KeyError:
61 sys.stderr.write("Bad version input, %s" % str(ver))
62 sys.exit(1)
63 return out_list
64
65def process_commandline(default_vals=options_default):
66 """
67 Set up the options dictionary
68
69 @param cfg_dflt The default configuration dictionary
70 @return A pair (options, args) as per parser return
71 """
Andreas Wundsam76db0062013-11-15 13:34:41 -080072 parser = OptionParser(version="%prog 0.1")
73
74 #@todo Add options via dictionary
75 parser.add_option("--list-files", action="store_true", default=False,
76 help="List output files generated")
77 parser.add_option("-l", "--lang", "--language",
78 default=default_vals["lang"],
79 help="Select the target language: c, python")
80 parser.add_option("-i", "--install-dir",
81 default=default_vals["install-dir"],
82 help="Directory to install generated files to (default %s)" % default_vals["install-dir"])
83 parser.add_option("-v", "--verbose",
84 action="store_true", default=False,
85 help="Debug output")
86
87 parser.add_option("-V", "--version-list",
88 default=default_vals["version-list"],
89 help="Specify the versions to target as 1.0 1.1 etc")
90
91 (options, args) = parser.parse_args()
92
93 options.lang = lang_normalize(options.lang)
94 target_version_list = version_list_normalize(options.version_list)
95 target_version_list.sort()
96 return (options, args, target_version_list)