ring has on_save hook
This commit is contained in:
parent
e3d25bbdb8
commit
b654700ccf
1 changed files with 14 additions and 11 deletions
|
@ -5,14 +5,14 @@ import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from subprocess import Popen
|
||||||
from panoramisk.actions import Action
|
|
||||||
|
|
||||||
import asterisk_misc_common
|
import asterisk_misc_common
|
||||||
|
from panoramisk.actions import Action
|
||||||
|
|
||||||
log = logging.getLogger("ring")
|
log = logging.getLogger("ring")
|
||||||
|
|
||||||
STATEFILE = None
|
ARGS = None
|
||||||
|
|
||||||
|
|
||||||
async def run_app(Cls, manager):
|
async def run_app(Cls, manager):
|
||||||
|
@ -72,14 +72,17 @@ class RingManager:
|
||||||
def save(self, state):
|
def save(self, state):
|
||||||
tmp = tempfile.NamedTemporaryFile(
|
tmp = tempfile.NamedTemporaryFile(
|
||||||
mode="w",
|
mode="w",
|
||||||
dir=STATEFILE.parent.absolute(),
|
dir=ARGS.state_file.parent.absolute(),
|
||||||
prefix="statefile-",
|
prefix="statefile-",
|
||||||
suffix=".json",
|
suffix=".json",
|
||||||
delete=False,
|
delete=False,
|
||||||
)
|
)
|
||||||
json.dump(state, tmp)
|
json.dump(state, tmp)
|
||||||
tmp.close()
|
tmp.close()
|
||||||
Path(tmp.name).rename(STATEFILE)
|
Path(tmp.name).rename(ARGS.state_file)
|
||||||
|
self.log.info("renamed")
|
||||||
|
if ARGS.on_save is not None:
|
||||||
|
Popen([str(ARGS.on_save.resolve())])
|
||||||
|
|
||||||
|
|
||||||
def refresh(manager, *args):
|
def refresh(manager, *args):
|
||||||
|
@ -108,18 +111,18 @@ async def on_shutdown(m):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global STATEFILE
|
global ARGS
|
||||||
p = ArgumentParser()
|
p = ArgumentParser()
|
||||||
p.add_argument("--state-file", type=Path, default=Path("./ring-state.json"))
|
p.add_argument("--state-file", type=Path, default=Path("./ring-state.json"))
|
||||||
|
p.add_argument("--on-save", type=Path, default=None)
|
||||||
|
|
||||||
asterisk_misc_common.add_arguments(p)
|
asterisk_misc_common.add_arguments(p)
|
||||||
args = p.parse_args()
|
ARGS = p.parse_args()
|
||||||
asterisk_misc_common.do_common_options(args)
|
asterisk_misc_common.do_common_options(ARGS)
|
||||||
STATEFILE = args.state_file
|
|
||||||
|
|
||||||
manager = asterisk_misc_common.get_manager(args)
|
manager = asterisk_misc_common.get_manager(ARGS)
|
||||||
asterisk_misc_common.run_manager(
|
asterisk_misc_common.run_manager(
|
||||||
manager, args, on_startup=init, on_shutdown=on_shutdown
|
manager, ARGS, on_startup=init, on_shutdown=on_shutdown
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue