-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
49 lines (39 loc) · 1.18 KB
/
setup.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
import pathlib
import platform
import os
import stat
import re
text = '''#!/bin/sh
# update leaderboard before commit
python3 leaderboard.py
git add leaderboard.json
'''
COOKIE_FILE = 'cookies'
if platform.system() == 'Windows':
text = text.replace('python3', 'python')
path = pathlib.Path('.git/hooks/pre-commit')
fp = open(path, 'w')
fp.write(text)
fp.close()
if platform.system() != 'Windows':
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IEXEC)
def write_cookies(new_cookies):
with open(COOKIE_FILE, 'w') as output_file:
output_file.write(new_cookies)
cookies = "empty"
wrong = False
while not (re.match("session=[a-z0-9]*", cookies) or cookies == ""):
if wrong:
print("This isn't a valid cookie please retry")
wrong = True
try:
with open(COOKIE_FILE, "r") as input_file:
current = input_file.readlines()[0]
cookies = input("New cookies (press ENTER to keep current): ")
except (IndexError, FileNotFoundError):
cookies = input("Cookies not found, enter your session cookies: ")
cookies = cookies.strip("Cookie: ")
if cookies != "":
write_cookies(cookies)
print("Hooks setup finished!")