summaryrefslogtreecommitdiff
path: root/qa/src/test_pcp_options.python
blob: 2a87249b63e8536ba1afd3fcd7061f725e10e176 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# Copyright (C) 2014 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#

import sys as system
from pcp import pmapi
import cpmapi as c_api

def optionsCB(opt, optarg, index):
    arg = "'" + opt + "'"
    if optarg != None:
        arg = arg + " (" + optarg + ")"
    arg = arg + " [index=" + str(index) + "]"
    print("optionsCB: got option '" + arg)

def overrideCB(opt):
    print("overrideCB: got option '" + str(opt) + "'")
    if opt == 'b':
        return 1
    return 0

""" Create an options object and set/get everything possible """

options = pmapi.pmOptions("a:bfl:D:h:H:K:LS:T:O:A:s:t:VZ:z?")
options.pmSetShortUsage("[options] parameters ...")

options.pmSetLongOptionHeader("General Options")
options.pmSetLongOptionAlign()
options.pmSetLongOptionArchive()
options.pmSetLongOptionDebug()
options.pmSetLongOptionGuiMode()
options.pmSetLongOptionHost()
options.pmSetLongOptionHostsFile()
options.pmSetLongOptionSpecLocal()
options.pmSetLongOptionLocalPMDA()
options.pmSetLongOptionOrigin()
options.pmSetLongOptionGuiPort()
options.pmSetLongOptionStart()
options.pmSetLongOptionSamples()
options.pmSetLongOptionFinish()
options.pmSetLongOptionInterval()
options.pmSetLongOptionVersion()
options.pmSetLongOptionTimeZone()
options.pmSetLongOptionHostZone()
options.pmSetLongOptionHelp()

options.pmSetLongOptionHeader("Test Options")
options.pmSetLongOption("force", 0, 'f', '', "force some behaviour")
options.pmSetLongOption("list", 1, 'l', "FILE", "open a list file")
options.pmSetLongOptionText("")
options.pmSetLongOptionText("The parameter parameter is not optional.")

options.pmSetOptionCallback(optionsCB)
options.pmSetOverrideCallback(overrideCB)

# parse options, extract values
if c_api.pmGetOptionsFromList(system.argv) != 0:
    c_api.pmUsageMessage()
    system.exit(1)

# extract any options we can (many are consumed internally) & dump
hosts = options.pmGetOptionHosts()
if hosts != None:
    print("Host list: %s" % hosts)

archives = options.pmGetOptionArchives()
if archives != None:
    print("Archive list: %s" % archives)

timezone = options.pmGetOptionTimezone()
if timezone != None:
    print("Timezone: %s" % timezone)

samples = options.pmGetOptionSamples()
if samples != None:
    print("Samples: %d" % samples)

interval = options.pmGetOptionInterval()
if interval != None:
    print("Interval: %s" % interval)

nonoptions = options.pmNonOptionsFromList(system.argv)
if nonoptions != None:
    print("Non-option arguments: %s" % nonoptions)

print("Done!")