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

Source Code for Module flumotion.admin.text.greeter

  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 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22   
 23   
 24  from flumotion.admin import connections 
 25  from flumotion.common import log, connection as fconnection 
 26  from flumotion.twisted import flavors, reflect, pb as fpb 
 27  from flumotion.twisted.compat import implements 
 28  from flumotion.admin.text import misc_curses 
 29  from flumotion.admin.text import connection 
 30   
 31  from twisted.internet import reactor 
 32  import gobject 
 33  import curses 
 34   
35 -class AdminTextGreeter(log.Loggable, gobject.GObject, misc_curses.CursesStdIO):
36 implements(flavors.IStateListener) 37 38 logCategory = 'admintextgreeter' 39
40 - def __init__(self, stdscr):
41 self.stdscr = stdscr 42 self.connections = connections.get_recent_connections() 43 self.current_connection = 0 44 self.state = 0 45 self.current_input = '' 46 curses.curs_set(0) 47 self.entries = [ '', 'Hostname', 'Port', 'Secure?', 'Username', 'Password' ] 48 self.inputs = [ '', 'localhost', '7531', 'Yes', 'user', '' ]
49
50 - def show(self):
51 self.stdscr.addstr(0, 0, "Please choose a connection:") 52 53 cury = 3 54 maxyx = self.stdscr.getmaxyx() 55 self.debug("mayx: %d, %d", maxyx[0], maxyx[1]) 56 for c in self.connections: 57 self.debug("cury: %d", cury) 58 if cury - 3 == self.current_connection: 59 self.stdscr.addstr(cury, 10, c['name'], curses.A_REVERSE) 60 else: 61 self.stdscr.addstr(cury, 10, c['name']) 62 if cury + 10 > maxyx[0]: 63 break 64 cury = cury + 1 65 self.displayed_connections = cury - 3 66 if cury - 3 == self.current_connection: 67 self.stdscr.addstr(cury + 1, 10, "New connection...", curses.A_REVERSE) 68 else: 69 self.stdscr.addstr(cury + 1, 10, "New connection...") 70 self.stdscr.refresh()
71 72
74 cury = self.displayed_connections + 5 + self.state 75 if self.state > 0 and self.state < 5: 76 self.stdscr.addstr(cury, 10, "%s: %s" % (self.entries[self.state],self.current_input)) 77 elif self.state == 5: 78 # password entry 79 self.stdscr.addstr(cury, 10, "%s: " % self.entries[self.state]) 80 else: 81 self.stdscr.move(cury,10) 82 self.stdscr.clrtobot() 83 self.stdscr.refresh()
84
85 - def doRead(self):
86 c= self.stdscr.getch() 87 if self.state == 0: 88 if c == curses.KEY_DOWN: 89 if self.current_connection >= self.displayed_connections : 90 self.current_connection = 0 91 else: 92 self.current_connection = self.current_connection + 1 93 self.show() 94 elif c == curses.KEY_UP: 95 if self.current_connection == 0: 96 self.current_connection = self.displayed_connections 97 else: 98 self.current_connection = self.current_connection - 1 99 self.show() 100 elif c == curses.KEY_ENTER or c == 10: 101 # if new connection, ask for username, password, hostname etc. 102 if self.current_connection == self.displayed_connections: 103 curses.curs_set(1) 104 self.current_input = self.inputs[1] 105 self.state = 1 106 self.display_current_input_line() 107 else: 108 # ok a recent connection has been selected 109 curses.curs_set(1) 110 c = self.connections[self.current_connection] 111 info = c['info'] 112 reactor.removeReader(self) 113 connection.connect_to_manager(self.stdscr, info) 114 else: 115 if c == curses.KEY_ENTER or c == 10: 116 if self.state < 6: 117 self.inputs[self.state] = self.current_input 118 if self.state < 5: 119 self.current_input = self.inputs[self.state+1] 120 self.state = self.state + 1 121 self.display_current_input_line() 122 else: 123 # connect 124 reactor.removeReader(self) 125 try: 126 port = int(self.inputs[2]) 127 except ValueError: 128 port = 7531 129 info = fconnection.PBConnectionInfo(self.inputs[1], port, 130 self.inputs[3] == 'Yes', fpb.Authenticator( 131 username=self.inputs[4], password=self.inputs[5])) 132 133 connection.connect_to_manager(self.stdscr, info) 134 pass 135 elif c == curses.KEY_BACKSPACE or c == 127: 136 self.current_input = self.current_input[:-1] 137 self.display_current_input_line() 138 elif c == curses.KEY_UP: 139 if self.state > 0: 140 self.current_input = self.inputs[self.state-1] 141 self.state = self.state - 1 142 if self.state == 0: 143 # turn off cursor 144 curses.curs_set(0) 145 self.display_current_input_line() 146 elif c == curses.KEY_DOWN: 147 pass 148 else: 149 self.current_input = self.current_input + chr(c) 150 self.display_current_input_line()
151