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 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  import optparse 
 23  import os 
 24  import sys 
 25   
 26  import gettext 
 27  import gtk.glade 
 28   
 29  from twisted.internet import reactor, defer 
 30  from flumotion.admin import connections 
 31  from flumotion.admin.admin import AdminModel 
 32  from flumotion.admin.gtk import dialogs 
 33  from flumotion.admin.gtk.client import Window 
 34  from flumotion.common import log, errors 
 35  from flumotion.configure import configure 
 36  from flumotion.twisted import pb as fpb 
 37   
38 -def Greeter():
39 # We do the import here so gettext has been set up and class strings 40 # from greeter are translated 41 from flumotion.admin.gtk import greeter 42 return greeter.Greeter()
43
44 -def startAdminFromGreeter(greeter):
45 def got_state(state): 46 greeter.set_sensitive(False) 47 authenticator = fpb.Authenticator(username=state['user'], 48 password=state['passwd']) 49 model = AdminModel(authenticator) 50 return model.connectToHost(state['host'], state['port'], 51 state['use_insecure'])
52 53 def refused(failure): 54 failure.trap(errors.ConnectionRefusedError) 55 dret = dialogs.connection_refused_message(state['host'], 56 greeter.window) 57 dret.addCallback(lambda _: startAdminFromGreeter(greeter)) 58 return dret 59 60 def failed(failure): 61 failure.trap(errors.ConnectionFailedError) 62 message = "".join(failure.value.args) 63 dret = dialogs.connection_failed_message(message, greeter.window) 64 dret.addCallback(lambda _: startAdminFromGreeter(greeter)) 65 return dret 66 67 def connected(model): 68 greeter.destroy() 69 return model 70 71 d = greeter.run_async() 72 d.addCallback(got_state) 73 d.addCallback(connected) 74 d.addErrback(refused) 75 d.addErrback(failed) 76 return d 77
78 -def startAdminFromManagerString(managerString, useSSL):
79 info = connections.parsePBConnectionInfo(managerString, useSSL) 80 model = AdminModel(info.authenticator) 81 d = model.connectToHost(info.host, info.port, not info.use_ssl) 82 return d
83
84 -def main(args):
85 parser = optparse.OptionParser() 86 parser.add_option('-d', '--debug', 87 action="store", type="string", dest="debug", 88 help="set debug levels") 89 parser.add_option('-v', '--verbose', 90 action="store_true", dest="verbose", 91 help="be verbose") 92 parser.add_option('', '--version', 93 action="store_true", dest="version", 94 default=False, 95 help="show version information") 96 parser.add_option('-m', '--manager', 97 action="store", type="string", dest="manager", 98 help="the manager to connect to, e.g. localhost:7531") 99 parser.add_option('', '--no-ssl', 100 action="store_true", dest="no_ssl", 101 help="disable encryption when connecting to the manager") 102 103 options, args = parser.parse_args(args) 104 105 if options.version: 106 from flumotion.common import common 107 print common.version("flumotion-admin") 108 return 0 109 110 if options.verbose: 111 log.setFluDebug("*:3") 112 113 if options.debug: 114 log.setFluDebug(options.debug) 115 116 # set up gettext 117 localedir = os.path.join(configure.localedatadir, 'locale') 118 log.debug("locale", "Loading locales from %s" % localedir) 119 gettext.bindtextdomain('flumotion', localedir) 120 gettext.textdomain('flumotion') 121 gtk.glade.bindtextdomain('flumotion', localedir) 122 gtk.glade.textdomain('flumotion') 123 124 if len(args) > 1: 125 log.error('flumotion-admin', 126 'too many argument: %r' % (args[1:],)) 127 128 if options.manager: 129 d = startAdminFromManagerString(options.manager, 130 not options.no_ssl) 131 else: 132 d = startAdminFromGreeter(Greeter()) 133 134 def failure(failure): 135 message = "".join(failure.value.args) 136 log.warning('admin', "Failed to connect: %s", 137 log.getFailureMessage(failure)) 138 sys.stderr.write("Connection to manager failed: %s\n" % message) 139 reactor.stop()
140 141 d.addCallbacks(lambda model: Window(model).show(), failure) 142 143 reactor.run() 144