Exemple #1
0
    def run(self):
        '''run the command and return result'''
        items = self.args.get(Command.DEFS, None)

        if items is None:
            items = json.load(sys.stdin)

        filter_names = self.args.get("type", None)

        if filter_names is None:
            return Result.bad_request("filter not specified")
        else:
            checks = []

            for name in filter_names:
                if name not in util.TYPE_CHECKS:
                    return Result.bad_request("filter not found: " + str(name))
                else:
                    filter_fun = util.TYPE_CHECKS[name]
                    checks.append(self.modifier(filter_fun))

            result = []
            for item in items:
                if self.multichecker(check(item) for check in checks):
                    result.append(item)

            return Result.ok(result)
Exemple #2
0
    def run(self):
        '''run the command and return result'''
        args = self.get_args()

        if isinstance(args, list):
            return Result.ok(self.process_list(args))
        elif isinstance(args, dict):
            # if it's a dict and there are default arguments remove them
            if Command.DEFS in args:
                del args[Command.DEFS]

            return Result.ok(self.process_object(args))
        else:
            return Result.ok(self.process_single(args))
Exemple #3
0
    def run(self):
        '''run the command and return result'''

        args = self.get_default_args()
        value = None

        if len(args) == 2:
            action, name = args
        elif len(args) == 3:
            action, name, value = args
        else:
            return Result.bad_request("expected 2 or 3 args")

        if action == "get":
            fail = self.args.get("fail", False)
            result = self.get(name, value, fail)
        elif action == "set":
            result = self.set(name, value)
        else:
            return Result.bad_request("expected valid action get or set")

        return Result.ok(result)
Exemple #4
0
def main(args):
    '''generic command entry point'''

    name = os.path.basename(args[0])

    if name.startswith("@"):
        name = name[1:]

    if name not in COMMANDS:
        finish(Result.not_found("command %s not found" % name))

    cls = COMMANDS[name]

    params = cls.parse_args(args[1:])

    result = cls.invoke(dict(name=name, args=params, vars=os.environ))
    finish(result)