3 # Copyright (C) 2014 Red Hat.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 import cpmapi
as c_api
20 def optionsCB(opt
, optarg
, index
):
23 arg
= arg
+ " (" + optarg
+ ")"
24 arg
= arg
+ " [index=" + str(index
) + "]"
25 print("optionsCB: got option '" + arg
)
28 print("overrideCB: got option '" + str(opt
) + "'")
33 """ Create an options object and set/get everything possible """
35 options
= pmapi
.pmOptions("a:bfl:D:h:H:K:LS:T:O:A:s:t:VZ:z?")
36 options
.pmSetShortUsage("[options] parameters ...")
38 options
.pmSetLongOptionHeader("General Options")
39 options
.pmSetLongOptionAlign()
40 options
.pmSetLongOptionArchive()
41 options
.pmSetLongOptionDebug()
42 options
.pmSetLongOptionGuiMode()
43 options
.pmSetLongOptionHost()
44 options
.pmSetLongOptionHostsFile()
45 options
.pmSetLongOptionSpecLocal()
46 options
.pmSetLongOptionLocalPMDA()
47 options
.pmSetLongOptionOrigin()
48 options
.pmSetLongOptionGuiPort()
49 options
.pmSetLongOptionStart()
50 options
.pmSetLongOptionSamples()
51 options
.pmSetLongOptionFinish()
52 options
.pmSetLongOptionInterval()
53 options
.pmSetLongOptionVersion()
54 options
.pmSetLongOptionTimeZone()
55 options
.pmSetLongOptionHostZone()
56 options
.pmSetLongOptionHelp()
58 options
.pmSetLongOptionHeader("Test Options")
59 options
.pmSetLongOption("force", 0, 'f', '', "force some behaviour")
60 options
.pmSetLongOption("list", 1, 'l', "FILE", "open a list file")
61 options
.pmSetLongOptionText("")
62 options
.pmSetLongOptionText("The parameter parameter is not optional.")
64 options
.pmSetOptionCallback(optionsCB
)
65 options
.pmSetOverrideCallback(overrideCB
)
67 # parse options, extract values
68 if c_api
.pmGetOptionsFromList(system
.argv
) != 0:
69 c_api
.pmUsageMessage()
72 # extract any options we can (many are consumed internally) & dump
73 hosts
= options
.pmGetOptionHosts()
75 print("Host list: %s" % hosts
)
77 archives
= options
.pmGetOptionArchives()
79 print("Archive list: %s" % archives
)
81 timezone
= options
.pmGetOptionTimezone()
83 print("Timezone: %s" % timezone
)
85 samples
= options
.pmGetOptionSamples()
87 print("Samples: %d" % samples
)
89 interval
= options
.pmGetOptionInterval()
91 print("Interval: %s" % interval
)
93 nonoptions
= options
.pmNonOptionsFromList(system
.argv
)
94 if nonoptions
!= None:
95 print("Non-option arguments: %s" % nonoptions
)