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

Source Code for Module flumotion.admin.text.connection

 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  """connecting to a manager interface""" 
19   
20  import curses 
21   
22  from flumotion.admin.admin import AdminModel 
23  from flumotion.admin.text.view import AdminTextView 
24  from flumotion.common import errors 
25   
26  from twisted.internet import reactor 
27   
28  __version__ = "$Rev$" 
29   
30   
31 -def connect_to_manager(stdscr, info):
32 stdscr.addstr( 33 0, 0, "Connecting to %s" % info) 34 stdscr.clrtobot() 35 stdscr.refresh() 36 37 model = AdminModel() 38 d = model.connectToManager(info) 39 40 def outputError(str): 41 print str
42 43 def connected(model): 44 stdscr.addstr(0, 0, "Connected") 45 stdscr.clrtobot() 46 stdscr.refresh() 47 48 try: 49 view = AdminTextView(model, stdscr) 50 reactor.addReader(view) 51 view.show() 52 except Exception: 53 # Set everything back to normal 54 stdscr.keypad(0) 55 curses.echo() 56 curses.nocbreak() 57 curses.endwin() 58 # And print the the traceback 59 import traceback 60 traceback.print_exc() 61 62 def refused(failure): 63 failure.trap(errors.ConnectionRefusedError) 64 #stdscr.addstr(0,0,"Connection refused") 65 #stdscr.clrtobot() 66 #stdscr.refresh() 67 reactor.addSystemEventTrigger('after', 'shutdown', 68 outputError, "Connection Refused") 69 reactor.callLater(0, reactor.stop) 70 71 def failed(failure): 72 failure.trap(errors.ConnectionFailedError) 73 message = "".join(failure.value.args) 74 #stdscr.addstr(0,0,"Connection failed: %s" % message) 75 #stdscr.clrtobot() 76 #stdscr.refresh() 77 reactor.addSystemEventTrigger( 78 'after', 79 'shutdown', 80 outputError, "Connection Failed: %s" % message) 81 reactor.callLater(0, reactor.stop) 82 83 84 d.addCallback(connected) 85 d.addErrback(refused) 86 d.addErrback(failed) 87