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,2008 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  """interface displayed when you first run the cursor interface""" 
 23   
 24  import curses 
 25   
 26  import gobject 
 27  from twisted.internet import reactor 
 28  from zope.interface import implements 
 29   
 30  from flumotion.admin.connections import getRecentConnections 
 31  from flumotion.admin.text import misc_curses 
 32  from flumotion.admin.text import connection 
 33  from flumotion.common.connection import PBConnectionInfo 
 34  from flumotion.common import log 
 35  from flumotion.twisted import flavors, pb as fpb 
 36   
 37  __version__ = "$Rev: 6961 $" 
 38   
 39   
40 -class AdminTextGreeter(log.Loggable, gobject.GObject, misc_curses.CursesStdIO):
41 implements(flavors.IStateListener) 42 43 logCategory = 'admintextgreeter' 44
45 - def __init__(self, stdscr):
46 self.stdscr = stdscr 47 self.connections = getRecentConnections() 48 self.current_connection = 0 49 self.state = 0 50 self.current_input = '' 51 curses.curs_set(0) 52 self.entries = [ '', 'Hostname', 'Port', 'Secure?', 'Username', 'Password' ] 53 self.inputs = [ '', 'localhost', '7531', 'Yes', 'user', '' ]
54
55 - def show(self):
56 self.stdscr.addstr(0, 0, "Please choose a connection:") 57 58 cury = 3 59 maxyx = self.stdscr.getmaxyx() 60 self.debug("mayx: %d, %d", maxyx[0], maxyx[1]) 61 for c in self.connections: 62 self.debug("cury: %d", cury) 63 if cury - 3 == self.current_connection: 64 self.stdscr.addstr(cury, 10, c.name, curses.A_REVERSE) 65 else: 66 self.stdscr.addstr(cury, 10, c.name) 67 if cury + 10 > maxyx[0]: 68 break 69 cury = cury + 1 70 self.displayed_connections = cury - 3 71 if cury - 3 == self.current_connection: 72 self.stdscr.addstr(cury + 1, 10, "New connection...", curses.A_REVERSE) 73 else: 74 self.stdscr.addstr(cury + 1, 10, "New connection...") 75 self.stdscr.refresh()
76 77
79 cury = self.displayed_connections + 5 + self.state 80 if self.state > 0 and self.state < 5: 81 self.stdscr.addstr(cury, 10, "%s: %s" % (self.entries[self.state],self.current_input)) 82 elif self.state == 5: 83 # password entry 84 self.stdscr.addstr(cury, 10, "%s: " % self.entries[self.state]) 85 else: 86 self.stdscr.move(cury,10) 87 self.stdscr.clrtobot() 88 self.stdscr.refresh()
89
90 - def connectionLost(self, failure):
91 pass
92
93 - def doRead(self):
94 c= self.stdscr.getch() 95 if self.state == 0: 96 if c == curses.KEY_DOWN: 97 if self.current_connection >= self.displayed_connections : 98 self.current_connection = 0 99 else: 100 self.current_connection = self.current_connection + 1 101 self.show() 102 elif c == curses.KEY_UP: 103 if self.current_connection == 0: 104 self.current_connection = self.displayed_connections 105 else: 106 self.current_connection = self.current_connection - 1 107 self.show() 108 elif c == curses.KEY_ENTER or c == 10: 109 # if new connection, ask for username, password, hostname etc. 110 if self.current_connection == self.displayed_connections: 111 curses.curs_set(1) 112 self.current_input = self.inputs[1] 113 self.state = 1 114 self.display_current_input_line() 115 else: 116 # ok a recent connection has been selected 117 curses.curs_set(1) 118 c = self.connections[self.current_connection] 119 info = c.info 120 reactor.removeReader(self) 121 connection.connect_to_manager(self.stdscr, info) 122 else: 123 if c == curses.KEY_ENTER or c == 10: 124 if self.state < 6: 125 self.inputs[self.state] = self.current_input 126 if self.state < 5: 127 self.current_input = self.inputs[self.state+1] 128 self.state = self.state + 1 129 self.display_current_input_line() 130 else: 131 # connect 132 reactor.removeReader(self) 133 try: 134 port = int(self.inputs[2]) 135 except ValueError: 136 port = 7531 137 info = PBConnectionInfo(self.inputs[1], port, 138 self.inputs[3] == 'Yes', fpb.Authenticator( 139 username=self.inputs[4], password=self.inputs[5])) 140 141 connection.connect_to_manager(self.stdscr, info) 142 pass 143 elif c == curses.KEY_BACKSPACE or c == 127: 144 self.current_input = self.current_input[:-1] 145 self.display_current_input_line() 146 elif c == curses.KEY_UP: 147 if self.state > 0: 148 self.current_input = self.inputs[self.state-1] 149 self.state = self.state - 1 150 if self.state == 0: 151 # turn off cursor 152 curses.curs_set(0) 153 self.display_current_input_line() 154 elif c == curses.KEY_DOWN: 155 pass 156 else: 157 self.current_input = self.current_input + chr(c) 158 self.display_current_input_line()
159