Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-02 10:29:04

0001 #!/usr/bin/env python3
0002 """Put an informational line on Production now for a number of hours.
0003 
0004 Writes one ``prod_now_notice`` record to the epicprod action stream: the
0005 line's text, the hours it stands, and the page it links to. The comp
0006 snapshot shows it grey among the Production now lines until its hours
0007 have passed (COMP_SNAPSHOT.md, Report and errors). The text before its
0008 first ": " names what the line is about, as every Production now line's
0009 does.
0010 
0011     cd /data/wenauseic/github/swf-monitor/src
0012     ../../swf-testbed/.venv/bin/python ../scripts/prod-now-notice.py \\
0013         "Campaign 26.07: over a billion events delivered" --hours 24 \\
0014         --link "https://epic-devcloud.org/prod/pcs/plan/?campaign=26.07" --by wenaus
0015 """
0016 
0017 import argparse
0018 import json
0019 import logging
0020 import os
0021 import sys
0022 
0023 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0024 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0025 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0026 
0027 import django  # noqa: E402
0028 django.setup()
0029 
0030 from monitor_app.epicprod_logging import log_epicprod_action  # noqa: E402
0031 
0032 
0033 def main():
0034     logging.basicConfig(level=logging.INFO, stream=sys.stderr)
0035     parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
0036     parser.add_argument('text', help='the line, "<what it is about>: <what holds>"')
0037     parser.add_argument('--hours', type=float, required=True,
0038                         help='how long the line stands')
0039     parser.add_argument('--link', default='', help='the page the line opens')
0040     parser.add_argument('--by', required=True, help='the person putting it up')
0041     parser.add_argument('--dry-run', action='store_true',
0042                         help='print the record; write nothing')
0043     args = parser.parse_args()
0044 
0045     text = ' '.join(args.text.split())
0046     if not text or args.hours <= 0:
0047         logging.error('a line needs text and a positive number of hours')
0048         print(json.dumps({'ok': False, 'error': 'text and positive hours required'}))
0049         return 1
0050     fields = {'title': text, 'summary': text, 'hours': args.hours,
0051               'url': args.link, 'subject_type': 'prod_now',
0052               'subject_label': text.split(': ', 1)[0]}
0053     if args.dry_run:
0054         print(json.dumps({'ok': True, 'dry_run': True, **fields}))
0055         return 0
0056     log_id = log_epicprod_action(
0057         'prod-now', 'prod_now_notice', username=args.by,
0058         message=f'Production now: {text} ({args.hours:g} h)', **fields)
0059     if not log_id:
0060         logging.error('the prod_now_notice record was not written')
0061         print(json.dumps({'ok': False, 'error': 'record not written'}))
0062         return 1
0063     print(json.dumps({'ok': True, 'log_id': log_id, **fields}))
0064     return 0
0065 
0066 
0067 if __name__ == '__main__':
0068     sys.exit(main())