Simplify the install and uninstall commands and improve tests.

This commit is contained in:
Anthony Sottile 2014-03-23 18:33:18 -07:00
parent 48bbc68b35
commit ecdacd474b
7 changed files with 82 additions and 52 deletions

25
pre_commit/commands.py Normal file
View file

@ -0,0 +1,25 @@
import os
import pkg_resources
import stat
def install(runner):
"""Install the pre-commit hooks."""
pre_commit_file = pkg_resources.resource_filename('pre_commit', 'resources/pre-commit.sh')
with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:
pre_commit_file_obj.write(open(pre_commit_file).read())
original_mode = os.stat(runner.pre_commit_path).st_mode
os.chmod(
runner.pre_commit_path,
original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH,
)
return 0
def uninstall(runner):
"""Uninstall the pre-commit hooks."""
if os.path.exists(runner.pre_commit_path):
os.remove(runner.pre_commit_path)
return 0