Ejemplo n.º 1
0
    def doCallback(self, args):
        try:
            methodName = args[0]
        except IndexError:
            common.errorRaise('Please specify a method name.')

        if len(args) > 1:
            args = common.parseTypedArgs(args[1], args[2:])
            if args is None:
                common.errorRaise('Could not parse arguments.')
        else:
            args = []

        d = self.getRootCommand().medium.callRemote(
            methodName, *args)

        def cb(result):
            import pprint
            self.stdout.write("Invoking '%s' on manager returned:\n%s\n" % (
                methodName, pprint.pformat(result)))

        def eb(failure):
            # FIXME
            if failure.check(errors.NoMethodError) \
                or failure.check(flavors.NoSuchMethod):
                common.errorRaise("No method '%s' on manager." % methodName)
            elif failure.check(errors.RemoteRunError):
                common.errorRaise(log.getFailureMessage(failure))
            else:
                common.errorRaise(log.getFailureMessage(failure))

        d.addCallback(cb)
        d.addErrback(eb)

        return d
Ejemplo n.º 2
0
    def doCallback(self, args):
        if not self.parentCommand.componentId:
            common.errorRaise("Please specify a component id "
                              "with 'component -i [component-id]'")

        try:
            methodName = args[0]
        except IndexError:
            common.errorRaise('Please specify a method name to invoke.')
        if len(args) > 1:
            args = common.parseTypedArgs(args[1], args[2:])
            if args is None:
                common.errorRaise('Could not parse arguments.')
        else:
            args = []

        p = self.parentCommand
        d = self.getRootCommand().medium.componentCallRemote(
            self.parentCommand.componentState, methodName, *args)

        def cb(result):
            if self.rawOutput:
                self.stdout.write(str(result))
            else:
                import pprint
                self.stdout.write(
                    "Invoking '%s' on '%s' returned:\n%s\n" %
                    (methodName, p.componentId, pprint.pformat(result)))

        def eb(failure):
            if failure.check(errors.NoMethodError):
                common.errorRaise("No method '%s' on component '%s'." %
                                  (methodName, p.componentId))
            elif failure.check(errors.SleepingComponentError):
                common.errorRaise("Component '%s' is sleeping." %
                                  p.componentId)
            else:
                common.errorRaise(log.getFailureMessage(failure))

        d.addCallback(cb)
        d.addErrback(eb)

        return d
Ejemplo n.º 3
0
    def doCallback(self, args):
        workerName = self.parentCommand.options.name
        if not workerName:
            common.errorRaise('Please specify a worker name with --name.')

        try:
            methodName = args[0]
        except IndexError:
            common.errorRaise('Please specify a method name.')

        if len(args) > 1:
            args = common.parseTypedArgs(args[1], args[2:])
            if args is None:
                common.errorRaise('Could not parse arguments.')
        else:
            args = []

        p = self.parentCommand
        d = self.getRootCommand().medium.callRemote(
            'workerCallRemote', workerName, methodName, *args)

        def cb(result):
            import pprint
            self.stdout.write("Invoking '%s' on '%s' returned:\n%s\n" % (
                methodName, workerName, pprint.pformat(result)))

        def eb(failure):
            # FIXME
            if failure.check(errors.NoMethodError):
                common.errorRaise("No method '%s' on worker '%s'." % (
                    methodName, workerName))
            elif failure.check(errors.SleepingComponentError):
                common.errorRaise("Component '%s' is sleeping." %
                    p.componentId)
            elif failure.check(errors.RemoteRunError):
                common.errorRaise(log.getFailureMessage(failure))
            else:
                common.errorRaise(log.getFailureMessage(failure))

        d.addCallback(cb)
        d.addErrback(eb)

        return d
Ejemplo n.º 4
0
    def doCallback(self, args):
        if not self.parentCommand.componentId:
            common.errorRaise("Please specify a component id "
                "with 'component -i [component-id]'")

        try:
            methodName = args[0]
        except IndexError:
            common.errorRaise('Please specify a method name to invoke.')
        if len(args) > 1:
            args = common.parseTypedArgs(args[1], args[2:])
            if args is None:
                common.errorRaise('Could not parse arguments.')
        else:
            args = []

        p = self.parentCommand
        d = self.getRootCommand().medium.componentCallRemote(
            self.parentCommand.componentState, methodName, *args)

        def cb(result):
            if self.rawOutput:
                self.stdout.write(str(result))
            else:
                import pprint
                self.stdout.write("Invoking '%s' on '%s' returned:\n%s\n" % (
                        methodName, p.componentId, pprint.pformat(result)))

        def eb(failure):
            if failure.check(errors.NoMethodError):
                common.errorRaise("No method '%s' on component '%s'." % (
                    methodName, p.componentId))
            elif failure.check(errors.SleepingComponentError):
                common.errorRaise(
                    "Component '%s' is sleeping." % p.componentId)
            else:
                common.errorRaise(log.getFailureMessage(failure))

        d.addCallback(cb)
        d.addErrback(eb)

        return d
