* Fixes for unhandled/unrecognized command options.
* Documentation update. * Added help command.
This commit is contained in:
@@ -26,8 +26,8 @@ class ParseError(RuntimeError):
|
|||||||
class ProgramError(RuntimeError):
|
class ProgramError(RuntimeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#----------------------- UNDER CONSTRUCTION -----------------------
|
MYSELF = 'show-node-status.py'
|
||||||
#Nothing was done yet
|
|
||||||
|
|
||||||
def node_slot_stats_raw(qstat_f, show_disabled_nodes=False):
|
def node_slot_stats_raw(qstat_f, show_disabled_nodes=False):
|
||||||
"""Prints the node stats from `qstat -f' in raw format:
|
"""Prints the node stats from `qstat -f' in raw format:
|
||||||
@@ -228,31 +228,31 @@ def print_hosttype_stats(hosttype_stats):
|
|||||||
|
|
||||||
def help():
|
def help():
|
||||||
msg = """\
|
msg = """\
|
||||||
show-node-status.py - Showing node status from SGE information
|
%(CMD)s - Shows node status from SGE information
|
||||||
|
|
||||||
The information is mainly drawn from `qstat -f` output.
|
The information is mainly drawn from `qstat -f` output.
|
||||||
|
|
||||||
Usage: one of the following:
|
Usage: one of the following:
|
||||||
|
|
||||||
--raw
|
%(CMD)s raw [qstat_file] [--save] [--show-disabled-nodes]
|
||||||
raw
|
|
||||||
Shows the raw queue/node status
|
Shows the raw queue/node status
|
||||||
|
|
||||||
--stats
|
%(CMD)s
|
||||||
stats
|
%(CMD)s stats [qstat_file] [--save] [--show-disabled-nodes]
|
||||||
(no argument)
|
|
||||||
Shows the statistic summary per node type
|
Shows the statistic summary per node type
|
||||||
"""
|
""" \
|
||||||
|
% dict(CMD=MYSELF)
|
||||||
|
print(msg)
|
||||||
|
|
||||||
|
|
||||||
def main_default(argv, save_qstat=None):
|
def main_default(argv):
|
||||||
"""Main default function:
|
"""Main default function:
|
||||||
- By default we invoke qstat -f and prints the analysis.
|
- By default we invoke qstat -f and prints the analysis.
|
||||||
- If argv[1] is given, then we read in the file and
|
- If argv[1] is given, then we read in the file and
|
||||||
use that for the analysis.
|
use that for the analysis.
|
||||||
"""
|
"""
|
||||||
from time import localtime, strftime
|
from time import localtime, strftime
|
||||||
from getopt import getopt
|
from getopt import getopt, GetoptError
|
||||||
|
|
||||||
dtime = localtime()
|
dtime = localtime()
|
||||||
dtimestr = strftime("%Y%m%d-%H%M", dtime)
|
dtimestr = strftime("%Y%m%d-%H%M", dtime)
|
||||||
@@ -262,29 +262,41 @@ def main_default(argv, save_qstat=None):
|
|||||||
cmd = "stats"
|
cmd = "stats"
|
||||||
elif argv[1] in ('--raw', 'raw'):
|
elif argv[1] in ('--raw', 'raw'):
|
||||||
cmd = "raw"
|
cmd = "raw"
|
||||||
elif argv[1] in ('--stats', 'stats'):
|
elif argv[1] in ('--stats', 'stats', 'stat'):
|
||||||
cmd = "stats"
|
cmd = "stats"
|
||||||
|
elif argv[1] in ('--help', 'help', '-h'):
|
||||||
|
help()
|
||||||
|
return 0
|
||||||
else:
|
else:
|
||||||
raise ValueError, "Unknown action: "+argv[1]
|
raise ValueError, "Unknown action: "+argv[1]
|
||||||
|
|
||||||
# Skip program name and first command:
|
# Skip program name and first command:
|
||||||
cmdargs_in = argv[2:]
|
cmdargs_in = argv[2:]
|
||||||
cmdopts, cmdargs = getopt(cmdargs_in,
|
try:
|
||||||
"ds",
|
cmdopts, cmdargs = getopt(cmdargs_in,
|
||||||
["show-disabled-nodes=",
|
"dhs",
|
||||||
"include-disabled-nodes=",
|
["show-disabled-nodes=", "include-disabled-nodes=",
|
||||||
"save",
|
"save",
|
||||||
])
|
"help"])
|
||||||
|
except GetoptError as err:
|
||||||
|
sys.stderr.writelines([str(err), "\n"])
|
||||||
|
return 2
|
||||||
|
|
||||||
# Default options
|
# Process flag argument
|
||||||
show_disabled_nodes = False
|
show_disabled_nodes = False
|
||||||
|
save_qstat = False
|
||||||
for o,a in cmdopts:
|
for o,a in cmdopts:
|
||||||
if o in ('-d',):
|
if o in ('-h', '--help'):
|
||||||
|
help()
|
||||||
|
return 0
|
||||||
|
elif o in ('-d',):
|
||||||
show_disabled_nodes = True
|
show_disabled_nodes = True
|
||||||
elif o in ('--show-disabled-nodes', '--include-disabled-nodes'):
|
elif o in ('--show-disabled-nodes', '--include-disabled-nodes'):
|
||||||
show_disabled_nodes = parse_int_or_bool(a)
|
show_disabled_nodes = parse_int_or_bool(a)
|
||||||
elif o in ('-s', '--save'):
|
elif o in ('-s', '--save'):
|
||||||
save_qstat = True
|
save_qstat = True
|
||||||
|
else:
|
||||||
|
raise ProgramError, "Unhandled option in main program: %s %s" % (o,a)
|
||||||
|
|
||||||
if len(cmdargs) > 0:
|
if len(cmdargs) > 0:
|
||||||
qstat_f_current = open(cmdargs[0], "r").read().splitlines()
|
qstat_f_current = open(cmdargs[0], "r").read().splitlines()
|
||||||
@@ -306,6 +318,8 @@ def main_default(argv, save_qstat=None):
|
|||||||
else:
|
else:
|
||||||
raise ProgramError, "Missing support for command: "+cmd
|
raise ProgramError, "Missing support for command: "+cmd
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user