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