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: 7162 $" 
 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?', 53 'Username', 'Password'] 54 self.inputs = ['', 'localhost', '7531', 'Yes', 'user', '']
55
56 - def show(self):
57 self.stdscr.addstr(0, 0, "Please choose a connection:") 58 59 cury = 3 60 maxyx = self.stdscr.getmaxyx() 61 self.debug("mayx: %d, %d", maxyx[0], maxyx[1]) 62 for c in self.connections: 63 self.debug("cury: %d", cury) 64 if cury - 3 == self.current_connection: 65 self.stdscr.addstr(cury, 10, c.name, curses.A_REVERSE) 66 else: 67 self.stdscr.addstr(cury, 10, c.name) 68 if cury + 10 > maxyx[0]: 69 break 70 cury = cury + 1 71 self.displayed_connections = cury - 3 72 if cury - 3 == self.current_connection: 73 self.stdscr.addstr(cury + 1, 10, "New connection...", 74 curses.A_REVERSE) 75 else: 76 self.stdscr.addstr(cury + 1, 10, "New connection...") 77 self.stdscr.refresh()
78
80 cury = self.displayed_connections + 5 + self.state 81 if self.state > 0 and self.state < 5: 82 self.stdscr.addstr(cury, 10, "%s: %s" % (self.entries[self.state], 83 self.current_input)) 84 elif self.state == 5: 85 # password entry 86 self.stdscr.addstr(cury, 10, "%s: " % self.entries[self.state]) 87 else: 88 self.stdscr.move(cury, 10) 89 self.stdscr.clrtobot() 90 self.stdscr.refresh()
91
92 - def connectionLost(self, failure):
93 pass
94
95 - def doRead(self):
96 c= self.stdscr.getch() 97 if self.state == 0: 98 if c == curses.KEY_DOWN: 99 if self.current_connection >= self.displayed_connections: 100 self.current_connection = 0 101 else: 102 self.current_connection = self.current_connection + 1 103 self.show() 104 elif c == curses.KEY_UP: 105 if self.current_connection == 0: 106 self.current_connection = self.displayed_connections 107 else: 108 self.current_connection = self.current_connection - 1 109 self.show() 110 elif c == curses.KEY_ENTER or c == 10: 111 # if new connection, ask for username, password, hostname etc. 112 if self.current_connection == self.displayed_connections: 113 curses.curs_set(1) 114 self.current_input = self.inputs[1] 115 self.state = 1 116 self.display_current_input_line() 117 else: 118 # ok a recent connection has been selected 119 curses.curs_set(1) 120 c = self.connections[self.current_connection] 121 info = c.info 122 reactor.removeReader(self) 123 connection.connect_to_manager(self.stdscr, info) 124 else: 125 if c == curses.KEY_ENTER or c == 10: 126 if self.state < 6: 127 self.inputs[self.state] = self.current_input 128 if self.state < 5: 129 self.current_input = self.inputs[self.state+1] 130 self.state = self.state + 1 131 self.display_current_input_line() 132 else: 133 # connect 134 reactor.removeReader(self) 135 try: 136 port = int(self.inputs[2]) 137 except ValueError: 138 port = 7531 139 info = PBConnectionInfo(self.inputs[1], port, 140 self.inputs[3] == 'Yes', fpb.Authenticator( 141 username=self.inputs[4], password=self.inputs[5])) 142 143 connection.connect_to_manager(self.stdscr, info) 144 pass 145 elif c == curses.KEY_BACKSPACE or c == 127: 146 self.current_input = self.current_input[:-1] 147 self.display_current_input_line() 148 elif c == curses.KEY_UP: 149 if self.state > 0: 150 self.current_input = self.inputs[self.state-1] 151 self.state = self.state - 1 152 if self.state == 0: 153 # turn off cursor 154 curses.curs_set(0) 155 self.display_current_input_line() 156 elif c == curses.KEY_DOWN: 157 pass 158 else: 159 self.current_input = self.current_input + chr(c) 160 self.display_current_input_line()
161