Exemple #1
0
def main():
    notify_if_latest_version_found()

    if len(sys.argv) < 2 or sys.argv[1] not in ("gen", "test", "submit",
                                                "codegen", "version"):
        print("Usage:")
        print("{} gen -- to generate workspace".format(sys.argv[0]))
        print("{} test -- to test codes in your workspace".format(sys.argv[0]))
        print("{} submit -- to submit a code to the contest system".format(
            sys.argv[0]))
        print("{} version -- show atcoder-tools version".format(sys.argv[0]))
        sys.exit(-1)

    prog = " ".join(sys.argv[:2])
    args = sys.argv[2:]

    if sys.argv[1] == "gen":
        envgen_main(prog, args)

    if sys.argv[1] == "test":
        exit_program(tester_main(prog, args))

    if sys.argv[1] == "submit":
        exit_program(submit_main(prog, args))

    if sys.argv[1] == "codegen":
        codegen_main(prog, args)

    if sys.argv[1] == "version":
        print(__version__)
def main():
    notify_if_latest_version_found()

    if len(sys.argv) < 2 or sys.argv[1] not in ("gen", "test", "submit", "codegen"):
        print("Usage:")
        print("{} gen -- to generate workspace".format(sys.argv[0]))
        print("{} test -- to test codes in your workspace".format(sys.argv[0]))
        print(
            "{} submit -- to submit a code to the contest system".format(sys.argv[0]))
        print(
            "{} codegen -- to generate a code for a given problem (stdout)".format(sys.argv[0]))
        sys.exit(-1)

    prog = " ".join(sys.argv[:2])
    args = sys.argv[2:]

    if sys.argv[1] == "gen":
        envgen_main(prog, args)

    if sys.argv[1] == "test":
        exit_program(tester_main(prog, args))

    if sys.argv[1] == "submit":
        exit_program(submit_main(prog, args))

    if sys.argv[1] == "codegen":
        codegen_main(prog, args)
def main():
    notify_if_latest_version_found()

    if len(sys.argv) < 2 or sys.argv[1] not in ("gen", "test", "submit",
                                                "codegen", "set", "version",
                                                "compile"):
        print("Usage:")
        print("{} gen -- to generate workspace".format(sys.argv[0]))
        print("{} test -- to test your code in the workspace".format(
            sys.argv[0]))
        print("{} submit -- to submit your code to the contest system".format(
            sys.argv[0]))
        print("{} compile -- compile source code".format(sys.argv[0]))
        print("{} set -- switch program language/judge method".format(
            sys.argv[0]))
        print("{} codegen -- to generate code of the specified single problem".
              format(sys.argv[0]))
        print("{} version -- show atcoder-tools version".format(sys.argv[0]))
        sys.exit(-1)

    prog = " ".join(sys.argv[:2])
    args = sys.argv[2:]

    if sys.argv[1] == "gen":
        envgen_main(prog, args)

    if sys.argv[1] == "test":
        exit_program(tester_main(prog, args))

    if sys.argv[1] == "submit":
        exit_program(submit_main(prog, args))

    if sys.argv[1] == "codegen":
        codegen_main(prog, args)

    if sys.argv[1] == "set":
        setter_main(prog, args)

    if sys.argv[1] == "compile":
        compiler_main(prog, args)

    if sys.argv[1] == "version":
        print(__version__)
Exemple #4
0
def main(prog, args) -> None:
    if len(args) == 0:
        print("Usage: atcoder tools set [options]")
        return

    parser = argparse.ArgumentParser(
        prog=prog, formatter_class=argparse.RawTextHelpFormatter)

    parser.add_argument('--judge-type',
                        '-j',
                        help='error type'
                        ' must be one of [{}]'.format(
                            ', '.join(USER_FACING_JUDGE_TYPE_LIST)),
                        type=str,
                        default=None)

    parser.add_argument('--error-value',
                        '-v',
                        help='error value for decimal number judge:'
                        ' [Default] ' + str(DEFAULT_EPS),
                        type=float,
                        default=None)

    parser.add_argument(
        "--lang",
        help="Programming language of your template code, {}.\n".format(
            " or ".join([lang.name for lang in ALL_LANGUAGES])),
        default=None)

    parser.add_argument(
        "--dir",
        '-d',
        help="Target directory to test. [Default] Current directory",
        default=".")

    args = parser.parse_args(args)

    old_metadata = Metadata.load_from(os.path.join(args.dir, "metadata.json"))

    # Use the old metadata as base metadata.
    output_metadata = Metadata.load_from(
        os.path.join(args.dir, "metadata.json"))

    if args.judge_type in ["absolute", "relative", "absolute_or_relative"]:
        new_metadata_judge_type = "decimal"
    else:
        new_metadata_judge_type = args.judge_type

    old_metadata_judge_type = old_metadata.judge_method.judge_type.value

    if new_metadata_judge_type is not None and new_metadata_judge_type != old_metadata_judge_type:
        if new_metadata_judge_type == JudgeType.Normal.value:
            output_metadata.judge_method = NormalJudge()
        elif new_metadata_judge_type == JudgeType.Decimal.value:
            output_metadata.judge_method = DecimalJudge()
        elif new_metadata_judge_type == JudgeType.MultiSolution.value:
            output_metadata.judge_method = MultiSolutionJudge()
        elif new_metadata_judge_type == JudgeType.Interactive.value:
            output_metadata.judge_method = InteractiveJudge()
        else:
            raise NoJudgeTypeException()

    judge_code_filename = os.path.join(args.dir, "judge.cpp")

    if new_metadata_judge_type == JudgeType.Decimal.value:
        if args.error_value is not None:
            output_metadata.judge_method.diff = args.error_value
        else:
            logger.warn(
                "Error-value is not specified. Default value will be set.")
        output_metadata.judge_method.error_type = ErrorType(args.judge_type)

    elif new_metadata_judge_type == JudgeType.MultiSolution.value:
        if not os.path.exists(judge_code_filename):
            print("Creating {} (multi-solution)".format(judge_code_filename))
            judge_template_path = get_default_judge_template_path('cpp')
            shutil.copy(judge_template_path, judge_code_filename)
        else:
            print("Judge code exists. Skipping creating judge code...")
    elif new_metadata_judge_type == JudgeType.Interactive.value:
        if not os.path.exists(judge_code_filename):
            print("Creating {} (interactive)".format(judge_code_filename))
            judge_template_path = get_default_judge_template_path('cpp')
            shutil.copy(judge_template_path, judge_code_filename)
        else:
            print("Judge code exists. Skipping creating judge code...")

    if args.lang is not None:
        if args.lang != output_metadata.lang.name:
            output_metadata.lang = Language.from_name(args.lang)
            output_metadata.code_filename = output_metadata.lang.get_code_filename(
                'main')
            url = "https://atcoder.jp/contests/{}/tasks/{}".format(
                output_metadata.problem.contest.contest_id,
                output_metadata.problem.problem_id)
            main_code_filename = os.path.join(args.dir,
                                              output_metadata.code_filename)
            if not os.path.exists(main_code_filename):
                codegen_main("", ["--lang", output_metadata.lang.name, url],
                             open(main_code_filename, 'w'))
            else:
                print("File exists: ", output_metadata.code_filename)
        else:
            print("Already set to {}. Skipping changing language...".format(
                args.lang))
    output_metadata.save_to(os.path.join(args.dir, "metadata.json"))
