def componentCreate(self, componentState): """ Create the given component. This will currently also trigger a start eventually when the component avatar attaches. The component should be sleeping. The worker it should be started on should be present. """ m = componentState.get('mood') if m != moods.sleeping.value: raise errors.ComponentMoodError("%r not sleeping but %s" % ( componentState, moods.get(m).name)) p = componentState.get('moodPending') if p != None: raise errors.ComponentMoodError( "%r already has a pending mood %s" % ( componentState, moods.get(p).name)) # find a worker this component can start on workerId = (componentState.get('workerName') or componentState.get('workerRequested')) if not workerId in self.workerHeaven.avatars: raise errors.ComponentNoWorkerError( "worker %s is not logged in" % workerId) else: return self._workerCreateComponents(workerId, [componentState])
def _verifyComponentIdGone(self, id, expectedMood=None, expectedMoodPending=None): # verify logged out components mappers = self.vishnu._componentMappers m = mappers[id] avatar = self._components[id] self.failUnless(id in mappers.keys()) self.assertEqual(m.id, id) self.failIf(avatar in mappers.keys()) self.assertEqual(m.avatar, None) self.failUnless(m.state) state = m.state if expectedMood: # Only check this if we had an expected mood passed self.assertEqual( state.get("mood"), expectedMood.value, "%s: mood is %s instead of %s" % (id, moods.get(state.get("mood")), expectedMood), ) # always check moodPending moodPendingValue = state.get("moodPending") expectedValue = expectedMoodPending if expectedMoodPending is not None: expectedValue = expectedMoodPending.value self.assertEqual( moodPendingValue, expectedValue, "%s: moodPending is %r instead of %r" % (id, moodPendingValue is not None and moods.get(moodPendingValue) or "None", expectedMoodPending), ) # verify avatar state self.failIf(avatar.jobState) self.failIf(avatar.componentState)
def planet_callback(uistate, self=self): component = util.findComponent(uistate, '/default/producer-firewire') if self.volume_monitor is None: import volume_monitor parent_widget = self.xml.get_object(self.box) self.volume_monitor = volume_monitor.VolumeMonitor(self.flumotion.medium, component, force_channels=1) volume_widget = self.volume_monitor.widget old_parent = volume_widget.get_parent() if old_parent: old_parent.remove(volume_widget) parent_widget.pack_start(volume_widget) if moods.get(component.get('mood')) is not moods.happy: return def component_callback(firewire_uistate, self=self): if self.volume_monitor.state is not None: return self.volume_monitor.setUIState(firewire_uistate) self.assistant.set_page_complete(self.page, True) self.focus_forward() d = self.flumotion.medium.componentCallRemote(component, 'getUIState') d.addCallback(component_callback)
def get_available_commands(self, input): input_split = input.split() last_input = '' if len(input_split) > 0: last_input = input_split[len(input_split) - 1] available_commands = [] if len(input_split) <= 1 and not input.endswith(' '): # this decides whether startall, stopall and clearall are allowed can_stop = True can_start = True for x in self._components.values(): mood = moods.get(x.get('mood')) can_stop = can_stop and (mood != moods.lost and mood != moods.sleeping) can_start = can_start and (mood == moods.sleeping) can_clear = can_start and not can_stop for command in self.global_commands: command_ok = (command != 'startall' and command != 'stopall' and command != 'clearall') command_ok = command_ok or (command == 'startall' and can_start) command_ok = command_ok or (command == 'stopall' and can_stop) command_ok = command_ok or (command == 'clearall' and can_clear) if (command_ok and string.lower(command).startswith( string.lower(last_input))): available_commands.append(command) else: available_commands = (available_commands + self.get_available_commands_for_component( input_split[0], input)) return available_commands
def planet_callback(uistate, self=self): component = util.findComponent(uistate, '/default/producer-firewire') if self.volume_monitor is None: import volume_monitor parent_widget = self.xml.get_object(self.box) self.volume_monitor = volume_monitor.VolumeMonitor( self.flumotion.medium, component, force_channels=1) volume_widget = self.volume_monitor.widget old_parent = volume_widget.get_parent() if old_parent: old_parent.remove(volume_widget) parent_widget.pack_start(volume_widget) if moods.get(component.get('mood')) is not moods.happy: return def component_callback(firewire_uistate, self=self): if self.volume_monitor.state is not None: return self.volume_monitor.setUIState(firewire_uistate) self.assistant.set_page_complete(self.page, True) self.focus_forward() d = self.flumotion.medium.componentCallRemote( component, 'getUIState') d.addCallback(component_callback)
def _update_mood(self): """ This method goes through all the components to determine and set the overall mood. """ # get a dictionary of components names = self._components.keys() if names: # get overall mood of components overallmood = moods.happy.value for compName in names: component = self._components[compName] mood = component.get('mood') self.debug("component %s has mood %d" % (compName, mood)) if mood > overallmood: overallmood = mood moodname = moods.get(overallmood).name self.debug("overall mood: %s %d" % (moodname, overallmood)) filename = os.path.join(configure.imagedir, 'mood-%s.png' % moodname) self._set_icon_from_filename(filename) else: # if no components, show fluendo logo self._set_icon_from_filename(_DEFAULT_ICON)
def __repr__(self): mood = '(unknown)' if self.componentState: moodValue = self.componentState.get('mood') if moodValue is not None: mood = moods.get(moodValue).name return '<%s %s (mood %s)>' % (self.__class__.__name__, self.avatarId, mood)
def verifyMoodIsHappy(result): self.debug("Turned happy") self.assertEqual(state.get('mood'), moods.happy.value, "mood of %s is not happy but %r" % ( m.state.get('name'), moods.get(state.get('mood')))) # verify the component avatars self.failUnless(avatar.jobState) self.failUnless(avatar.componentState)
def verifyMoodIsHappy(result): self.debug("Turned happy") self.assertEqual( state.get('mood'), moods.happy.value, "mood of %s is not happy but %r" % (m.state.get('name'), moods.get(state.get('mood')))) # verify the component avatars self.failUnless(avatar.jobState) self.failUnless(avatar.componentState)
def _getMoodPixbufs(self): # load all pixbufs for the moods pixbufs = {} for i in range(0, len(moods)): name = moods.get(i).name pixbufs[i] = gtk.gdk.pixbuf_new_from_file_at_size( os.path.join(configure.imagedir, 'mood-%s.png' % name), 24, 24) return pixbufs
def _updateStartStop(self): oldstop = self.get_property('can-stop-any') oldstart = self.get_property('can-start-any') moodnames = [moods.get(x[COL_MOOD_VALUE]).name for x in self._model] canStop = bool([x for x in moodnames if (x != 'sleeping')]) canStart = bool([x for x in moodnames if (x == 'sleeping')]) if oldstop != canStop: self.set_property('can-stop-any', canStop) if oldstart != canStart: self.set_property('can-start-any', canStart)
def _updateStartStop(self): oldstop = self.get_property('can-stop-any') oldstart = self.get_property('can-start-any') moodnames = [moods.get(x[COL_MOOD_VALUE]).name for x in self._model] canStop = bool([x for x in moodnames if (x!='sleeping')]) canStart = bool([x for x in moodnames if (x=='sleeping')]) if oldstop != canStop: self.set_property('can-stop-any', canStop) if oldstart != canStart: self.set_property('can-start-any', canStart)
def gotPlanetStateCb(planetState, self=self, dead=self.dead): for f in planetState.get('flows') + [planetState.get('atmosphere')]: ds = [] for component in sorted(f.get('components'), cmp=lambda a, b: cmp(a.get('name'), b.get('name'))): name = component.get('name') if name == "justintv": continue mood = component.get('mood') if mood != moods.happy: print "%30s %10s (%i)" % ( name, moods.get(mood).name, mood) if moods.get(mood) in (moods.sad,): dead[name] = 5 + dead.get(name, 0) elif moods.get(mood) in (moods.hungry, moods.sleeping): dead[name] = 0.1 + dead.get(name, 0) elif moods.get(mood) not in (moods.happy, moods.waking): dead[name] = 1 + dead.get(name, 0) reactor.callLater(1, self._callback)
def _setMoodValue(self, titer, value): """ Set the mood value on the given component name. @type value: int """ self._model.set(titer, COL_MOOD, self._moodPixbufs[value]) self._model.set(titer, COL_MOOD_VALUE, value) mood = moods.get(value) self._model.set(titer, COL_TOOLTIP, _("<b>Component is %s</b>") % (MOODS_INFO[mood].lower(), )) self._updateStartStop()
def canStop(self): """ Get whether the selected components can be stoped. @rtype: bool """ states = self.getSelectedStates() if not states: return False canStop = True for state in states: moodname = moods.get(state.get('mood')).name canStop = canStop and moodname != 'sleeping' return canStop
def _setMoodValue(self, titer, value): """ Set the mood value on the given component name. @type value: int """ self._model.set(titer, COL_MOOD, self._moodPixbufs[value]) self._model.set(titer, COL_MOOD_VALUE, value) self._model.set(titer, COL_SAD, moods.sad.value == value) mood = moods.get(value) self._model.set(titer, COL_TOOLTIP, _("<b>Component is %s</b>") % (MOODS_INFO[mood].lower(), )) self._updateStartStop()
def _verifyComponentIdGone(self, id, expectedMood=None, expectedMoodPending=None): # verify logged out components mappers = self.vishnu._componentMappers m = mappers[id] avatar = self._components[id] self.failUnless(id in mappers.keys()) self.assertEqual(m.id, id) self.failIf(avatar in mappers.keys()) self.assertEqual(m.avatar, None) self.failUnless(m.state) state = m.state if expectedMood: # Only check this if we had an expected mood passed self.assertEqual( state.get('mood'), expectedMood.value, '%s: mood is %s instead of %s' % (id, moods.get(state.get('mood')), expectedMood)) # always check moodPending moodPendingValue = state.get('moodPending') expectedValue = expectedMoodPending if expectedMoodPending is not None: expectedValue = expectedMoodPending.value self.assertEqual(moodPendingValue, expectedValue, '%s: moodPending is %r instead of %r' % (id, moodPendingValue is not None \ and moods.get(moodPendingValue) or 'None', expectedMoodPending)) # verify avatar state self.failIf(avatar.jobState) self.failIf(avatar.componentState)
def emptyPlanet(self): """ Empty the planet of all components, and flows. Also clears all messages. @returns: a deferred that will fire when the planet is empty. """ for mid in self.state.get('messages').keys(): self.clearMessage(mid) # first get all components to sleep components = self.getComponentStates() # if any component is already in a mood change/command, fail components = [c for c in components if c.get('moodPending') != None] if components: state = components[0] raise errors.BusyComponentError( state, "moodPending is %s" % moods.get(state.get('moodPending'))) # filter out the ones that aren't sleeping and stop them components = [c for c in self.getComponentStates() if c.get('mood') is not moods.sleeping.value] # create a big deferred for stopping everything d = defer.Deferred() self.debug('need to stop %d components: %r' % ( len(components), components)) for c in components: avatar = self._componentMappers[c].avatar # If this has logged out, but isn't sleeping (so is sad or lost), # we won't have an avatar. So, stop if it we can. if avatar: d.addCallback(lambda result, a: a.stop(), avatar) else: assert (c.get('mood') is moods.sad.value or c.get('mood') is moods.lost.value) d.addCallback(self._emptyPlanetCallback) # trigger the deferred after returning reactor.callLater(0, d.callback, None) return d
def canStart(self): """ Get whether the selected components can be started. @rtype: bool """ states = self.getSelectedStates() if not states: return False canStart = True for state in states: moodname = moods.get(state.get('mood')).name workerName = state.get('workerRequested') canStart = (canStart and moodname == 'sleeping' and workerName in self._workers) return canStart
def canStop(self): """ Get whether the selected components can be stopped. Returns True if none of the components are sleeping. Also returns False if no components are selected. @rtype: bool """ states = self.getSelectedStates() if not states: return False canStop = True for state in states: moodname = moods.get(state.get('mood')).name canStop = canStop and moodname != 'sleeping' return canStop
def canDelete(self): """ Get whether the selected components can be deleted. Returns True if all components are sleeping. Also returns False if no components are selected. @rtype: bool """ states = self.getSelectedStates() if not states: return False canDelete = True for state in states: moodname = moods.get(state.get('mood')).name canDelete = canDelete and moodname == 'sleeping' return canDelete
def update(self, obj): cname = obj.get('name') new_mood = moods.get(obj.get('mood')).name self.__cobjs[cname] = obj with self.__lock: previous_state = self.__current.get(cname, ['unknown', 0]) if new_mood != previous_state[0]: # Move the previous state into the history history = self.age(cname) if cname not in self.__history: self.__history[cname] = [] if previous_state[0] != 'unknown': self.__history[cname].append( (previous_state[0], previous_state[-1], history)) # Update the mood self.__current[cname] = (new_mood, time.time())
def update(self, obj): cname = obj.get('name') new_mood = moods.get(obj.get('mood')).name self.__cobjs[cname] = obj with self.__lock: previous_state = self.__current.get(cname, ['unknown', 0]) if new_mood != previous_state[0]: # Move the previous state into the history history = self.age(cname) if cname not in self.__history: self.__history[cname] = [] if previous_state[0] != 'unknown': self.__history[cname].append(( previous_state[0], previous_state[-1], history)) # Update the mood self.__current[cname] = (new_mood, time.time())
def get_available_commands(self, input): input_split = input.split() last_input='' if len(input_split) >0: last_input = input_split[len(input_split)-1] available_commands = [] if len(input_split) <= 1 and not input.endswith(' '): # this decides whether startall, stopall and clearall are allowed can_stop = True can_start = True for x in self._components.values(): mood = moods.get(x.get('mood')) can_stop = can_stop and (mood != moods.lost and mood != moods.sleeping) can_start = can_start and (mood == moods.sleeping) can_clear = can_start and not can_stop for command in self.global_commands: command_ok = (command != 'startall' and command != 'stopall' and command != 'clearall') command_ok = command_ok or (command == 'startall' and can_start) command_ok = command_ok or (command == 'stopall' and can_stop) command_ok = command_ok or (command == 'clearall' and can_clear) if (command_ok and string.lower(command).startswith( string.lower(last_input))): available_commands.append(command) else: available_commands = (available_commands + self.get_available_commands_for_component( input_split[0], input)) return available_commands
def run_command(self, command): # this decides whether startall, stopall and clearall are allowed can_stop = True can_start = True for x in self._components.values(): mood = moods.get(x.get('mood')) can_stop = can_stop and (mood != moods.lost and mood != moods.sleeping) can_start = can_start and (mood == moods.sleeping) can_clear = can_start and not can_stop if string.lower(command) == 'quit': reactor.stop() elif string.lower(command) == 'startall': if can_start: for c in self._components.values(): self._component_start(c) self.command_result = 'Attempting to start all components' else: self.command_result = ( 'Components not all in state to be started') elif string.lower(command) == 'stopall': if can_stop: for c in self._components.values(): self._component_stop(c) self.command_result = 'Attempting to stop all components' else: self.command_result = ( 'Components not all in state to be stopped') elif string.lower(command) == 'clearall': if can_clear: self.admin.cleanComponents() self.command_result = 'Attempting to clear all components' else: self.command_result = ( 'Components not all in state to be cleared') else: command_split = command.split() # if at least 2 tokens in the command if len(command_split)>1: # check if the first is a component name for c in self._components.values(): if string.lower(c.get('name')) == ( string.lower(command_split[0])): # bingo, we have a component if string.lower(command_split[1]) == 'start': # start component self._component_start(c) elif string.lower(command_split[1]) == 'stop': # stop component self._component_stop(c) else: # component specific commands try: textui = self._comptextui[c.get('name')] if textui: d = textui.runCommand( ' '.join(command_split[1:])) self.debug( "textui runcommand defer: %r" % d) # add a callback d.addCallback(self._runCommand_cb) except KeyError: pass
def __componentMoodChanged(self, moodnum): mood = moods.get(moodnum) if mood != self._mood.getValue(): self._mood.setValue(mood) self.emit("mood-changed", mood)
def run_command(self, command): # this decides whether startall, stopall and clearall are allowed can_stop = True can_start = True for x in self._components.values(): mood = moods.get(x.get('mood')) can_stop = can_stop and (mood != moods.lost and mood != moods.sleeping) can_start = can_start and (mood == moods.sleeping) can_clear = can_start and not can_stop if string.lower(command) == 'quit': reactor.stop() elif string.lower(command) == 'startall': if can_start: for c in self._components.values(): self._component_start(c) self.command_result = 'Attempting to start all components' else: self.command_result = ( 'Components not all in state to be started') elif string.lower(command) == 'stopall': if can_stop: for c in self._components.values(): self._component_stop(c) self.command_result = 'Attempting to stop all components' else: self.command_result = ( 'Components not all in state to be stopped') elif string.lower(command) == 'clearall': if can_clear: self.admin.cleanComponents() self.command_result = 'Attempting to clear all components' else: self.command_result = ( 'Components not all in state to be cleared') else: command_split = command.split() # if at least 2 tokens in the command if len(command_split) > 1: # check if the first is a component name for c in self._components.values(): if string.lower(c.get('name')) == (string.lower( command_split[0])): # bingo, we have a component if string.lower(command_split[1]) == 'start': # start component self._component_start(c) elif string.lower(command_split[1]) == 'stop': # stop component self._component_stop(c) else: # component specific commands try: textui = self._comptextui[c.get('name')] if textui: d = textui.runCommand(' '.join( command_split[1:])) self.debug("textui runcommand defer: %r" % d) # add a callback d.addCallback(self._runCommand_cb) except KeyError: pass
def stopUnknown(): msg = ('asked to stop a component without avatar in mood %s' % moods.get(mood)) self.warning(msg) return defer.fail(errors.ComponentMoodError(msg))
def check_happy(_): self.debug('Checking for happiness') for c in flow: self.assertEquals(moods.get(c.comp.getMood()), moods.happy) return _