-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_args.py
67 lines (51 loc) · 1.83 KB
/
parse_args.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4:shiftwidth=4:smarttab:expandtab:softtabstop=4:autoindent
import getopt
import sys
import os
from Config import Config
def parse_args(*argv):
shrt_args = "hf:c:t:"
long_args = ["help", "file=", "column=", "time="]
try:
opts, args = getopt.getopt(sys.argv[1:], shrt_args, long_args)
except getopt.GetoptError:
return False
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
elif opt in ("-f", "--file"):
Config.stats_file = arg
elif opt in ("-t", "--time"):
Config.timewait = float(arg)
elif opt in ("-c", "--column"):
try:
arg = int(arg)
except:
print("need integer in column argument")
usage()
os._exit(0)
if arg >= 0 and arg < 6:
Config.sort = int(arg)
else:
usage()
def usage():
message = """
Usage: {progname} [options]
\t-h, --help: __________________ Displays the usage.
\t-f, --file: __________________ stats file or http.
\t-c, --column: ________________ sort on this column number - from 0 to 5.
\t-t, --time: __________________ change the polling time in seconds.
\t"--column 0" means no sort at all
\tTips: You can use numbers from 0 to 5 during execution to dynamically change the column sorting
\tif no file is provided, the default will be:
\t\t/run/scality/connectors/sfused/misc/stats_sfused
Usage examples::
{progname} -f 'http://127.0.0.1:35951/store/bizobj/DATA/0?ctl=bizobj_advanced_stats'
{progname} -f /run/scality/connectors/sfused/misc/stats_sfused
{progname} -c 2 --time .5
{progname} --time 30
""".format(progname=sys.argv[0])
print(message)
os._exit(0)