Ejemplo n.º 1
0
 def gotModule(mod):
     if hasattr(mod, function):
         return getattr(mod, function)
     else:
         msg = 'No procedure named %s in module %s' % (function, module)
         self.warning('%s', msg)
         raise errors.RemoteRunError(msg)
Ejemplo n.º 2
0
    def componentCall(self, componentState, methodName, *args, **kwargs):
        # FIXME: for now, we only allow calls to go through that have
        # their UI currently displayed.  In the future, maybe we want
        # to create all UI's at startup regardless and allow all messages
        # to be processed, since they're here now anyway
        self.log("componentCall received for %r.%s ..." %
                 (componentState, methodName))
        localMethodName = "component_%s" % methodName
        name = componentState.get('name')

        try:
            textui = self._comptextui[name]
        except KeyError:
            return

        if not hasattr(textui, localMethodName):
            self.log("... but does not have method %s" % localMethodName)
            self.warning("Component view %s does not implement %s" %
                         (name, localMethodName))
            return
        self.log("... and executing")
        method = getattr(textui, localMethodName)

        # call the method, catching all sorts of stuff
        try:
            result = method(*args, **kwargs)
        except TypeError:
            msg = ("component method %s did not"
                   " accept *a %s and **kwa %s (or TypeError)") % (
                       methodName, args, kwargs)
            self.debug(msg)
            raise errors.RemoteRunError(msg)
        self.log("component: returning result: %r to caller" % result)
        return result
Ejemplo n.º 3
0
        def callback(result):
            self.debug('runInWorker callbacked a result')
            self.clear_msg(functionName)

            if not isinstance(result, messages.Result):
                msg = messages.Error(T_(
                    N_("Internal error: could not run check code on worker.")),
                                     debug=(
                                         'function %r returned a non-Result %r'
                                         % (functionName, result)))
                self.add_msg(msg)
                self.taskFinished(True)
                raise errors.RemoteRunError(functionName, 'Internal error.')

            for m in result.messages:
                self.debug('showing msg %r' % m)
                self.add_msg(m)

            if result.failed:
                self.debug('... that failed')
                self.taskFinished(True)
                raise errors.RemoteRunFailure(functionName, 'Result failed')
            self.debug('... that succeeded')
            self.taskFinished()
            return result.value
Ejemplo n.º 4
0
def do_element_check(pipeline_str, element_name, check_proc, state=None,
    set_state_deferred=False):
    """
    Parse the given pipeline and set it to the given state.
    When the bin reaches that state, perform the given check function on the
    element with the given name.

    @param pipeline_str: description of the pipeline used to test
    @param element_name: name of the element being checked
    @param check_proc: a function to call with the GstElement as argument.
    @param state: an unused keyword parameter that will be removed when
    support for GStreamer 0.8 is dropped.
    @param set_state_deferred: a flag to say whether the set_state is run in
    a deferToThread
    @type set_state_deferred: bool
    @returns: a deferred that will fire with the result of check_proc, or
              fail.
    @rtype: L{twisted.internet.defer.Deferred}
    """

    def run_check(pipeline, resolution):
        element = pipeline.get_by_name(element_name)
        try:
            retval = check_proc(element)
            resolution.callback(retval)
        except check.CheckProcError, e:
            log.debug('check', 'CheckProcError when running %r: %r',
                      check_proc, e.data)
            resolution.errback(errors.RemoteRunError(e.data))
        except Exception, e:
            log.debug('check', 'Unhandled exception while running %r: %r',
                      check_proc, e)
            resolution.errback(errors.RemoteRunError(
                log.getExceptionMessage(e)))
Ejemplo n.º 5
0
 def run_check(pipeline, resolution):
     element = pipeline.get_by_name(element_name)
     try:
         retval = check_proc(element)
         resolution.callback(retval)
     except check.CheckProcError, e:
         log.debug('check', 'CheckProcError when running %r: %r',
                   check_proc, e.data)
         resolution.errback(errors.RemoteRunError(e.data))
Ejemplo n.º 6
0
        def errback(failure):
            self.debug('runInWorker errbacked, showing error msg')
            if failure.check(errors.RemoteRunError):
                debug = failure.value
            else:
                debug = "Failure while running %s.%s:\n%s" % (
                    moduleName, functionName, failure.getTraceback())

            msg = messages.Error(T_(
                N_("Internal error: could not run check code on worker.")),
                                 debug=debug)
            self.add_msg(msg)
            self.taskFinished(True)
            raise errors.RemoteRunError(functionName, 'Internal error.')
Ejemplo n.º 7
0
 def remote_effect(self, effectName, methodName, *args, **kwargs):
     """
     Invoke the given methodName on the given effectName in this component.
     The effect should implement effect_(methodName) to receive the call.
     """
     self.debug("calling %s on effect %s" % (methodName, effectName))
     if not effectName in self.comp.effects:
         raise errors.UnknownEffectError(effectName)
     effect = self.comp.effects[effectName]
     if not hasattr(effect, "effect_%s" % methodName):
         raise errors.NoMethodError("%s on effect %s" %
                                    (methodName, effectName))
     method = getattr(effect, "effect_%s" % methodName)
     try:
         result = method(*args, **kwargs)
     except TypeError:
         msg = "effect method %s did not accept %s and %s" % (methodName,
                                                              args, kwargs)
         self.debug(msg)
         raise errors.RemoteRunError(msg)
     self.debug("effect: result: %r" % result)
     return result
Ejemplo n.º 8
0
 def gotModuleError(failure):
     failure.trap(errors.NoBundleError)
     msg = 'Failed to find bundle for module %s' % module
     self.warning('%s', msg)
     raise errors.RemoteRunError(msg)