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
|
||||
from argparse import ArgumentParser
|
||||
from pathlib import Path
|
||||
|
||||
from panoramisk.actions import Action
|
||||
from subprocess import Popen
|
||||
|
||||
import asterisk_misc_common
|
||||
from panoramisk.actions import Action
|
||||
|
||||
log = logging.getLogger("ring")
|
||||
|
||||
STATEFILE = None
|
||||
ARGS = None
|
||||
|
||||
|
||||
async def run_app(Cls, manager):
|
||||
|
@ -72,14 +72,17 @@ class RingManager:
|
|||
def save(self, state):
|
||||
tmp = tempfile.NamedTemporaryFile(
|
||||
mode="w",
|
||||
dir=STATEFILE.parent.absolute(),
|
||||
dir=ARGS.state_file.parent.absolute(),
|
||||
prefix="statefile-",
|
||||
suffix=".json",
|
||||
delete=False,
|
||||
)
|
||||
json.dump(state, tmp)
|
||||
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):
|
||||
|
@ -108,18 +111,18 @@ async def on_shutdown(m):
|
|||
|
||||
|
||||
def main():
|
||||
global STATEFILE
|
||||
global ARGS
|
||||
p = ArgumentParser()
|
||||
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)
|
||||
args = p.parse_args()
|
||||
asterisk_misc_common.do_common_options(args)
|
||||
STATEFILE = args.state_file
|
||||
ARGS = p.parse_args()
|
||||
asterisk_misc_common.do_common_options(ARGS)
|
||||
|
||||
manager = asterisk_misc_common.get_manager(args)
|
||||
manager = asterisk_misc_common.get_manager(ARGS)
|
||||
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