Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-26 08:40:22

0001 #!/usr/bin/env python3
0002 """import_evgen_rucio.py — assimilate the JLab Rucio EVGEN inventory into PCS.
0003 
0004 Fetches ``epic:/EVGEN/*`` from JLab Rucio, saves a snapshot, and resolves each
0005 PCS evgen Dataset to the Rucio EVGEN dataset(s) that realize it — matching on
0006 the shared filter axes (beam, physics, Q² overlap), never on path strings.
0007 One abstract request (``minQ2=N``) can resolve to several Q²-range datasets.
0008 Re-running picks up a grown Rucio listing in the same way.
0009 
0010 Dry run by default (no DB writes); pass ``--apply`` to persist
0011 ``metadata['rucio']`` onto the matched Datasets.
0012 
0013 Usage::
0014 
0015     cd /data/wenauseic/github/swf-monitor/src
0016     source ../../swf-testbed/.venv/bin/activate && source ~/.env
0017     python ../scripts/import_evgen_rucio.py            # dry run
0018     python ../scripts/import_evgen_rucio.py --apply    # persist
0019 """
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 pcs.services import refresh_evgen_rucio, ServiceError  # noqa: E402
0031 
0032 
0033 def main(argv):
0034     apply = '--apply' in argv[1:]
0035     print('EVGEN Rucio assimilation' + (' (APPLY)' if apply else ' (dry run)'))
0036     try:
0037         s = refresh_evgen_rucio(apply=apply)
0038     except ServiceError as e:
0039         print(f'ERROR: {e}', file=sys.stderr)
0040         return 1
0041     print(f"  rucio EVGEN datasets:   {s['rucio_evgen']}")
0042     print(f"  PCS evgen datasets:     {s['datasets_seen']}")
0043     print(f"  matched:                {s['datasets_matched']}")
0044     print(f"  unmatched (PCS):        {s['datasets_unmatched']}")
0045     print(f"  unmatched (Rucio):      {s['rucio_unmatched']}")
0046     print(f"  snapshot:               {s['snapshot_path']}")
0047     for ex in s.get('samples', []):
0048         print(f"    {ex['request']}")
0049         for d in ex['matched']:
0050             print(f"        -> {d}")
0051     if s['errors']:
0052         print(f"  errors: {len(s['errors'])}")
0053         for e in s['errors'][:10]:
0054             print(f"    - {e}")
0055     return 0
0056 
0057 
0058 if __name__ == '__main__':
0059     sys.exit(main(sys.argv))