示例#1
0
def main(args: argparse.Namespace):
    progname = "gfzs.cmd.demo"
    properties = {
        "progname": progname,
        "severity": int(args.log_level),
        "log_path": args.log_path,
    }
    logger.init_properties(**properties)
    logger.debug("start %s" % progname)

    def handle_sigint(signum, fframe) -> None:
        logger.debug("detect SIGINT (Ctrl-c)")
        logger.debug("exit 0")
        sys.exit(0)

    signal.signal(signal.SIGINT, handle_sigint)
    warnings.simplefilter("ignore", FutureWarning)

    runtime_config.init()
    runtime_opts.init(args)
    if not runtime_config.valid():
        logger.debug("[print] 'Config is invalid.'")
        print("Config is invalid.")
        for error in runtime_config.errors:
            logger.error(error)
            print("Error: %s" % error)
        sys.exit(1)

    data = DEMO_JSON_DATA
    error = None
    controller = Controller(data)
    try:
        _ = controller.run()
    except curses.error as e:
        error = e
    except Exception as e:
        error = e
    finally:
        controller._end_curses()
        if error != None:
            logger.error(error)
            print("Error: %s" % error)
            logger.debug("exit 1")
            sys.exit(1)

        logger.debug("end %s" % progname, new_line=True)
示例#2
0
文件: model.py 项目: yukihirop/gfzs
    }
    logger.init_properties(**properties)
    logger.debug("start %s" % progname)

    def handle_sigint(signum, frame):
        logger.debug("detect SIGINT (Ctrl-c)")
        logger.debug("exit 0")
        sys.exit(0)

    signal.signal(signal.SIGINT, handle_sigint)

    json_str = open("fixtures/rust.json", "r").read()
    data = json.loads(json_str)

    args = argparse.Namespace(score=30)
    runtime_opts.init(args)

    model = TestModel(data)

    result = model.find("Amazon")
    logger.debug("Search (query=Amazon, score=%d):  %d / %d" %
                 (runtime_opts.score, model.data_size, model.summary_count))
    print("Search (query=Amazon, score=%d):  %d / %d" %
          (runtime_opts.score, model.data_size, model.summary_count))
    for i in range(len(result)):
        print(result[i]["title"])

    result = model.find("\0")
    logger.debug("Search (query=\0, score=%d):  %d / %d" %
                 (runtime_opts.score, model.data_size, model.summary_count))
    print("Search (query=\0, score=%d):  %d / %d" %
示例#3
0
        "progname": progname,
        "severity": 0,
        "log_path": "./tmp/gfzs.log"
    }
    logger.init_properties(**properties)
    logger.debug("start %s" % progname)

    def handle_sigint(signum, frame):
        logger.debug("detect SIGINT (Ctrl-c)")
        logger.debug("exit 0")
        sys.exit(0)

    signal.signal(signal.SIGINT, handle_sigint)

    runtime_config.init()
    runtime_opts.init()
    if not runtime_config.valid():
        logger.debug("[prinnt] Config is invalid.")
        print("Config is invalid.")
        for error in runtime_config.errors:
            logger.error(error)
            print("Error: %s" % error)
        logger.debug("exit 1")
        sys.exit(1)

    json_str = open("fixtures/rust.json", "r").read()
    data = json.loads(json_str)

    error = None
    controller = Controller(data)
    try: