mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-30 18:26:53 +00:00
42 lines
1.1 KiB
Python
Executable file
42 lines
1.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""This is a script to install git-lfs to a tempdir for use in tests"""
|
|
import io
|
|
import os.path
|
|
import shutil
|
|
import tarfile
|
|
import urllib.request
|
|
from typing import cast
|
|
from typing import IO
|
|
|
|
DOWNLOAD_PATH = (
|
|
'https://github.com/github/git-lfs/releases/download/'
|
|
'v2.2.1/git-lfs-linux-amd64-2.2.1.tar.gz'
|
|
)
|
|
PATH_IN_TAR = 'git-lfs-2.2.1/git-lfs'
|
|
DEST_PATH = '/tmp/git-lfs/git-lfs'
|
|
DEST_DIR = os.path.dirname(DEST_PATH)
|
|
|
|
|
|
def main(): # type: () -> int
|
|
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(urllib.request.urlopen(DOWNLOAD_PATH).read())
|
|
with tarfile.open(fileobj=contents) as tar:
|
|
with cast(IO[bytes], 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)
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
exit(main())
|