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

Source Code for Module flumotion.admin.gtk.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 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  """flumotion-admin entry point, command line parsing and invokation""" 
 23   
 24  import gettext 
 25  import sys 
 26   
 27  from twisted.internet import reactor 
 28  from twisted.python import log as twistedlog 
 29   
 30  from flumotion.admin.connections import parsePBConnectionInfoRecent 
 31  from flumotion.common import log, i18n 
 32  from flumotion.common.errors import  OptionError, ConnectionRefusedError,\ 
 33          ConnectionFailedError 
 34  from flumotion.common.options import OptionParser 
 35   
 36  __version__ = "$Rev: 7984 $" 
 37  _ = gettext.gettext 
 38  _retval = 0 
 39   
 40   
41 -def showGreeter(adminWindow):
42 from flumotion.admin.gtk.greeter import Greeter 43 greeter = Greeter(adminWindow) 44 d = greeter.runAsync() 45 return d
46 47
48 -def _connectToManager(win, manager, ssl):
49 try: 50 info = parsePBConnectionInfoRecent(manager, use_ssl=ssl) 51 except OptionError, e: 52 raise SystemExit("ERROR: %s" % (e, )) 53 54 def errback(failure): 55 global _retval 56 print >> sys.stderr, "ERROR: %s" % (failure.value, ) 57 _retval = 1 58 reactor.stop()
59 60 def errorDialogShown(unused): 61 return showGreeter(win) 62 63 def connectionFailed(failure): 64 failure.trap(ConnectionRefusedError, ConnectionFailedError) 65 from flumotion.admin.gtk.dialogs import showConnectionErrorDialog 66 d = showConnectionErrorDialog(failure, info) 67 d.addCallback(errorDialogShown) 68 return d 69 70 d = win.openConnection(info) 71 d.addErrback(connectionFailed) 72 d.addErrback(errback) 73 return d 74 75
76 -def main(args):
77 global _retval 78 79 parser = OptionParser(domain="flumotion-admin") 80 parser.add_option('-m', '--manager', 81 action="store", type="string", dest="manager", 82 help="the manager to connect to, e.g. localhost:7531") 83 parser.add_option('', '--no-ssl', 84 action="store_false", dest="ssl", default=True, 85 help="disable encryption when connecting to the manager") 86 87 options, args = parser.parse_args(args) 88 89 i18n.installGettext() 90 91 if len(args) > 1: 92 log.error('flumotion-admin', 93 'too many arguments: %r' % (args[1:], )) 94 return 1 95 96 from flumotion.ui.icons import register_icons 97 register_icons() 98 99 from flumotion.admin.gtk.dialogs import exceptionHandler 100 sys.excepthook = exceptionHandler 101 102 from flumotion.admin.gtk.adminwindow import AdminWindow 103 win = AdminWindow() 104 105 if options.verbose or (options.debug and options.debug > 3): 106 win.setDebugEnabled(True) 107 108 if options.manager: 109 d = _connectToManager(win, options.manager, options.ssl) 110 else: 111 d = showGreeter(win) 112 113 # Printout unhandled exception to stderr 114 d.addErrback(twistedlog.err) 115 116 # Fixes a bug on widnows version of twisted that makes 117 # the application to crash because _simtag is not defined. 118 if not hasattr(reactor, '_simtag'): 119 reactor._simtag = None 120 121 reactor.run() 122 return _retval
123