|
@@ -22,7 +22,7 @@ python "D:\dev\websites\sandpoints-dev\custom_syadmin\git_hooks_post-receive.py" |
|
|
|
|
|
|
|
|
Just a mental note to read refs from the post-receive hook like this:
|
|
|
Just a mental note to read refs from the post-receive hook like this:
|
|
|
|
|
|
|
|
|
oldrev,newrev,refname = sys.stdin.readline().strip().split(’ ‘)
|
|
|
|
|
|
|
|
|
oldrev,newrev,refname = sys.stdin.readline().strip().split(' ')
|
|
|
|
|
|
|
|
|
"""
|
|
|
"""
|
|
|
import os
|
|
|
import os
|
|
@@ -84,14 +84,20 @@ def cmd(parts, cwd=None, env=None): |
|
|
return subprocess.check_output(parts, cwd=cwd, env=env, universal_newlines=True).strip()
|
|
|
return subprocess.check_output(parts, cwd=cwd, env=env, universal_newlines=True).strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rmrf(path):
|
|
|
|
|
|
|
|
|
def rmrf(path, keep_dir=False):
|
|
|
""" Use safe-rm for recursive removal """
|
|
|
""" Use safe-rm for recursive removal """
|
|
|
""" @TODO: make it safer """
|
|
|
""" @TODO: make it safer """
|
|
|
def remove_readonly(func, path, excinfo):
|
|
|
def remove_readonly(func, path, excinfo):
|
|
|
os.chmod(path, stat.S_IWRITE)
|
|
|
os.chmod(path, stat.S_IWRITE)
|
|
|
func(path)
|
|
|
func(path)
|
|
|
# Try removal
|
|
|
# Try removal
|
|
|
if os.path.exists(path) and len(os.path.realpath(path)) > 1:
|
|
|
|
|
|
|
|
|
if keep_dir and os.path.exists(path) and len(os.path.realpath(path)) > 1:
|
|
|
|
|
|
for root, dirs, files in os.walk(path):
|
|
|
|
|
|
for f in files:
|
|
|
|
|
|
os.unlink(os.path.join(root, f))
|
|
|
|
|
|
for d in dirs:
|
|
|
|
|
|
shutil.rmtree(os.path.join(root, d), onerror=remove_readonly)
|
|
|
|
|
|
elif os.path.exists(path) and len(os.path.realpath(path)) > 1:
|
|
|
shutil.rmtree(path, onerror=remove_readonly)
|
|
|
shutil.rmtree(path, onerror=remove_readonly)
|
|
|
else:
|
|
|
else:
|
|
|
print("Either the path doesn't exist or you are trying to delete the root directory(?!):", path)
|
|
|
print("Either the path doesn't exist or you are trying to delete the root directory(?!):", path)
|
|
@@ -115,9 +121,13 @@ def build_site(dest, tmp, branch=None, hugo_environment='gitea'): |
|
|
else:
|
|
|
else:
|
|
|
cmd([GIT_PATH, 'clone', '.', tmp], cwd=GIT_REPO)
|
|
|
cmd([GIT_PATH, 'clone', '.', tmp], cwd=GIT_REPO)
|
|
|
rmrf(os.path.join(tmp, '.git'))
|
|
|
rmrf(os.path.join(tmp, '.git'))
|
|
|
rmrf(dest)
|
|
|
|
|
|
|
|
|
rmrf(dest, keep_dir=True)
|
|
|
try:
|
|
|
try:
|
|
|
os.makedirs(dest, exist_ok=True)
|
|
|
|
|
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
|
|
os.makedirs(dest)
|
|
|
|
|
|
print("Build destination created: ", dest)
|
|
|
|
|
|
else:
|
|
|
|
|
|
print("Build destination exists: ", dest)
|
|
|
except:
|
|
|
except:
|
|
|
print(f"Error creating the directory: {dest}")
|
|
|
print(f"Error creating the directory: {dest}")
|
|
|
lcl = f'{tmp}/last-commit-log.txt'
|
|
|
lcl = f'{tmp}/last-commit-log.txt'
|
|
|