Package flumotion :: Package admin :: Package text :: Module main
[hide private]

Source Code for Module flumotion.admin.text.main

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  """flumotion-admin-text entry point, command line parsing and invokation""" 
 19   
 20  import curses 
 21   
 22  from twisted.internet import reactor 
 23   
 24  from flumotion.admin.text import connection 
 25  from flumotion.admin.text.greeter import AdminTextGreeter 
 26  from flumotion.common import messages # make Message proxyable 
 27  from flumotion.common.options import OptionParser 
 28  from flumotion.common.connection import PBConnectionInfo 
 29  from flumotion.twisted import pb as fpb 
 30   
 31  __version__ = "$Rev$" 
 32   
 33   
34 -def cleanup_curses(stdscr):
35 curses.nocbreak() 36 stdscr.keypad(0) 37 curses.echo() 38 curses.endwin()
39 40
41 -def _runInterface(options):
42 # initialise curses 43 44 stdscr = curses.initscr() 45 curses.noecho() 46 curses.cbreak() 47 stdscr.nodelay(1) 48 stdscr.keypad(1) 49 50 reactor.addSystemEventTrigger('after', 51 'shutdown', cleanup_curses, stdscr) 52 53 54 # first lets sort out logging in 55 username = 'user' 56 password = 'test' 57 hostname = 'localhost' 58 insecure = False 59 port = 7531 60 if options.username and options.password and options.hostname: 61 username = options.username 62 password = options.password 63 hostname = options.hostname 64 if options.port: 65 try: 66 port = int(options.port) 67 except ValueError: 68 pass 69 if options.insecure: 70 insecure = True 71 authenticator = fpb.Authenticator(username=username, password=password) 72 info = PBConnectionInfo(hostname, port, not insecure, authenticator) 73 connection.connect_to_manager(stdscr, info) 74 75 else: 76 # do greeter 77 # get recent connections 78 greeter = AdminTextGreeter(stdscr) 79 reactor.addReader(greeter) 80 greeter.show()
81 82
83 -def main(args):
84 parser = OptionParser(domain="flumotion-admin-text") 85 parser.add_option('-u', '--username', 86 action="store", type="string", dest="username", 87 help="set username to connect to manager") 88 parser.add_option('-P', '--password', 89 action="store", type="string", dest="password", 90 help="set password to connect to manager") 91 parser.add_option('-H', '--hostname', 92 action="store", type="string", dest="hostname", 93 help="set hostname of manager to connect to") 94 parser.add_option('-p', '--port', 95 action="store", type="string", dest="port", 96 help="set port of manager to connect to") 97 parser.add_option('', '--insecure', 98 action="store_true", dest="insecure", 99 help="make insecure connection") 100 101 options, args = parser.parse_args(args) 102 103 _runInterface(options) 104 105 reactor.run()
106