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 ConnectionRefusedError, OptionError 
 33  from flumotion.common.options import OptionParser 
 34   
 35  __version__ = "$Rev: 7082 $" 
 36  _ = gettext.gettext 
 37  _retval = 0 
 38   
39 -def _connectToManager(win, manager, ssl):
40 try: 41 info = parsePBConnectionInfoRecent(manager, use_ssl=ssl) 42 except OptionError, e: 43 raise SystemExit("ERROR: %s" % (e,)) 44 45 d = win.openConnection(info) 46 def errbackConnectionRefused(failure): 47 global _retval 48 failure.trap(ConnectionRefusedError) 49 print >> sys.stderr, _( 50 "ERROR: Could not connect to manager:\n" 51 " The connection to %r was refused.") % ( 52 manager,) 53 _retval = 1 54 reactor.stop()
55 56 def errback(failure): 57 global _retval 58 print >> sys.stderr, "ERROR: %s" % (failure.value,) 59 _retval = 1 60 reactor.stop() 61 d.addErrback(errbackConnectionRefused) 62 d.addErrback(errback) 63 return d 64
65 -def _exceptionHandler(exctype, value, tb):
66 if exctype is KeyboardInterrupt: 67 return 68 69 from flumotion.extern.exceptiondialog import ExceptionDialog 70 dialog = ExceptionDialog((exctype, value, tb)) 71 response = dialog.run() 72 if response != ExceptionDialog.RESPONSE_BUG: 73 dialog.destroy() 74 return 75 76 from flumotion.common.bugreporter import BugReporter 77 br = BugReporter() 78 br.submit(dialog.getFilenames(), 79 dialog.getDescription(), 80 dialog.getSummary()) 81 dialog.destroy()
82
83 -def main(args):
84 global _retval 85 86 parser = OptionParser(domain="flumotion-admin") 87 parser.add_option('-m', '--manager', 88 action="store", type="string", dest="manager", 89 help="the manager to connect to, e.g. localhost:7531") 90 parser.add_option('', '--no-ssl', 91 action="store_false", dest="ssl", default=True, 92 help="disable encryption when connecting to the manager") 93 94 options, args = parser.parse_args(args) 95 96 i18n.installGettext() 97 98 if len(args) > 1: 99 log.error('flumotion-admin', 100 'too many arguments: %r' % (args[1:],)) 101 return 1 102 103 from flumotion.ui.icons import register_icons 104 register_icons() 105 106 sys.excepthook = _exceptionHandler 107 108 from flumotion.admin.gtk.adminwindow import AdminWindow 109 win = AdminWindow() 110 111 if options.verbose or (options.debug and options.debug > 3): 112 win.setDebugEnabled(True) 113 114 if options.manager: 115 d = _connectToManager(win, options.manager, options.ssl) 116 else: 117 from flumotion.admin.gtk.greeter import Greeter 118 greeter = Greeter(win) 119 d = greeter.runAsync() 120 121 # Printout unhandled exception to stderr 122 d.addErrback(twistedlog.err) 123 124 reactor.run() 125 return _retval
126