File indexing completed on 2026-11-09 10:47:25
0001
0002 """sysconfig-set.py — set one SysConfig key, the single-key counterpart
0003 of the System page editor (monitor_app.viewdir.system_status.sysconfig_save),
0004 recorded the same way: one ``sysconfig_edit`` action-stream event carrying
0005 the key, the previous and new values, the editor and the reason.
0006
0007 cd /data/wenauseic/github/swf-monitor/src
0008 source ../../swf-testbed/.venv/bin/activate && source ~/.env
0009 python ../scripts/sysconfig-set.py front.jedi_throttled false \
0010 --by wenaus --comment "the JEDI throttler observes; the front keeps its own caps"
0011
0012 The value is parsed as JSON (``false``, ``8.0``, ``"active"``, ``[...]``);
0013 a value that is not JSON is stored as a string. ``--dry-run`` prints the
0014 change and writes nothing. Exit 1 on failure.
0015 """
0016 import argparse
0017 import json
0018 import os
0019 import sys
0020
0021 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0022 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0023 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0024
0025 import django
0026 django.setup()
0027
0028 from monitor_app.epicprod_logging import log_epicprod_action
0029 from monitor_app.models import SysConfig
0030
0031
0032 def main():
0033 parser = argparse.ArgumentParser()
0034 parser.add_argument('key')
0035 parser.add_argument('value')
0036 parser.add_argument('--by', required=True, help='the editor recorded on the change')
0037 parser.add_argument('--comment', required=True, help='why the key changes')
0038 parser.add_argument('--dry-run', action='store_true')
0039 args = parser.parse_args()
0040
0041 try:
0042 value = json.loads(args.value)
0043 except ValueError:
0044 value = args.value
0045 config = SysConfig.get_config()
0046 present = args.key in config
0047 previous = config.get(args.key)
0048 print(json.dumps({'key': args.key, 'present': present, 'previous': previous,
0049 'value': value, 'by': args.by, 'dry_run': args.dry_run}))
0050 if args.dry_run:
0051 return 0
0052 SysConfig.update_config({args.key: value}, username=args.by)
0053 log_epicprod_action(
0054 'web', 'sysconfig_edit', username=args.by,
0055 sublevel='high', live_default=True,
0056 keys=[args.key], key=args.key, previous=previous, value=value,
0057 comment=args.comment,
0058 message=f'sysconfig_edit {args.key}: {previous!r} -> {value!r}: {args.comment}',
0059 )
0060 after = SysConfig.get_config().get(args.key)
0061 if after != value:
0062 print(f'ERROR: {args.key} reads {after!r} after the write', file=sys.stderr)
0063 return 1
0064 print(f'{args.key} = {after!r}')
0065 return 0
0066
0067
0068 if __name__ == '__main__':
0069 sys.exit(main())