Exemple #5
0
def main(prog, args):
    if len(args) == 0:
        print("Usage: atcoder tools set [options]")
        return

    parser = argparse.ArgumentParser(
        prog=prog,
        formatter_class=argparse.RawTextHelpFormatter)

    parser.add_argument('--judge-type', '-j',
                        help='error type'
                             ' must be one of [{}]'.format(
                                 ', '.join(USER_FACING_JUDGE_TYPE_LIST)),
                        type=str,
                        default=None)

    parser.add_argument('--error-value', '-v',
                        help='error value for decimal number judge:'
                             ' [Default] ' + str(DEFAULT_EPS),
                        type=float,
                        default=None)

    parser.add_argument("--lang",
                        help="Programming language of your template code, {}.\n".format(
                            " or ".join([lang.name for lang in ALL_LANGUAGES])),
                        default=None)

    parser.add_argument("--dir", '-d',
                        help="Target directory to test. [Default] Current directory",
                        default=".")

    args = parser.parse_args(args)

    metadata = Metadata.load_from(args.dir + "/metadata.json")

    new_judge_type = args.judge_type
    if new_judge_type in ["decimal", "absolute", "relative", "absolute_or_relative"]:
        new_judge_type = "decimal"
        if args.judge_type == "decimal":
            args.judge_type = "absolute_or_relative"

    old_judge_type = metadata.judge_method.judge_type.value

    if new_judge_type is not None and new_judge_type != old_judge_type:
        if new_judge_type == JudgeType.Normal.value:
            metadata.judge_method = NormalJudge()
        elif new_judge_type == JudgeType.Decimal.value:
            metadata.judge_method = DecimalJudge()
        elif new_judge_type == JudgeType.MultiSolution.value:
            metadata.judge_method = MultiSolutionJudge()
        elif new_judge_type == JudgeType.Interactive.value:
            metadata.judge_method = InteractiveJudge()
        else:
            raise NoJudgeTypeException()

    if new_judge_type == JudgeType.Decimal.value:
        if args.error_value is not None:
            metadata.judge_method.diff = args.error_value
        else:
            print("Warning: error-value is not specified default value is set. ")
        metadata.judge_method.error_type = ErrorType(args.judge_type)
    elif new_judge_type == JudgeType.MultiSolution.value:
        if not os.path.exists("./judge.cpp"):
            print("touch ./judge.cpp (multi sotlution)")
            judge_template_path = get_default_judge_template_path('cpp')
            shutil.copy(judge_template_path, "./judge.cpp")
        else:
            print("Judge Code exists")
    elif new_judge_type == JudgeType.Interactive.value:
        if not os.path.exists("/judge.cpp"):
            print("touch ./judge.cpp (interactive)")
            judge_template_path = get_default_judge_template_path('cpp')
            shutil.copy(judge_template_path, "./judge.cpp")
        else:
            print("Judge Code exists")

    if args.lang is not None:
        if args.lang != metadata.lang.name:
            metadata.lang = Language.from_name(args.lang)
            metadata.code_filename = metadata.lang.get_code_filename('main')
            url = "https://atcoder.jp/contests/{}/tasks/{}".format(
                metadata.problem.contest.contest_id, metadata.problem.problem_id)
            if not os.path.exists(metadata.code_filename):
                codegen_main("", ["--lang", metadata.lang.name,
                                  url], open(metadata.code_filename, 'w'))
            else:
                print("file exists: ", metadata.code_filename)
        else:
            print("already set to {}".format(args.lang))
    metadata.save_to(args.dir + "/metadata.json")
    return metadata