mirror of
https://github.com/oskar456/dzonegit.git
synced 2024-05-11 05:55:41 +00:00
Add deamon reload support
This commit is contained in:
74
dzonegit.py
74
dzonegit.py
@ -3,6 +3,7 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import shlex
|
||||
import re
|
||||
import time
|
||||
import datetime
|
||||
@ -399,30 +400,33 @@ def post_receive(stdin=sys.stdin):
|
||||
added or delefed.
|
||||
"""
|
||||
suffixes = list(str(n) if n else "" for n in range(10))
|
||||
checkoutpath = get_config("dzonegit.checkoutpath")
|
||||
blacklist = load_set_file(get_config("dzonegit.zoneblacklist"))
|
||||
whitelist = load_set_file(get_config("dzonegit.zonewhitelist"))
|
||||
if checkoutpath:
|
||||
print("Checking out repository into {}…".format(checkoutpath))
|
||||
subprocess.run(
|
||||
["git", "checkout", "-f", "master"],
|
||||
check=True,
|
||||
env=dict(os.environ, GIT_WORK_TREE=checkoutpath),
|
||||
checkoutpath = get_config("dzonegit.checkoutpath")
|
||||
if not checkoutpath:
|
||||
raise SystemExit("Checkout path not defined. Nothing to do.")
|
||||
|
||||
print("Checking out repository into {}…".format(checkoutpath))
|
||||
subprocess.run(
|
||||
["git", "checkout", "-f", "master"],
|
||||
check=True,
|
||||
env=dict(os.environ, GIT_WORK_TREE=checkoutpath),
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
for s in suffixes:
|
||||
cfpath = get_config("dzonegit.conffilepath{}".format(s))
|
||||
tplpath = get_config("dzonegit.conffiletemplate{}".format(s))
|
||||
if cfpath is None or tplpath is None:
|
||||
continue
|
||||
print("Templating config file {}…".format(cfpath))
|
||||
Path(cfpath).write_text(
|
||||
template_config(
|
||||
checkoutpath,
|
||||
Path(tplpath).read_text(),
|
||||
blacklist=blacklist,
|
||||
whitelist=whitelist,
|
||||
),
|
||||
)
|
||||
for s in suffixes:
|
||||
cfpath = get_config("dzonegit.conffilepath{}".format(s))
|
||||
tplpath = get_config("dzonegit.conffiletemplate{}".format(s))
|
||||
if cfpath is None or tplpath is None:
|
||||
continue
|
||||
print("Templating config file {}…".format(cfpath))
|
||||
Path(cfpath).write_text(
|
||||
template_config(
|
||||
checkoutpath,
|
||||
Path(tplpath).read_text(),
|
||||
blacklist=blacklist,
|
||||
whitelist=whitelist,
|
||||
),
|
||||
)
|
||||
|
||||
if stdin.isatty():
|
||||
raise SystemExit(
|
||||
@ -435,7 +439,33 @@ def post_receive(stdin=sys.stdin):
|
||||
continue
|
||||
if against == "0000000000000000000000000000000000000000":
|
||||
against = get_head() # Empty commit
|
||||
# TODO reloads
|
||||
should_reconfig = [
|
||||
f for f in get_altered_files(against, "ACDRU", revision)
|
||||
if f.suffix == ".zone"
|
||||
]
|
||||
zones_to_reload = [
|
||||
get_zone_name(f, (checkoutpath / f).read_bytes())
|
||||
for f in get_altered_files(against, "M", revision)
|
||||
if f.suffix == ".zone"
|
||||
]
|
||||
if should_reconfig:
|
||||
print("Zone list change detected, reloading configuration")
|
||||
for s in suffixes:
|
||||
reconfigcmd = get_config("dzonegit.reconfigcmd{}".format(s))
|
||||
if reconfigcmd:
|
||||
print("Calling {}…".format(reconfigcmd))
|
||||
subprocess.run(reconfigcmd, shell=True)
|
||||
|
||||
for z in zones_to_reload:
|
||||
for s in suffixes:
|
||||
zonereloadcmd = get_config(
|
||||
"dzonegit.zonereloadcmd{}".format(s),
|
||||
)
|
||||
if zonereloadcmd:
|
||||
cmd = shlex.split(zonereloadcmd)
|
||||
cmd.append(z)
|
||||
print("Calling {}…".format(" ".join(cmd)))
|
||||
subprocess.run(cmd)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -261,7 +261,10 @@ def test_update(git_dir):
|
||||
|
||||
def test_pre_receive(git_dir):
|
||||
git_dir.chdir()
|
||||
revisions = "{} {} ".format("0"*40, dzonegit.get_head())
|
||||
revisions = "{} {} ".format(
|
||||
"4b825dc642cb6eb9a060e54bf8d69288fbee4904",
|
||||
dzonegit.get_head(),
|
||||
)
|
||||
stdin = StringIO(revisions + "refs/heads/slave\n")
|
||||
with pytest.raises(SystemExit):
|
||||
dzonegit.pre_receive(stdin)
|
||||
@ -271,12 +274,21 @@ def test_pre_receive(git_dir):
|
||||
|
||||
def test_post_receive(git_dir):
|
||||
git_dir.chdir()
|
||||
revisions = "{} {} ".format("0"*40, dzonegit.get_head())
|
||||
stdin = StringIO(revisions + "refs/heads/master\n")
|
||||
head = dzonegit.get_head()
|
||||
revisions = "{} {} refs/heads/master\n".format(
|
||||
"4b825dc642cb6eb9a060e54bf8d69288fbee4904",
|
||||
head,
|
||||
)
|
||||
stdin = StringIO(revisions)
|
||||
codir = git_dir.mkdir("co")
|
||||
subprocess.call(["git", "config", "dzonegit.checkoutpath", str(codir)])
|
||||
subprocess.call([
|
||||
"git", "config", "dzonegit.reconfigcmd",
|
||||
"echo TEST >{}/test".format(codir),
|
||||
])
|
||||
dzonegit.post_receive(stdin)
|
||||
assert codir.join("dummy.zone").check()
|
||||
assert codir.join("test").read() == "TEST\n"
|
||||
|
||||
|
||||
def test_template_config(git_dir):
|
||||
|
Reference in New Issue
Block a user