Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# (c) Stefan Countryman, 2016-2019
3"""
4Tools for handling incoming alerts.
5"""
7import logging
8from copy import deepcopy
9from typing import Dict
10from llama.flags import FlagDict, FLAG_PRESETS
11from llama.utils import DEFAULT_RUN_DIR
12from llama.cli import parse_atom, CanonicalPathAction
14LOGGER = logging.getLogger(__name__)
17def flag_update_freeze_veto(flagdict: FlagDict, updatedict: Dict[str, str]):
18 """Update a ``flagdict`` for some event wit hthe given dictionary of new
19 flag values, but **IGNORE** any updates to the ``VETOED`` flag, since this
20 flag should usually be set manually (and this function is meant to be a way
21 to procedurally apply ``llama.flags.FLAG_PRESETS`` to an existing
22 ``llama.event.Event`` without accidentally vetoing or un-vetoing the
23 event)."""
24 updatedict = deepcopy(dict(updatedict)) # don't clobber
25 del updatedict['VETOED']
26 LOGGER.info("setting flags to %s (VETOED excluded)", updatedict)
27 LOGGER.info("old flags: %s", flagdict)
28 flagdict.update(updatedict)
29 LOGGER.info("flags updated to %s", flagdict)
32def flag_preset_freeze_veto(flagdict: FlagDict, presetname: str):
33 """Exactly like ``flag_update_freeze_veto``, but instead of providing the
34 dictionary of the flag value changes you want to apply, you provide the
35 name of the ``llama.flags.FLAG_PRESETS`` attribute you want to use. Just a
36 shortcut for getting that attribute manually that also logs the preset
37 choice."""
38 LOGGER.info("setting flags (except 'VETOED') to preset: %s", presetname)
39 flag_update_freeze_veto(flagdict, getattr(FLAG_PRESETS, presetname))
42class Parsers:
43 """Parsers for new trigger listeners."""
45 rundir = parse_atom("-r", "--rundir", action=CanonicalPathAction,
46 default=DEFAULT_RUN_DIR, help=f"""
47 Change the run directory (i.e. where new LLAMA triggers are saved by
48 the GCN handler) to this directory. Creates the directory if it does
49 not already exist. (default: {DEFAULT_RUN_DIR})""")