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

Source Code for Module flumotion.component.base.feedersnode

  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  Feeders tab in the component UI 
 24  """ 
 25  import gettext 
 26  import os 
 27  import time 
 28    
 29  import gtk 
 30   
 31  from flumotion.common import common 
 32  from flumotion.common.format import formatStorage, formatTime, formatTimeStamp 
 33  from flumotion.common.i18n import gettexter 
 34  from flumotion.component.base.baseadminnode import BaseAdminGtkNode 
 35  from flumotion.component.base.statewatcher import StateWatcher 
 36   
 37  _ = gettext.gettext 
 38  __version__ = "$Rev: 7089 $" 
 39  T_ = gettexter() 
 40   
 41   
42 -class FeedersAdminGtkNode(BaseAdminGtkNode):
43 gladeFile = os.path.join('flumotion', 'component', 'base', 'feeders.glade') 44
45 - def __init__(self, state, admin):
46 BaseAdminGtkNode.__init__(self, state, admin, title=_("Feeders")) 47 # tree model is a model of id, uiState, StateWatcher, type 48 # tree model contains feeders and their feeder clients 49 # type is a str, 'feeder' or 'client' 50 self.treemodel = None 51 self.treeview = None 52 self.selected = None 53 self.labels = {} 54 self._lastConnect = 0 55 self._lastDisconnect = 0
56
57 - def select(self, watcher):
58 if self.selected: 59 self.selected.hide() 60 if watcher: 61 self.selected = watcher 62 self.selected.show() 63 else: 64 self.selected = None
65
66 - def setFeederName(self, state, value):
67 self.labels['feeder-name'].set_markup(_('Feeder <b>%s</b>') % value)
68
69 - def _mungeClientId(self, clientId):
70 try: 71 flowName, compName, feedName = common.parseFullFeedId(clientId) 72 return common.feedId(compName, feedName) 73 except: 74 return clientId
75
76 - def setFeederClientName(self, state, value):
77 if not value: 78 self.labels['eater-name'].set_markup(_('<i>select an eater</i>')) 79 return 80 value = self._mungeClientId(value) 81 self.labels['eater-name'].set_markup(_('<b>%s</b>') 82 % (value,))
83
84 - def setFeederClientBytesReadCurrent(self, state, value):
85 txt = value and (formatStorage(value) + _('Byte')) or '' 86 self.labels['bytes-read-current'].set_text(txt) 87 self.updateConnectionTime() 88 self.updateDisconnectionTime()
89
90 - def setFeederClientBuffersDroppedCurrent(self, state, value):
91 if value is None: 92 # no support for counting dropped buffers 93 value = _("Unknown") 94 self.labels['buffers-dropped-current'].set_text(str(value)) 95 self.updateConnectionTime() 96 self.updateDisconnectionTime()
97
98 - def setFeederClientBytesReadTotal(self, state, value):
99 txt = value and (formatStorage(value) + _('Byte')) or '' 100 self.labels['bytes-read-total'].set_text(txt)
101
102 - def setFeederClientBuffersDroppedTotal(self, state, value):
103 if value is None: 104 # no support for counting dropped buffers 105 value = _("Unknown") 106 self.labels['buffers-dropped-total'].set_text(str(value))
107
108 - def setFeederClientReconnects(self, state, value):
109 self.labels['connections-total'].set_text(str(value))
110
111 - def setFeederClientLastConnect(self, state, value):
112 if value: 113 text = formatTimeStamp(time.localtime(value)) 114 self.labels['connected-since'].set_text(text) 115 self._lastConnect = value 116 self.updateConnectionTime()
117
118 - def setFeederClientLastDisconnect(self, state, value):
119 if value: 120 text = formatTimeStamp(time.localtime(value)) 121 self.labels['disconnected-since'].set_text(text) 122 self._lastDisconnect = value 123 self.updateDisconnectionTime()
124
125 - def setFeederClientLastActivity(self, state, value):
126 if value: 127 text = formatTimeStamp(time.localtime(value)) 128 self.labels['last-activity'].set_text(text)
129
130 - def setFeederClientFD(self, state, value):
131 if value == None: 132 # disconnected 133 self._table_connected.hide() 134 self._table_disconnected.show() 135 else: 136 self._table_disconnected.hide() 137 self._table_connected.show()
138 139 # FIXME: add a timeout to update this ?
140 - def updateConnectionTime(self):
141 if self._lastConnect: 142 text = formatTime(time.time() - self._lastConnect) 143 self.labels['connection-time'].set_text(text)
144 145 # FIXME: add a timeout to update this ?
146 - def updateDisconnectionTime(self):
147 if self._lastDisconnect: 148 text = formatTime(time.time() - self._lastDisconnect) 149 self.labels['disconnection-time'].set_text(text)
150
151 - def addFeeder(self, uiState, state):
152 """ 153 @param uiState: the component's uiState 154 @param state: the feeder's uiState 155 """ 156 feederName = state.get('feederName') 157 i = self.treemodel.append(None) 158 self.treemodel.set(i, 0, feederName, 1, state) 159 w = StateWatcher(state, 160 {'feederName': self.setFeederName}, 161 {'clients': self.addFeederClient}, 162 {'clients': self.removeFeederClient}) 163 self.treemodel.set(i, 2, w, 3, 'feeder') 164 self.treeview.expand_all()
165 166 # FIXME: this docstring is confusing
167 - def addFeederClient(self, feederState, state):
168 """ 169 @param feederState: the component's uiState 170 @param state: the feeder client's uiState 171 """ 172 173 printableClientId = self._mungeClientId(state.get('client-id')) 174 for row in self.treemodel: 175 if self.treemodel.get_value(row.iter, 1) == feederState: 176 break 177 i = self.treemodel.append(row.iter) 178 self.treemodel.set(i, 0, printableClientId, 1, state) 179 w = StateWatcher(state, { 180 'client-id': self.setFeederClientName, 181 'bytes-read-current': self.setFeederClientBytesReadCurrent, 182 'buffers-dropped-current': self.setFeederClientBuffersDroppedCurrent, 183 'bytes-read-total': self.setFeederClientBytesReadTotal, 184 'buffers-dropped-total': self.setFeederClientBuffersDroppedTotal, 185 'reconnects': self.setFeederClientReconnects, 186 'last-connect': self.setFeederClientLastConnect, 187 'last-disconnect': self.setFeederClientLastDisconnect, 188 'last-activity': self.setFeederClientLastActivity, 189 'fd': self.setFeederClientFD, 190 }, {}, {}) 191 self.treemodel.set(i, 2, w, 3, 'client') 192 self.treeview.expand_all()
193
194 - def removeFeederClient(self, feederState, state):
195 for row in self.treemodel: 196 if self.treemodel.get_value(row.iter, 1) == feederState: 197 break 198 for row in row.iterchildren(): 199 if self.treemodel.get_value(row.iter, 1) == state: 200 break 201 state, watcher = self.treemodel.get(row.iter, 1, 2) 202 if watcher == self.selected: 203 self.select(None) 204 watcher.unwatch() 205 self.treemodel.remove(row.iter)
206
207 - def setUIState(self, state):
208 # will only be called when we have a widget tree 209 BaseAdminGtkNode.setUIState(self, state) 210 self.widget.show_all() 211 for feeder in state.get('feeders'): 212 self.addFeeder(state, feeder) 213 sel = self.treeview.get_selection() 214 if sel is not None: 215 sel.select_iter(self.treemodel.get_iter_first())
216
217 - def haveWidgetTree(self):
218 self.labels = {} 219 self.widget = self.wtree.get_widget('feeders-widget') 220 self.treeview = self.wtree.get_widget('treeview-feeders') 221 self.treemodel = gtk.TreeStore(str, object, object, str) 222 self.treeview.set_model(self.treemodel) 223 col = gtk.TreeViewColumn('Feeder', gtk.CellRendererText(), 224 text=0) 225 self.treeview.append_column(col) 226 sel = self.treeview.get_selection() 227 sel.set_mode(gtk.SELECTION_SINGLE) 228 def sel_changed(sel): 229 model, i = sel.get_selected() 230 self.select(i and model.get_value(i, 2)) 231 # don't show the feeder client stuff for a feeder 232 if model.get_value(i, 3) == 'feeder': 233 self.setFeederClientName(model.get_value(i, 1), None) 234 self._table_feedclient.hide() 235 else: 236 parent = model.get_value(model.iter_parent(i), 1) 237 self.setFeederName(parent, parent.get('feederName')) 238 self._table_feedclient.show()
239 240 sel.connect('changed', sel_changed) 241 242 def set_label(name): 243 self.labels[name] = self.wtree.get_widget('label-' + name) 244 # zeroes out all value labels 245 self.labels[name].set_text('')
246 247 for name in ('feeder-name', 'eater-name', 248 'bytes-read-current', 'buffers-dropped-current', 249 'connected-since', 'connection-time', 250 'disconnected-since', 'disconnection-time', 251 'bytes-read-total', 'buffers-dropped-total', 252 'connections-total', 'last-activity'): 253 set_label(name) 254 255 self._table_connected = self.wtree.get_widget('table-current-connected') 256 self._table_disconnected = self.wtree.get_widget( 257 'table-current-disconnected') 258 self._table_feedclient = self.wtree.get_widget('table-feedclient') 259 self._table_connected.hide() 260 self._table_disconnected.hide() 261 self._table_feedclient.hide() 262 self.wtree.get_widget('box-right').hide() 263 264 return self.widget 265