* Fixes for unhandled/unrecognized command options.

* Documentation update.
* Added help command.
master
Wirawan Purwanto 8 years ago
parent 850bd34377
commit 67bc899f4a
  1. 50
      sge/show-node-status.py

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

Loading…
Cancel
Save