示例#1
0
    def execute(self, server, argv):
        options, args = parser.parse_args(argv)
        if len(argv) < 2:
            parser.print_help()
            return USER_ERROR

        filename = args[1]
        f = open(filename, 'r')
        status, data = backend.execute(server, f.read(), [], raw_output=options.raw)

        if status != OK:
            error("Failed to run script {filename}: {content}".format(
                filename=filename,
                content=data))
            return SERVER_ERROR

        if options.raw:
            sys.stdout.write("{}\n".format(json.dumps(data, indent=4)))
        else:
            # The stacktrace prop changed name with newer versions.
            if backend.STACKTRACE_FIELD in data:
                sys.stderr.write(data[backend.STACKTRACE_FIELD])
                return SERVER_ERROR
            elif backend.OUTPUT_FIELD in data:
                sys.stdout.write("{}".format(data[backend.OUTPUT_FIELD].encode('utf-8')))
            else:
                return INTERNAL_ERROR
        return OK
示例#2
0
    def execute(self, server, argv):
        options, args = parser.parse_args(argv)
        if len(argv) < 2:
            parser.print_help()
            return USER_ERROR

        filename = args[1]
        f = open(filename, 'r')
        status, data = backend.execute(server,
                                       f.read(), [],
                                       raw_output=options.raw)

        if status != OK:
            error("Failed to run script {filename}: {content}".format(
                filename=filename, content=data))
            return SERVER_ERROR

        if options.raw:
            sys.stdout.write("{}\n".format(json.dumps(data, indent=4)))
        else:
            # The stacktrace prop changed name with newer versions.
            if backend.STACKTRACE_FIELD in data:
                sys.stderr.write(data[backend.STACKTRACE_FIELD])
                return SERVER_ERROR
            elif backend.OUTPUT_FIELD in data:
                sys.stdout.write("{}".format(
                    data[backend.OUTPUT_FIELD].encode('utf-8')))
            else:
                return INTERNAL_ERROR
        return OK
示例#3
0
def test_execute():
    with HTTMock(service_mock):
        server = Server('localhost')
        f = open('tests/test_data/script.groovy')
        status, data = execute(server, f.read(), ['groovy'])
        eq_(OK, status)
        eq_(u'foo\n', data[OUTPUT_FIELD])
        eq_(u'0', data[RESULT_FIELD])
        ok_(STACKTRACE_FIELD not in data)