qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / test_pcp_options.python
blob45f69d8dbb218bb42bdab61531afd2ad00242f3d
1 #!/usr/bin/pcp python
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
13 # for more details.
16 import sys as system
17 from pcp import pmapi
18 import cpmapi as c_api
20 def optionsCB(opt, optarg, index):
21 arg = "'" + opt + "'"
22 if optarg != None:
23 arg = arg + " (" + optarg + ")"
24 arg = arg + " [index=" + str(index) + "]"
25 print("optionsCB: got option '" + arg)
27 def overrideCB(opt):
28 print("overrideCB: got option '" + str(opt) + "'")
29 if opt == 'b':
30 return 1
31 return 0
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()
70 system.exit(1)
72 # extract any options we can (many are consumed internally) & dump
73 hosts = options.pmGetOptionHosts()
74 if hosts != None:
75 print("Host list: %s" % hosts)
77 archives = options.pmGetOptionArchives()
78 if archives != None:
79 print("Archive list: %s" % archives)
81 timezone = options.pmGetOptionTimezone()
82 if timezone != None:
83 print("Timezone: %s" % timezone)
85 samples = options.pmGetOptionSamples()
86 if samples != None:
87 print("Samples: %d" % samples)
89 interval = options.pmGetOptionInterval()
90 if interval != None:
91 print("Interval: %s" % interval)
93 nonoptions = options.pmNonOptionsFromList(system.argv)
94 if nonoptions != None:
95 print("Non-option arguments: %s" % nonoptions)
97 print("Done!")