| 1 |
|
|---|
| 2 |
import optparse; |
|---|
| 3 |
|
|---|
| 4 |
class OptionHandler: |
|---|
| 5 |
""" Support for command line options. |
|---|
| 6 |
""" |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
m_options = None; |
|---|
| 14 |
m_args = None; |
|---|
| 15 |
m_parser = None; |
|---|
| 16 |
|
|---|
| 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]; |
|---|
| 22 |
|
|---|
| 23 |
if (optionVal != None) and (optionVal != False): |
|---|
| 24 |
return True; |
|---|
| 25 |
|
|---|
| 26 |
return False; |
|---|
| 27 |
|
|---|
| 28 |
getOptionActive = staticmethod(getOptionActive); |
|---|
| 29 |
|
|---|
| 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]; |
|---|
| 35 |
|
|---|
| 36 |
return None; |
|---|
| 37 |
|
|---|
| 38 |
getOptionArg = staticmethod(getOptionArg); |
|---|
| 39 |
|
|---|
| 40 |
def getOptionList(): |
|---|
| 41 |
""" Low level access to the options dictionary. |
|---|
| 42 |
""" |
|---|
| 43 |
return OptionHandler.m_options; |
|---|
| 44 |
|
|---|
| 45 |
getOptionList = staticmethod(getOptionList); |
|---|
| 46 |
|
|---|
| 47 |
def getArgList(): |
|---|
| 48 |
""" Low level access to the arguments list. |
|---|
| 49 |
""" |
|---|
| 50 |
return OptionHandler.m_args; |
|---|
| 51 |
|
|---|
| 52 |
getArgList = staticmethod(getArgList); |
|---|
| 53 |
|
|---|
| 54 |
def setup(): |
|---|
| 55 |
""" Setup option parser |
|---|
| 56 |
""" |
|---|
| 57 |
if OptionHandler.m_parser != None: |
|---|
| 58 |
print "WARNING: OptionHandler.setup: Called twice."; |
|---|
| 59 |
return; |
|---|
| 60 |
|
|---|
| 61 |
OptionHandler.m_parser = optparse.OptionParser(); |
|---|
| 62 |
|
|---|
| 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"); |
|---|
| 70 |
|
|---|
| 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]."); |
|---|
| 76 |
|
|---|
| 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]."); |
|---|
| 82 |
|
|---|
| 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"); |
|---|
| 90 |
|
|---|
| 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"); |
|---|
| 98 |
|
|---|
| 99 |
OptionHandler.m_parser.add_option( |
|---|
| 100 |
"-v", "--verbose", |
|---|
| 101 |
action="store_true", |
|---|
| 102 |
dest="verbose", |
|---|
| 103 |
help="print diagnostic messages. [default: false]."); |
|---|
| 104 |
|
|---|
| 105 |
OptionHandler.m_parser.add_option( |
|---|
| 106 |
"-c", "--compat-mode", |
|---|
| 107 |
action="store_true", |
|---|
| 108 |
dest="compatMode", |
|---|
| 109 |
help="enable 1.x compatibility mode. [default: false]."); |
|---|
| 110 |
|
|---|
| 111 |
OptionHandler.m_parser.add_option( |
|---|
| 112 |
"-B", "--bundle", |
|---|
| 113 |
action="store_true", |
|---|
| 114 |
dest="bundleMode", |
|---|
| 115 |
help="create field bundle. [default: false]."); |
|---|
| 116 |
|
|---|
| 117 |
OptionHandler.m_parser.set_defaults(writeBase=False); |
|---|
| 118 |
OptionHandler.m_parser.set_defaults(writeFC=False); |
|---|
| 119 |
OptionHandler.m_parser.set_defaults(verbose=False); |
|---|
| 120 |
|
|---|
| 121 |
setup = staticmethod(setup); |
|---|
| 122 |
|
|---|
| 123 |
def parse(args): |
|---|
| 124 |
""" Parse command line arguments. |
|---|
| 125 |
""" |
|---|
| 126 |
if OptionHandler.m_parser == None: |
|---|
| 127 |
print "WARNING: OptionHandler.parse: no parser, run setup first."; |
|---|
| 128 |
return; |
|---|
| 129 |
|
|---|
| 130 |
(options, args) = OptionHandler.m_parser.parse_args(args); |
|---|
| 131 |
|
|---|
| 132 |
OptionHandler.m_options = options; |
|---|
| 133 |
OptionHandler.m_args = args; |
|---|
| 134 |
|
|---|
| 135 |
parse = staticmethod(parse); |
|---|