Package flumotion :: Package component :: Package base :: Module componentnode
[hide private]

Source Code for Module flumotion.component.base.componentnode

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_feedcomponent010 -*- 
  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  """ 
 23  Component tab in the component UI 
 24  """ 
 25   
 26  import gettext 
 27  import os 
 28  import time 
 29    
 30  import gtk 
 31   
 32  from flumotion.common.format import formatStorage, formatTime 
 33  from flumotion.common.i18n import gettexter 
 34  from flumotion.component.base.baseadminnode import BaseAdminGtkNode 
 35  from flumotion.extern.log.log import getDebug 
 36  from flumotion.common.planet import AdminFlowState 
 37   
 38   
 39  _ = gettext.gettext 
 40  __version__ = "$Rev: 6860 $" 
 41  T_ = gettexter() 
 42   
 43   
 44   
45 -class ComponentAdminGtkNode(BaseAdminGtkNode):
46 gladeFile = os.path.join('flumotion', 'component', 'base', 47 'component.glade') 48
49 - def __init__(self, state, admin):
50 BaseAdminGtkNode.__init__(self, state, admin, title=_("Component")) 51 52 self._startTime = None 53 self._debugging = None 54 self._initialFluMask = '' 55 self._initialGstMask = ''
56
57 - def setDebugEnabled(self, enabled):
58 BaseAdminGtkNode.setDebugEnabled(self, enabled) 59 if self._debugging: 60 self._debugging.set_property('visible', enabled) 61 62 self._initialFluMask = getDebug() 63 self._initialGstMask = os.environ.get('GST_DEBUG', '')
64
65 - def haveWidgetTree(self):
66 self.widget = self.wtree.get_widget('main-vbox') 67 assert self.widget, "No component-widget in %s" % self.gladeFile 68 self.gst_mask = self.wtree.get_widget('gst_mask') 69 self.gst_mask.connect('changed', self._on_gst_mask_changed) 70 self.gst_label = self.wtree.get_widget('gst_label') 71 self.flu_mask = self.wtree.get_widget('flu_mask') 72 self.flu_mask.connect('changed', self._on_flu_mask_changed) 73 self.gst_profile = self.wtree.get_widget('gst_profile') 74 self.gst_profile.connect('changed', self._on_gst_profile_changed) 75 self.flu_profile = self.wtree.get_widget('flu_profile') 76 self.flu_profile.connect('changed', self._on_flu_profile_changed) 77 78 # pid 79 l = self.wtree.get_widget('label-pid') 80 pid = self.state.get('pid') 81 l.set_text(str(pid)) 82 83 # Find the labels which we'll update when we get uiState updates. 84 self._label_start_time = self.wtree.get_widget('label-since') 85 self._label_uptime = self.wtree.get_widget('label-uptime') 86 self._label_cpu = self.wtree.get_widget('label-cpu') 87 self._label_vsize = self.wtree.get_widget('label-vsize') 88 self._label_component_type = self.wtree.get_widget( 89 'label-component-type') 90 91 self.widget.show() 92 93 self._prepareDebugging() 94 95 self._debugging = self.wtree.get_widget('debugging') 96 if self._debugEnabled: 97 self._debugging.show() 98 99 componentType = self.state.get('config')['type'] 100 self._label_component_type.set_text(componentType) 101 102 return self.widget
103
104 - def _validateMask(self, mask):
105 if ':' not in mask or mask.count(':') != 1: 106 return False 107 name, level = mask.split(':', 1) 108 try: 109 int(level) 110 except ValueError: 111 return False 112 return True
113
114 - def _on_gst_profile_changed(self, combo):
115 profile = combo.get_selected() 116 if profile is not None: 117 gtk.Entry.set_text(self.gst_mask, profile) 118 self.gst_mask.set_sensitive(profile is None)
119
120 - def _on_flu_profile_changed(self, combo):
121 profile = combo.get_selected() 122 if profile is not None: 123 gtk.Entry.set_text(self.flu_mask, profile) 124 self.flu_mask.set_sensitive(profile is None)
125
126 - def _on_flu_mask_changed(self, entry):
127 debug = entry.get_text() 128 if not self._debugEnabled or not self._validateMask(debug): 129 return 130 self.info('setting flu debug to %s for %s' % ( 131 debug, self.state.get('name'))) 132 self.admin.componentCallRemote(self.state, 'setFluDebug', debug)
133
134 - def _on_gst_mask_changed(self, entry):
135 debug = entry.get_text() 136 if not self._debugEnabled or not self._validateMask(debug): 137 return 138 self.info('setting gst debug to %s for %s' % ( 139 debug, self.state.get('name'))) 140 self.admin.componentCallRemote(self.state, 'setGstDebug', debug)
141
142 - def _prepareDebugging(self):
143 debugEnabled = self._debugEnabled 144 self._debugEnabled = False 145 default = [(_('Nothing'), '*:0'), 146 (_('Everything'), '*:4'), 147 (_('Custom'), None)] 148 self.flu_profile.prefill(default) 149 150 if isinstance(self.state.get('parent'), AdminFlowState): 151 self.gst_profile.prefill(default) 152 else: 153 self.gst_profile.hide() 154 self.gst_label.hide() 155 self.gst_mask.hide() 156 157 self._debugEnabled = debugEnabled
158
159 - def _setStartTime(self, value):
160 self._label_start_time.set_text( 161 time.strftime("%c", time.localtime(value))) 162 self._label_uptime.set_text(formatTime(0)) 163 164 self._startTime = value
165
166 - def _setCurrentTime(self, value):
167 if self._startTime is not None: 168 runtime = value - self._startTime 169 170 self._label_uptime.set_text(formatTime(runtime)) 171 else: 172 self._label_uptime.set_text(_("not available"))
173
174 - def _updateCPU(self, cpu):
175 # given float for cpu, update the label 176 self._label_cpu.set_text('%.2f %%' % (cpu * 100.0))
177
178 - def _updateVSize(self, vsize):
179 # given int for vsize in bytes, update the label 180 if not vsize: 181 self._label_vsize.set_text(_('Unknown')) 182 else: 183 self._label_vsize.set_text('%sB' % formatStorage(vsize))
184
185 - def setUIState(self, uiState):
186 BaseAdminGtkNode.setUIState(self, uiState) 187 188 # Ick; we don't get these otherwise. 189 for key in uiState.keys(): 190 val = uiState.get(key) 191 if val is not None: 192 self.stateSet(uiState, key, uiState.get(key))
193 194 # IStateListener Interface
195 - def stateSet(self, object, key, value):
196 if key == 'cpu-percent': 197 self._updateCPU(value) 198 elif key == 'virtual-size': 199 self._updateVSize(value) 200 if key == 'start-time': 201 self._setStartTime(value) 202 elif key == 'current-time': 203 self._setCurrentTime(value)
204
205 - def stateAppend(self, object, key, value):
206 pass
207
208 - def stateRemove(self, object, key, value):
209 pass
210