예제 #1
0
    def action(self, args):
        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                node = self.mode.pfaFiles[args[0].text].obj

            else:
                self.syntaxError()

            try:
                node = node[self.name]  # "input" or "output"
            except KeyError:
                raise InspectorError("PFA document \"{0}\" is missing {1} section')".format(args[0].text, self.name))

            if options["pretty"]:
                print avscToPretty(node)
            else:
                t.look(node, inlineDepth=1)
예제 #2
0
    def action(self, args):
        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]

            else:
                self.syntaxError()

            names = sorted(model.engineConfig.fcns)
            for index, name in enumerate(names):
                fcn = model.engineConfig.fcns[name]
                print "u." + name + ":"
                print "    parameters:"
                for pname in fcn.paramNames:
                    ptype = fcn.params[pname]
                    if options["pretty"]:
                        print "        " + pname + ": " + avscToPretty(ptype.jsonNode(set()), 10 + len(pname)).lstrip()
                    else:
                        print "        " + pname + ": " + ptype.toJson()

                if options["pretty"]:
                    print "    returns " + avscToPretty(fcn.ret.jsonNode(set()), 12).lstrip()
                else:
                    print "    returns " + fcn.ret.toJson()

                if model.engine.isRecursive("u." + name):
                    print "    recursive"
                elif model.engine.hasRecursive("u." + name):
                    print "    can call a recursive function"
                else:
                    print "    call depth: " + str(model.engine.callDepth("u." + name))
                if model.engine.hasSideEffects("u." + name):
                    print "    can modify a cell or pool"

                calledBy = sorted(model.engine.calledBy("u." + name))
                print "    called by: " + ", ".join(calledBy) if len(calledBy) > 0 else "(none)"

                if index != len(names) - 1:
                    print

            if len(names) == 0:
                print "PFA document contains no user functions"
예제 #3
0
    def action(self, args):
        """Perform the action associated with this command.

        :type args: list of titus.inspector.parser.Ast
        :param args: arguments passed to the command
        :rtype: ``None``
        :return: nothing; results must be printed to the screen
        """

        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(
                            opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(
                        opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError(
                        "no PFA document named \"{0}\" in memory (try 'load <file> as {1}')"
                        .format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]
                node = model.obj

            else:
                self.syntaxError()

            try:
                node = node[self.name]  # "input" or "output"
            except KeyError:
                raise InspectorError(
                    "PFA document \"{0}\" is missing {1} section')".format(
                        args[0].text, self.name))

            if isinstance(node, basestring):
                names = model.engine.parser.names.names.keys()
                if node in names:
                    node = model.engine.parser.getAvroType(node).jsonNode(
                        set())

            if options["pretty"]:
                print avscToPretty(node)
            else:
                t.look(node, inlineDepth=1)
예제 #4
0
파일: pfagadget.py 프로젝트: nkhuyu/hadrian
    def action(self, args):
        """Perform the action associated with this command.

        :type args: list of titus.inspector.parser.Ast
        :param args: arguments passed to the command
        :rtype: ``None``
        :return: nothing; results must be printed to the screen
        """

        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]
                node = model.obj

            else:
                self.syntaxError()

            try:
                node = node[self.name]  # "input" or "output"
            except KeyError:
                raise InspectorError("PFA document \"{0}\" is missing {1} section')".format(args[0].text, self.name))

            if isinstance(node, basestring):
                names = model.engine.parser.names.names.keys()
                if node in names:
                    node = model.engine.parser.getAvroType(node).jsonNode(set())

            if options["pretty"]:
                print avscToPretty(node)
            else:
                t.look(node, inlineDepth=1)
예제 #5
0
파일: pfagadget.py 프로젝트: nkhuyu/hadrian
    def action(self, args):
        """Perform the action associated with this command.

        :type args: list of titus.inspector.parser.Ast
        :param args: arguments passed to the command
        :rtype: ``None``
        :return: nothing; results must be printed to the screen
        """

        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]

            else:
                self.syntaxError()

            if self.name == "cells":
                node = model.engineConfig.cells
            elif self.name == "pools":
                node = model.engineConfig.pools

            names = sorted(node.keys())
            for index, name in enumerate(names):
                obj = node[name]
                if self.name == "cells":
                    preamble = "{0}: shared={1} rollback={2} type=".format(name, json.dumps(obj.shared), json.dumps(obj.rollback))
                elif self.name == "pools":
                    preamble = "{0}: shared={1} rollback={2} elements={3} type=".format(name, json.dumps(obj.shared), json.dumps(obj.rollback), len(json.loads(obj.init)))

                ptype = obj.avroType
                if options["pretty"]:
                    print preamble + avscToPretty(ptype.jsonNode(set()), len(preamble)).lstrip()
                else:
                    print preamble + ptype.toJson()

                if index != len(names) - 1:
                    print

            if len(names) == 0:
                print "PFA document contains no " + self.name
