def main():
    ASTYLE_PATH = "./astyle/build/gcc/bin/astyle"
    debug = False
    safe = True
    unsafe = True
    date = time.strftime("%m-%d-%Y_%Hh%Mm%S")

    args = docopt(__doc__, version='0.4')

    # get selected language
    language = None
    if args["--language"]:
        language = args["--language"]
    else:
        print("Specify a language with -l/--language option (cs, php)")
        sys.exit(1)

    # check if language exists
    if not FileManager.exist_language(language):
        print("Patch your language folder '{}'".format(language))
        sys.exit(1)

    # create generator for specified language
    g = Generator(date, language=language)

    # List of flaws
    flaw_list = g.get_group_list()
    cwe_list = g.get_cwe_list()

    flaw_group_user = [x.lower() for x in args["--flaw-group"]]
    for flaw in flaw_group_user:
        if flaw.lower() not in flaw_list:
            print("There is no flaws associated with the given flaw group (-f {} option).\
                  See --help.".format(flaw.lower()))
            sys.exit(1)
    try:
        flaw_type_user = [int(x) for x in args["--cwe"]]
    except ValueError:
        print("Invalid format. Value of the -c option must be an integer. See --help")
        sys.exit(1)
    for cwe in flaw_type_user:
        if cwe not in cwe_list:
            print("There is no flaws associated with the given CWE (-c {} option). See --help.".format(cwe))
            sys.exit(1)
    if args["--safe"]:
        safe = True
        unsafe = False
    if args["--unsafe"]:
        safe = False
        unsafe = True
    debug = args["--debug"]
    try:
        arg = args["--depth"]
        g.max_recursion = int(arg) if arg is not None else 1
    except ValueError:
        print("Invalid format. Value of the -r option must be an integer. See --help")
        sys.exit(1)
    try:
        arg = args["--number-generated"]
        g.number_generated = int(arg) if arg is not None else -1
    except ValueError:
        print("Invalid format. Value of the -g option must be an integer. See --help")
        sys.exit(1)

    # set user list
    g.set_flaw_type_user(flaw_type_user)
    g.set_flaw_group_user(flaw_group_user)

    # run generation
    g.generate(debug=debug, generate_safe=safe, generate_unsafe=unsafe)

    # check if astyle is here
    if os.path.isfile(ASTYLE_PATH):
        print("Indentation ...")
        cmd = ASTYLE_PATH+" -r TestSuite_"+date+"/*."+g.get_extension()+" --style=java --suffix=none --indent-switches -q"
        os.system(cmd)
    else:
        print("No indentation")

    print("Finish")
Пример #2
0
def main():
    ASTYLE_PATH = "./astyle/build/gcc/bin/astyle"
    debug = False
    safe = True
    unsafe = True
    date = time.strftime("%m-%d-%Y_%Hh%Mm%S")

    args = docopt(__doc__, version='0.4')

    # get selected language
    language = None
    if args["--language"]:
        language = args["--language"]
    else:
        print("Specify a language with -l/--language option (cs, php)")
        sys.exit(1)

    # check if language exists
    if not FileManager.exist_language(language):
        print("Patch your language folder '{}'".format(language))
        sys.exit(1)

    # create generator for specified language
    g = Generator(date, language=language)

    # List of flaws
    flaw_list = g.get_group_list()
    cwe_list = g.get_cwe_list()

    flaw_group_user = [x.lower() for x in args["--flaw-group"]]
    for flaw in flaw_group_user:
        if flaw.lower() not in flaw_list:
            print(
                "There is no flaws associated with the given flaw group (-f {} option).\
                  See --help.".format(flaw.lower()))
            sys.exit(1)
    try:
        flaw_type_user = [int(x) for x in args["--cwe"]]
    except ValueError:
        print(
            "Invalid format. Value of the -c option must be an integer. See --help"
        )
        sys.exit(1)
    for cwe in flaw_type_user:
        if cwe not in cwe_list:
            print(
                "There is no flaws associated with the given CWE (-c {} option). See --help."
                .format(cwe))
            sys.exit(1)
    if args["--safe"]:
        safe = True
        unsafe = False
    if args["--unsafe"]:
        safe = False
        unsafe = True
    debug = args["--debug"]
    try:
        arg = args["--depth"]
        g.max_recursion = int(arg) if arg is not None else 1
    except ValueError:
        print(
            "Invalid format. Value of the -r option must be an integer. See --help"
        )
        sys.exit(1)
    try:
        arg = args["--number-generated"]
        g.number_generated = int(arg) if arg is not None else -1
    except ValueError:
        print(
            "Invalid format. Value of the -g option must be an integer. See --help"
        )
        sys.exit(1)

    # set user list
    g.set_flaw_type_user(flaw_type_user)
    g.set_flaw_group_user(flaw_group_user)

    # run generation
    g.generate(debug=debug, generate_safe=safe, generate_unsafe=unsafe)

    # check if astyle is here
    if os.path.isfile(ASTYLE_PATH):
        print("Indentation ...")
        cmd = ASTYLE_PATH + " -r TestSuite_" + date + "/*." + g.get_extension(
        ) + " --style=java --suffix=none --indent-switches -q"
        os.system(cmd)
    else:
        print("No indentation")

    print("Finish")