fixed: gcc8 compile issues
[opensg.git] / Tools / fcd2code / OptionHandler.py
blob06be085d14d4729b169406989f670fa9625dffea
2 import optparse;
4 class OptionHandler:
5 """ Support for command line options.
6 """
8 #### class member
9 # m_options -- option object (returned by optparse.parse_args)
10 # m_args -- arguments list (returned by optparse.parse_args)
11 # m_parser -- option parser
13 m_options = None;
14 m_args = None;
15 m_parser = None;
17 def getOptionActive(optionName):
18 """ Returns true if the given option is active
19 """
20 if optionName in OptionHandler.m_options.__dict__:
21 optionVal = OptionHandler.m_options.__dict__[optionName];
23 if (optionVal != None) and (optionVal != False):
24 return True;
26 return False;
28 getOptionActive = staticmethod(getOptionActive);
30 def getOptionArg(optionName):
31 """ Returns the argument of an option
32 """
33 if optionName in OptionHandler.m_options.__dict__:
34 return OptionHandler.m_options.__dict__[optionName];
36 return None;
38 getOptionArg = staticmethod(getOptionArg);
40 def getOptionList():
41 """ Low level access to the options dictionary.
42 """
43 return OptionHandler.m_options;
45 getOptionList = staticmethod(getOptionList);
47 def getArgList():
48 """ Low level access to the arguments list.
49 """
50 return OptionHandler.m_args;
52 getArgList = staticmethod(getArgList);
54 def setup():
55 """ Setup option parser
56 """
57 if OptionHandler.m_parser != None:
58 print "WARNING: OptionHandler.setup: Called twice.";
59 return;
61 OptionHandler.m_parser = optparse.OptionParser();
63 OptionHandler.m_parser.add_option(
64 "-d", "--fcd-file",
65 action="store",
66 type="string",
67 dest="fcdFile",
68 help="FieldContainer description file.",
69 metavar="file.fcd");
71 OptionHandler.m_parser.add_option(
72 "-b", "--write-base",
73 action="store_true",
74 dest="writeBase",
75 help="write the FieldContainerBase files. [default: false].");
77 OptionHandler.m_parser.add_option(
78 "-f", "--write-fc",
79 action="store_true",
80 dest="writeFC",
81 help="write the FieldContainer files. [default: false].");
83 OptionHandler.m_parser.add_option(
84 "-p", "--out-path",
85 action="store",
86 type="string",
87 dest="outPath",
88 help="destination path for files.",
89 metavar="PATH");
91 OptionHandler.m_parser.add_option(
92 "-r", "--root-path",
93 action="store",
94 type="string",
95 dest="rootPath",
96 help="root of the OpenSG source tree.",
97 metavar="PATH");
99 OptionHandler.m_parser.add_option(
100 "-t", "--template-path",
101 action="store",
102 type="string",
103 dest="templatePath",
104 help="path to where the fcd2code templates are stored.",
105 metavar="PATH");
107 OptionHandler.m_parser.add_option(
108 "-v", "--verbose",
109 action="store_true",
110 dest="verbose",
111 help="print diagnostic messages. [default: false].");
113 OptionHandler.m_parser.add_option(
114 "-c", "--compat-mode",
115 action="store_true",
116 dest="compatMode",
117 help="enable 1.x compatibility mode. [default: false].");
119 OptionHandler.m_parser.add_option(
120 "-B", "--bundle",
121 action="store_true",
122 dest="bundleMode",
123 help="create field bundle. [default: false].");
125 OptionHandler.m_parser.set_defaults(writeBase=False);
126 OptionHandler.m_parser.set_defaults(writeFC=False);
127 OptionHandler.m_parser.set_defaults(verbose=False);
129 setup = staticmethod(setup);
131 def parse(args):
132 """ Parse command line arguments.
134 if OptionHandler.m_parser == None:
135 print "WARNING: OptionHandler.parse: no parser, run setup first.";
136 return;
138 (options, args) = OptionHandler.m_parser.parse_args(args);
140 OptionHandler.m_options = options;
141 OptionHandler.m_args = args;
143 parse = staticmethod(parse);