Ejemplo n.º 5
0
    def doCallback(self, args):
        try:
            moduleName = args[0]
        except IndexError:
            common.errorRaise('Please specify a module name to invoke from.')
        try:
            methodName = args[1]
        except IndexError:
            common.errorRaise('Please specify a method name.')

        if len(args) > 2:
            args = common.parseTypedArgs(args[2], args[3:])
            if args is None:
                common.errorRaise('Could not parse arguments.')
        else:
            args = []

        p = self.parentCommand
        workerName = p.options.name
        d = self.getRootCommand().medium.callRemote(
            'workerCallRemote', workerName, 'runFunction',
            moduleName, methodName, *args)

        def cb(result):
            i18n.installGettext()
            # handle some results specifically, like Result
            self.stdout.write("Invoking '%s' on '%s' returned:\n" %
                    (methodName, workerName))
            import pprint
            self.stdout.write("%s\n" % pprint.pformat(result))

            if isinstance(result, messages.Result):
                _headings = {
                    messages.ERROR: _('Error'),
                    messages.WARNING: _('Warning'),
                    messages.INFO: _('Note'),
                }

                for m in result.messages:
                    translator = i18n.Translator()
                    localedir = os.path.join(configure.localedatadir, 'locale')
                    # FIXME: add locales as messages from domains come in
                    translator.addLocaleDir(configure.PACKAGE, localedir)
                    self.stdout.write('%s:\n' % _headings[m.level])
                    self.stdout.write(translator.translate(m) + '\n')
                    if hasattr(m, 'timestamp'):
                        self.stdout.write(_("\nPosted on %s.\n") %
                            time.strftime("%c", time.localtime(m.timestamp)))
                    if m.debug:
                        self.stdout.write("DEBUG:\n%s\n" % m.debug)

                if result.failed:
                    self.stdout.write('Result failed.\n')
                else:
                    self.stdout.write('Result successful:\n%s\n' %
                        pprint.pformat(result.value))

        def eb(failure):
            if failure.check(errors.NoMethodError):
                common.errorRaise("No method '%s' on worker '%s'." % (
                    methodName, workerName))
            elif failure.check(errors.SleepingComponentError):
                common.errorRaise("Component '%s' is sleeping." %
                    p.componentId)
            elif failure.check(errors.RemoteRunError):
                common.errorRaise(log.getFailureMessage(failure))
            else:
                common.errorRaise(log.getFailureMessage(failure))

        d.addCallback(cb)
        d.addErrback(eb)

        return d
Ejemplo n.º 6
0
    def doCallback(self, args):
        try:
            moduleName = args[0]
        except IndexError:
            common.errorRaise('Please specify a module name to invoke from.')
        try:
            methodName = args[1]
        except IndexError:
            common.errorRaise('Please specify a method name.')

        if len(args) > 2:
            args = common.parseTypedArgs(args[2], args[3:])
            if args is None:
                common.errorRaise('Could not parse arguments.')
        else:
            args = []

        p = self.parentCommand
        workerName = p.options.name
        d = self.getRootCommand().medium.callRemote('workerCallRemote',
                                                    workerName, 'runFunction',
                                                    moduleName, methodName,
                                                    *args)

        def cb(result):
            i18n.installGettext()
            # handle some results specifically, like Result
            self.stdout.write("Invoking '%s' on '%s' returned:\n" %
                              (methodName, workerName))
            import pprint
            self.stdout.write("%s\n" % pprint.pformat(result))

            if isinstance(result, messages.Result):
                _headings = {
                    messages.ERROR: _('Error'),
                    messages.WARNING: _('Warning'),
                    messages.INFO: _('Note'),
                }

                for m in result.messages:
                    translator = i18n.Translator()
                    localedir = os.path.join(configure.localedatadir, 'locale')
                    # FIXME: add locales as messages from domains come in
                    translator.addLocaleDir(configure.PACKAGE, localedir)
                    self.stdout.write('%s:\n' % _headings[m.level])
                    self.stdout.write(translator.translate(m) + '\n')
                    if hasattr(m, 'timestamp'):
                        self.stdout.write(
                            _("\nPosted on %s.\n") %
                            time.strftime("%c", time.localtime(m.timestamp)))
                    if m.debug:
                        self.stdout.write("DEBUG:\n%s\n" % m.debug)

                if result.failed:
                    self.stdout.write('Result failed.\n')
                else:
                    self.stdout.write('Result successful:\n%s\n' %
                                      pprint.pformat(result.value))

        def eb(failure):
            if failure.check(errors.NoMethodError):
                common.errorRaise("No method '%s' on worker '%s'." %
                                  (methodName, workerName))
            elif failure.check(errors.SleepingComponentError):
                common.errorRaise("Component '%s' is sleeping." %
                                  p.componentId)
            elif failure.check(errors.RemoteRunError):
                common.errorRaise(log.getFailureMessage(failure))
            else:
                common.errorRaise(log.getFailureMessage(failure))

        d.addCallback(cb)
        d.addErrback(eb)

        return d