예제 #6
0
    def action(self, args):
        """Perform the action associated with this command.

        :type args: list of titus.inspector.parser.Ast
        :param args: arguments passed to the command
        :rtype: ``None``
        :return: nothing; results must be printed to the screen
        """

        if len(args) == 1 and args[0] == parser.Word("help"):
            print(self.help)
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]

            else:
                self.syntaxError()

            if self.name == "cells":
                node = model.engineConfig.cells
            elif self.name == "pools":
                node = model.engineConfig.pools

            names = sorted(node.keys())
            for index, name in enumerate(names):
                obj = node[name]
                if self.name == "cells":
                    preamble = "{0}: shared={1} rollback={2} type=".format(name, json.dumps(obj.shared), json.dumps(obj.rollback))
                elif self.name == "pools":
                    preamble = "{0}: shared={1} rollback={2} elements={3} type=".format(name, json.dumps(obj.shared), json.dumps(obj.rollback), len(json.loads(obj.init)))

                ptype = obj.avroType
                if options["pretty"]:
                    print(preamble + avscToPretty(ptype.jsonNode(set()), len(preamble)).lstrip())
                else:
                    print(preamble + ptype.toJson())

                if index != len(names) - 1:
                    print()

            if len(names) == 0:
                print("PFA document contains no " + self.name)
예제 #7
0
    def action(self, args):
        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]

            else:
                self.syntaxError()

            names = sorted(model.engine.parser.names.names.keys())
            for index, name in enumerate(names):
                node = model.engine.parser.getAvroType(name).jsonNode(set())
                print name + ":"
                if options["pretty"]:
                    print avscToPretty(node, 4)
                else:
                    t.look(node, inlineDepth=1)
                if index != len(names) - 1:
                    print

            if len(names) == 0:
                print "PFA document contains no named types"
예제 #8
0
    def action(self, args):
        """Perform the action associated with this command.

        :type args: list of titus.inspector.parser.Ast
        :param args: arguments passed to the command
        :rtype: ``None``
        :return: nothing; results must be printed to the screen
        """

        if len(args) == 1 and args[0] == parser.Word("help"):
            print(self.help)
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError("no PFA document named \"{0}\" in memory (try 'load <file> as {1}')".format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]

            else:
                self.syntaxError()

            names = sorted(model.engine.parser.names.names.keys())
            for index, name in enumerate(names):
                node = model.engine.parser.getAvroType(name).jsonNode(set())
                print(name + ":")
                if options["pretty"]:
                    print(avscToPretty(node, 4))
                else:
                    t.look(node, inlineDepth=1)
                if index != len(names) - 1:
                    print()

            if len(names) == 0:
                print("PFA document contains no named types")
예제 #9
0
    def action(self, args):
        """Perform the action associated with this command.

        :type args: list of titus.inspector.parser.Ast
        :param args: arguments passed to the command
        :rtype: ``None``
        :return: nothing; results must be printed to the screen
        """

        if len(args) == 1 and args[0] == parser.Word("help"):
            print self.help
        else:
            options = {"pretty": True}
            while len(args) > 0 and isinstance(args[-1], parser.Option):
                opt = args.pop()
                if opt.word.text in ["pretty"]:
                    try:
                        options[opt.word.text] = opt.value.value()
                    except TypeError:
                        raise InspectorError("illegal value for {0}".format(
                            opt.word.text))
                else:
                    raise InspectorError("option {0} unrecognized".format(
                        opt.word.text))

            if not isinstance(options["pretty"], bool):
                raise InspectorError("pretty must be boolean")

            if len(args) == 1 and isinstance(args[0], parser.Word):
                if args[0].text not in self.mode.pfaFiles:
                    raise InspectorError(
                        "no PFA document named \"{0}\" in memory (try 'load <file> as {1}')"
                        .format(args[0].text, args[0].text))
                model = self.mode.pfaFiles[args[0].text]

            else:
                self.syntaxError()

            names = sorted(model.engineConfig.fcns)
            for index, name in enumerate(names):
                fcn = model.engineConfig.fcns[name]
                print "u." + name + ":"
                print "    parameters:"
                for pname in fcn.paramNames:
                    ptype = fcn.params[pname]
                    if options["pretty"]:
                        print "        " + pname + ": " + avscToPretty(
                            ptype.jsonNode(set()), 10 + len(pname)).lstrip()
                    else:
                        print "        " + pname + ": " + ptype.toJson()

                if options["pretty"]:
                    print "    returns " + avscToPretty(
                        fcn.ret.jsonNode(set()), 12).lstrip()
                else:
                    print "    returns " + fcn.ret.toJson()

                if model.engine.isRecursive("u." + name):
                    print "    recursive"
                elif model.engine.hasRecursive("u." + name):
                    print "    can call a recursive function"
                else:
                    print "    call depth: " + str(
                        model.engine.callDepth("u." + name))
                if model.engine.hasSideEffects("u." + name):
                    print "    can modify a cell or pool"

                calledBy = sorted(model.engine.calledBy("u." + name))
                print "    called by: " + ", ".join(calledBy) if len(
                    calledBy) > 0 else "(none)"

                if index != len(names) - 1:
                    print

            if len(names) == 0:
                print "PFA document contains no user functions"