mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2025-08-26 18:10:18 +08:00
40 lines
1.0 KiB
Python
Executable File
40 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3.4
|
|
"""This is a script to install git-lfs to a tempdir for use in tests"""
|
|
import io
|
|
import os.path
|
|
import shutil
|
|
import tarfile
|
|
from urllib.request import urlopen
|
|
|
|
DOWNLOAD_PATH = (
|
|
'https://github.com/github/git-lfs/releases/download/'
|
|
'v1.1.0/git-lfs-linux-amd64-1.1.0.tar.gz'
|
|
)
|
|
PATH_IN_TAR = 'git-lfs-1.1.0/git-lfs'
|
|
DEST_PATH = '/tmp/git-lfs/git-lfs'
|
|
DEST_DIR = os.path.dirname(DEST_PATH)
|
|
|
|
|
|
def main():
|
|
if (
|
|
os.path.exists(DEST_PATH) and
|
|
os.path.isfile(DEST_PATH) and
|
|
os.access(DEST_PATH, os.X_OK)
|
|
):
|
|
print('Already installed!')
|
|
return 0
|
|
|
|
shutil.rmtree(DEST_DIR, ignore_errors=True)
|
|
os.makedirs(DEST_DIR, exist_ok=True)
|
|
|
|
contents = io.BytesIO(urlopen(DOWNLOAD_PATH).read())
|
|
with tarfile.open(fileobj=contents) as tar:
|
|
with tar.extractfile(PATH_IN_TAR) as src_file:
|
|
with open(DEST_PATH, 'wb') as dest_file:
|
|
shutil.copyfileobj(src_file, dest_file)
|
|
os.chmod(DEST_PATH, 0o755)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
exit(main())
|