-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.py
executable file
·76 lines (45 loc) · 1.5 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import os
import stat
from setup import logging
from config import base_dir
import argparse
def install_hooks():
files = os.listdir(os.path.join(base_dir, "hooks"))
file_permissions = (
stat.S_IRUSR |
stat.S_IWUSR |
stat.S_IXUSR |
stat.S_IRGRP |
stat.S_IWGRP |
stat.S_IXGRP
)
for file in files:
symlink_path = os.path.join(base_dir, f".git/hooks/{file[:-3]}")
file_path = os.path.join(base_dir, f"hooks/{file}")
if os.path.islink(symlink_path):
logging.info(f"{file}: Hook aready installed")
continue
os.chmod(file_path,file_permissions)
os.symlink(file_path, symlink_path)
logging.info("Hooks installed")
def uninstall_hooks():
files = os.listdir(os.path.join(base_dir, ".git/hooks"))
for file in files:
path = os.path.join(base_dir, f".git/hooks/{file}")
if os.path.islink(path):
os.unlink(path)
logging.info(f"Uninstalled {file}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="E-wallet repo git hooks installer",
add_help=True
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-i", "--install", action="store_true")
group.add_argument("-u", "--uninstall", action="store_true")
args = parser.parse_args()
if args.install:
install_hooks()
if args.uninstall:
uninstall_hooks()