コード例 #1
0
ファイル: pre_commit.py プロジェクト: joshmoore/captainhook
def main(commit_only=True):
    """
    Run the configured code checks.

    Return system exit code.
        1 - reject commit
        0 - accept commit
    """
    global TEMP_FOLDER
    exit_code = 0
    hook_checks = HookConfig('tox.ini')
    with files_to_check(commit_only) as files:
        for name, mod in checks():
            default = getattr(mod, 'DEFAULT', 'off')
            if hook_checks.is_enabled(name, default=default):
                if hasattr(mod, 'REQUIRED_FILES'):
                    for filename in mod.REQUIRED_FILES:
                        if os.path.isfile(filename):
                            shutil.copy(filename, TEMP_FOLDER)
                args = hook_checks.arguments(name)
                if args:
                    errors = mod.run(files, TEMP_FOLDER, args)
                else:
                    errors = mod.run(files, TEMP_FOLDER)
                if errors:
                    title_print("Checking {0}".format(name))
                    print((errors.replace(TEMP_FOLDER + "/", '')))
                    print("")
                    exit_code = 1

    if exit_code == 1:
        title_print("Rejecting commit")
    return exit_code
コード例 #2
0
ファイル: pre_commit.py プロジェクト: koddsson/captainhook
def main():
    """
    Run the configured code checks.

    Return system exit code.
        1 - reject commit
        0 - accept commit
    """
    global TEMP_FOLDER
    exit_code = 0
    hook_checks = HookConfig('tox.ini')
    with gitstash():
        for name, mod in checks():
            default = getattr(mod, 'DEFAULT', 'off')
            if hook_checks.is_enabled(name, default=default):
                args = hook_checks.arguments(name)
                if args:
                    errors = mod.run(args)
                else:
                    errors = mod.run()
                if errors:
                    title_print("Checking {0}".format(name))
                    print(errors.replace(TEMP_FOLDER + "/", ''))
                    exit_code = 1

    if exit_code == 1:
        title_print("Rejecting commit")
    return exit_code
コード例 #3
0
def main(commit_only=True):
    """
    Run the configured code checks.

    Return system exit code.
        1 - reject commit
        0 - accept commit
    """
    global TEMP_FOLDER
    exit_code = 0
    hook_checks = HookConfig('tox.ini')
    with files_to_check(commit_only) as files:
        for name, mod in checks():
            default = getattr(mod, 'DEFAULT', 'off')
            if hook_checks.is_enabled(name, default=default):
                if hasattr(mod, 'REQUIRED_FILES'):
                    for filename in mod.REQUIRED_FILES:
                        if os.path.isfile(filename):
                            shutil.copy(filename, TEMP_FOLDER)
                args = hook_checks.arguments(name)
                if args:
                    errors = mod.run(files, TEMP_FOLDER, args)
                else:
                    errors = mod.run(files, TEMP_FOLDER)
                if errors:
                    title_print("Checking {0}".format(name))
                    print((errors.replace(TEMP_FOLDER + "/", '')))
                    print("")
                    exit_code = 1

    if exit_code == 1:
        title_print("Rejecting commit")
    return exit_code