Package flumotion :: Package component :: Package plugs :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.plugs.wizard_gtk

  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  """Wizard plugin for the cortado http plug 
 19  """ 
 20   
 21  from zope.interface import implements 
 22   
 23  import gtk 
 24  import os 
 25   
 26  from flumotion.admin.assistant.interfaces import IHTTPServerPlugin 
 27  from flumotion.admin.assistant.models import Plug 
 28  from flumotion.common import messages 
 29  from flumotion.common.i18n import N_, gettexter 
 30  from flumotion.ui.fileselector import FileSelectorDialog 
 31  from flumotion.ui.plugarea import WizardPlugLine 
 32   
 33  __version__ = "$Rev$" 
 34  T_ = gettexter() 
 35   
 36   
37 -class RequestLoggerPlug(Plug):
38 """I am a model representing the configuration file for a 39 Request Logger plug. 40 """ 41 plugType = "requestlogger-file" 42
43 - def __init__(self, component):
44 Plug.__init__(self) 45 self.component = component 46 self.properties.logfile = '/tmp/access.log'
47
48 - def setActive(self, active):
49 if active: 50 self.component.addPlug(self) 51 else: 52 self.component.delPlug(self)
53 54
55 -class RequestLoggerPlugLine(WizardPlugLine):
56 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 57 'wizard.glade') 58 toplevel_name = 'requestlogger-window' 59
60 - def __init__(self, wizard, model, description):
61 WizardPlugLine.__init__(self, wizard, model, description) 62 63 self.logfile.data_type = str 64 self._proxy = self.add_proxy(self.model.properties, ['logfile']) 65 66 if self.getActive(): 67 self.model.setActive(True) 68 else: 69 self.plugActiveChanged(False)
70 71 # WizardPlugLine 72
73 - def plugActiveChanged(self, active):
74 self.logfile.set_sensitive(active) 75 self.select_logfile.set_sensitive(active) 76 self.model.setActive(active)
77 78 # Callbacks 79
80 - def on_select_logfile_clicked(self, button):
81 82 def response(fs, response): 83 fs.hide() 84 if response == gtk.RESPONSE_OK: 85 filename = os.path.join(fs.getFilename(), 'access.log') 86 self.model.properties.logfile = filename 87 self._proxy.update('logfile')
88 89 fs = FileSelectorDialog(self.wizard.window, 90 self.wizard.getAdminModel()) 91 92 fs.connect('response', response) 93 fs.selector.setOnlyDirectoriesMode(True) 94 fs.selector.setWorkerName(self.model.component.worker) 95 directory = os.path.dirname(self.model.properties.logfile) 96 fs.setDirectory(directory) 97 fs.show_all()
98
99 - def on_logfile_changed(self, button):
100 self._runChecks()
101
102 - def _runChecks(self):
103 self.wizard.waitForTask('ondemand check') 104 105 worker = self.model.component.worker 106 directory = os.path.dirname(self.logfile.get_text()) 107 108 def importError(failure): 109 failure.trap(ImportError) 110 self.info('could not import twisted-web') 111 message = messages.Warning(T_(N_( 112 "Worker '%s' cannot import module '%s'."), 113 worker, 'twisted.web')) 114 message.add(T_(N_("\nThis module is part of the '%s'."), 115 'Twisted Project')) 116 message.add(T_(N_("\nThe project's homepage is %s"), 117 'http://www.twistedmatrix.com/')) 118 message.id = 'module-twisted-web' 119 self.wizard.add_msg(message) 120 self.wizard.taskFinished(True) 121 return False
122 123 def checkPathFinished(pathExists): 124 if not pathExists: 125 message = messages.Warning(T_(N_( 126 "Directory '%s' does not exist, " 127 "or is not readable on worker '%s'.") 128 % (directory, worker))) 129 message.id = 'log-path-check' 130 self.wizard.add_msg(message) 131 self.wizard.taskFinished(True) 132 return False 133 else: 134 self.wizard.clear_msg('log-path-check') 135 self.wizard.taskFinished(False) 136 return True 137 138 self.wizard.taskFinished() 139 140 def checkPath(unused): 141 d = self.wizard.runInWorker( 142 worker, 'flumotion.worker.checks.check', 143 'checkDirectory', directory) 144 d.addCallback(checkPathFinished) 145 return d 146 147 d = self.wizard.checkImport(worker, 'twisted.web') 148 d.addCallback(checkPath) 149 d.addErrback(importError) 150 return d 151 152
153 -class RequestLoggerPlugWizardPlugin(object):
154 implements(IHTTPServerPlugin) 155
156 - def __init__(self, wizard, component):
157 self.wizard = wizard 158 self.model = RequestLoggerPlug(component)
159
160 - def workerChanged(self, worker):
161 pass
162
163 - def getPlugWizard(self, description):
164 return RequestLoggerPlugLine(self.wizard, self.model, description)
165 166
167 -class RequestModifierForceDownloadPlug(Plug):
168 """I am a model representing the configuration file for the 169 Force download plug. 170 """ 171 plugType = "requestmodifier-forcedownload" 172
173 - def __init__(self, component):
174 Plug.__init__(self) 175 self.component = component 176 self.properties.argument_name = 'force' 177 self.properties.trigger_value = 'true'
178
179 - def setActive(self, active):
180 if active: 181 self.component.addPlug(self) 182 else: 183 self.component.delPlug(self)
184 185
186 -class RequestModifierForceDownloadPlugLine(WizardPlugLine):
187
188 - def __init__(self, wizard, model, description):
189 WizardPlugLine.__init__(self, wizard, model, description) 190 191 if self.getActive(): 192 self.model.setActive(True)
193 194 # WizardPlugLine 195
196 - def plugActiveChanged(self, active):
197 self.model.setActive(active)
198 199
200 -class RequestModifierForceDownloadPlugWizardPlugin(object):
201 implements(IHTTPServerPlugin) 202
203 - def __init__(self, wizard, component):
204 self.wizard = wizard 205 self.model = RequestModifierForceDownloadPlug(component)
206
207 - def workerChanged(self, worker):
208 pass
209
210 - def getPlugWizard(self, description):
211 return RequestModifierForceDownloadPlugLine(self.wizard, self.model, 212 description)
213