Esempio n. 1
0
    def run(self, content, log):
        assert isinstance(content, bytes), (`content`, type(content))
        assert self.rref is not None
        options = ClientOptions()
        options.parseOptions(self.flappclient_args)

        def stdio(proto):
            # This value is being sent to the stdin of the flapp.
            proto.dataReceived(content)
            proto.connectionLost("EOF")

        options.subOptions.stdio = stdio

        # These are not used.
        options.subOptions.stdout = None
        options.subOptions.stderr = None

        print >>log, "Starting command."
        self.d = RunCommand().run(self.rref, options.subOptions)
        def _log_return_code(rc):
            print >>log, "Command completed with exit code %r" % (rc,)
        def _log_failure(f):
            print >>log, "Command failed with %r" % (f,)

        self.d.addCallbacks(_log_return_code, _log_failure)
        return self.d
Esempio n. 2
0
    def run(self, content, log):
        assert isinstance(content, bytes), (`content`, type(content))
        assert self.rref is not None
        options = ClientOptions()
        options.parseOptions(self.flappclient_args)

        def stdio(proto):
            # This value is being sent to the stdin of the flapp.
            proto.dataReceived(content)
            proto.connectionLost("EOF")

        options.subOptions.stdio = stdio

        # These are not used.
        options.subOptions.stdout = None
        options.subOptions.stderr = None

        print >>log, "Starting command."
        self.d = RunCommand().run(self.rref, options.subOptions)
        def _log_return_code(rc):
            print >>log, "Command completed with exit code %r" % (rc,)
        def _log_failure(f):
            print >>log, "Command failed with %r" % (f,)

        self.d.addCallbacks(_log_return_code, _log_failure)
        return self.d
Esempio n. 3
0
 def __init__(self, furlfile):
     self.flappclient_args = ["-f", furlfile, "run-command"]
     options = ClientOptions()
     options.parseOptions(self.flappclient_args)
     self.furl = options.furl
     self.tub = Tub()
     self.rref = None
     self.d = defer.succeed(None)
Esempio n. 4
0
 def __init__(self, furl):
     self.flappclient_args = ["--furl", furl, "run-command"]
     options = ClientOptions()
     options.parseOptions(self.flappclient_args)
     self.furl = options.furl
     self.tub = Tub()
     self.rref = None
     self.d = defer.succeed(None)
Esempio n. 5
0
    def run(self, content, stdout, stderr, when_done, when_failed):
        assert self.rref is not None
        options = ClientOptions()
        options.stdout = stdout
        options.stderr = stderr
        options.parseOptions(self.flappclient_args)

        def stdio(proto):
            proto.dataReceived(content)
            proto.connectionLost("EOF")

        options.subOptions.stdio = stdio
        options.subOptions.stdout = stdout
        options.subOptions.stderr = stderr

        def _go(ign):
            print >>stdout, "Starting..."
            return RunCommand().run(self.rref, options.subOptions)
        def _done(rc):
            if rc == 0:
                when_done()
            else:
                print >>stdout, "Command failed with exit code %r." % (rc,)
                when_failed()
        def _error(f):
            print >>stdout, str(f)
            when_failed()
        def _recover(f):
            try:
                print >>stderr, str(f)
            except Exception:
                print >>stderr, "something weird"

        self.d.addCallback(_go)
        self.d.addCallbacks(_done, _error)
        self.d.addErrback(_recover)
Esempio n. 6
0
    def run(self, content, stdout, stderr, when_done, when_failed):
        assert self.rref is not None
        options = ClientOptions()
        options.stdout = stdout
        options.stderr = stderr
        options.parseOptions(self.flappclient_args)

        def stdio(proto):
            proto.dataReceived(content)
            proto.connectionLost("EOF")

        options.subOptions.stdio = stdio
        options.subOptions.stdout = stdout
        options.subOptions.stderr = stderr

        def _go(ign):
            print >> stdout, "Starting..."
            return RunCommand().run(self.rref, options.subOptions)

        def _done(rc):
            if rc == 0:
                when_done()
            else:
                print >> stdout, "Command failed with exit code %r." % (rc, )
                when_failed()

        def _error(f):
            print >> stdout, str(f)
            when_failed()

        def _recover(f):
            try:
                print >> stderr, str(f)
            except Exception:
                print >> stderr, "something weird"

        self.d.addCallback(_go)
        self.d.addCallbacks(_done, _error)
        self.d.addErrback(_recover)