Пример #1
0
    def main(self):
        self.parse_args()
        args, kwargs = parse_args_and_kwargs(self.args[1:])

        if len(args) < 2:
            self.print_help()
            sys.exit(1)
            #解析参数,获取位置参数和关键字参数

        cli = Client(globs=args[0],
                     exclude_globs=self.options.exclude,
                     nthread=int(self.options.nthread),
                     conf_dir=self.options.config_dir)
        rets = {}
        if args[0] == "sys.job_info":
            if len(args[1:]) == 0 and len(kwargs) == 0:
                sys.stderr.write(c("jid needed for sys.job_info\n", 'r'))
                sys.stderr.flush()
            else:
                rets = cli.job_info(*args[2:], **kwargs)
        else:
            cli.submit_job(args[1], *args[2:], **kwargs)
            rets = cli.get_return(self.options.timeout)

        if rets:
            rets = sort_ret(rets)
        else:
            print c('#' * 50, 'y')
            print color(rets.get("msg"), 'r')
            print c('#' * 50, 'y')
            sys.exit(1)

        nfail = 0
        for ret in rets:
            if not ret[1]:
                nfail += 1

        if not self.options.is_raw:
            format_ret = enumerate([
                u"%s : %s" % (c(ret[0], 'b'), color(format_obj(ret[1])))
                for ret in rets
            ])
        else:
            format_ret = enumerate(
                [u"%s : %s" % (ret[0], ret[1]) for ret in rets])
        print c('#' * 50, 'y')

        for index, item in format_ret:
            print item.encode("utf-8")

        print c('#' * 50, 'y')

        if locals().get('index') >= 0:
            index += 1
        else:
            index = 0
        print "一共执行了[%s]个,失败了[%s]" % (color(index), color(nfail, 0))
Пример #2
0
    def main(self):
        self.parse_args()
        args, kwargs = parse_args_and_kwargs(self.args[1:])

        if len(args) < 2:
            self.print_help()
            sys.exit(1)
            #解析参数,获取位置参数和关键字参数

        cli = Client(
            globs=args[0],
            exclude_globs=self.options.exclude,
            nthread=int(self.options.nthread),
            conf_dir=self.options.config_dir
        )
        rets = {}
        if args[0] == "sys.job_info":
            if len(args[1:]) == 0 and len(kwargs) == 0:
                sys.stderr.write(c("jid needed for sys.job_info\n", 'r'))
                sys.stderr.flush()
            else:
                rets = cli.job_info(*args[2:], **kwargs)
        else:
            cli.submit_job(args[1], *args[2:], **kwargs)
            rets = cli.get_return(self.options.timeout)

        if rets:
            rets = sort_ret(rets)
        else:
            print c('#' * 50, 'y')
            print color(rets.get("msg"), 'r')
            print c('#' * 50, 'y')
            sys.exit(1)

        nfail = 0
        for ret in rets:
            if not ret[1]:
                nfail += 1

        if not self.options.is_raw:
            format_ret = enumerate([u"%s : %s" % (c(ret[0], 'b'), color(format_obj(ret[1]))) for ret in rets])
        else:
            format_ret = enumerate([u"%s : %s" % (ret[0], ret[1]) for ret in rets])
        print c('#' * 50, 'y')

        for index, item in format_ret:
            print item.encode("utf-8")

        print c('#' * 50, 'y')

        if locals().get('index') >= 0:
            index += 1
        else:
            index = 0
        print "一共执行了[%s]个,失败了[%s]" % (color(index), color(nfail, 0))
Пример #3
0
 def main(self):
     """
     init zookeeper
     """
     self.parse_args()
     keeper = Keeper(self.config)
     if keeper.init_db(self.options.force):
         sys.stdout.write(c("init zookeeper db ok\n", 'g'))
     else:
         sys.stdout.write(c("init zookeeper db fail\n", 'r'))
     sys.stdout.flush()
Пример #4
0
 def status(self):
     """
     show status
     """
     try:
         pid = open(self.config["swall"]["pidfile"], 'r').read()
         message = c("swall is running[%s]...\n" % pid, 'g')
     except IOError:
         message = c("swall is not running!\n", 'r')
     sys.stdout.write(message)
     sys.stdout.flush()
Пример #5
0
 def status(self):
     """
     show status
     """
     try:
         pid = open(self.config["swall"]["pidfile"], 'r').read()
         message = c("swall is running[%s]...\n" % pid, 'g')
     except IOError:
         message = c("swall is not running!\n", 'r')
     sys.stdout.write(message)
     sys.stdout.flush()
Пример #6
0
 def main(self):
     """
     init zookeeper
     """
     self.parse_args()
     keeper = Keeper(self.config)
     if keeper.init_db(self.options.force):
         sys.stdout.write(c("init zookeeper db ok\n", 'g'))
     else:
         sys.stdout.write(c("init zookeeper db fail\n", 'r'))
     sys.stdout.flush()