use optparse

This commit is contained in:
nojhan 2009-06-28 20:30:51 +00:00
commit 87f15f170c

View file

@ -396,10 +396,29 @@ class monitorCurses:
if __name__ == "__main__":
import sys
from optparse import OptionParser
# CURSES
if len(sys.argv) > 1:
if sys.argv[1] == "--curses":
usage = """Usage: %prog [options]
A user interface to monitor existing SSH tunnel that are managed with autossh.
Called without options, ereshkigal displays
"""
parser = OptionParser(usage=usage)
parser.add_option("-c", "--curses", dest="curses", default=False,
help="Start the user interface in text mode")
parser.add_option("-n", "--connections", dest="connections", default=False,
help="Display only the list of SSH connections related to a tunnel")
parser.add_option("-a", "--autossh", dest="autossh", default=False,
help="Display only the list of autossh processes")
(options, args) = parser.parse_args()
#if len(options) > 1:
# parser.error("options are mutually exclusive")
if options.curses:
import curses
import traceback
@ -437,20 +456,32 @@ if __name__ == "__main__":
curses.endwin()
traceback.print_exc()
elif sys.argv[1] == "--connections":
elif options.connections:
tm = AutoSSHTunnelMonitor()
con = tm.get_connections()
for c in con:
print con
elif sys.argv[1] == "--autossh":
elif options.autossh:
tm = AutoSSHTunnelMonitor()
auto = tm.get_autossh_instances()
for i in auto:
print auto
# CLI
else:
tm = AutoSSHTunnelMonitor()
tm.update()
print tm
#
# In Mesopotamian mythology, Ereshkigal (lit. "great lady under earth")
# was the goddess of Irkalla, the land of the dead or underworld.
#
# Thus, she knows a lot about tunnels...
#
# http://en.wikipedia.org/wiki/Ereshkigal
#