use optparse
This commit is contained in:
parent
a6db1511b7
commit
87f15f170c
1 changed files with 83 additions and 52 deletions
|
|
@ -396,10 +396,29 @@ class monitorCurses:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
# CURSES
|
usage = """Usage: %prog [options]
|
||||||
if len(sys.argv) > 1:
|
A user interface to monitor existing SSH tunnel that are managed with autossh.
|
||||||
if sys.argv[1] == "--curses":
|
|
||||||
|
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 curses
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
@ -437,20 +456,32 @@ if __name__ == "__main__":
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
elif sys.argv[1] == "--connections":
|
|
||||||
|
elif options.connections:
|
||||||
tm = AutoSSHTunnelMonitor()
|
tm = AutoSSHTunnelMonitor()
|
||||||
con = tm.get_connections()
|
con = tm.get_connections()
|
||||||
for c in con:
|
for c in con:
|
||||||
print con
|
print con
|
||||||
|
|
||||||
elif sys.argv[1] == "--autossh":
|
|
||||||
|
elif options.autossh:
|
||||||
tm = AutoSSHTunnelMonitor()
|
tm = AutoSSHTunnelMonitor()
|
||||||
auto = tm.get_autossh_instances()
|
auto = tm.get_autossh_instances()
|
||||||
for i in auto:
|
for i in auto:
|
||||||
print auto
|
print auto
|
||||||
|
|
||||||
# CLI
|
|
||||||
else:
|
else:
|
||||||
tm = AutoSSHTunnelMonitor()
|
tm = AutoSSHTunnelMonitor()
|
||||||
|
tm.update()
|
||||||
print tm
|
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
|
||||||
|
#
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue