Gitlab will migrate to a new storage backend starting 0300 UTC on 2020-04-04. We do not anticipate a maintenance window for this migration. Performance may be impacted over the weekend. Thanks for your patience.

update-channel-list 1.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#!/usr/bin/env python3

import os
import sys
import nds2


HOSTPORT = os.getenv('NDSSERVER', 'nds.ligo.caltech.edu:31200').split(',')[0].split(':')
HOST = HOSTPORT[0]
if len(HOSTPORT) == 1:
    PORT = 31200
else:
    PORT = int(HOSTPORT[1])
CACHE_DIR = os.path.expanduser('~/.cache/ligo-channel-list')
NDS_CHAN_LIST = os.getenv('NDS_CHAN_LIST', os.path.join(CACHE_DIR, 'nds-chan-list.txt'))
EPICS_CHAN_LIST = os.getenv('EPICS_CHAN_LIST', os.path.join(CACHE_DIR, 'epics-chan-list.txt'))


def main():
    if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']:
        print("""Update channel file lists for use with ligo_channel_completion.

Downloads the channel list from NDS and updates the NDS and EPICS
channel list files.  Uses the server specified in the NDSSERVER
environment variable, or 'nds.ligo.caltech.edu:31200' if not
specified.  If the NDS_CHAN_LIST and EPICS_CHAN_LIST variables exist
they are assumed to be the paths to files to be updated.  Otherwise
the files are updated in the default cache locations:

NDS_CHAN_LIST={}
EPICS_CHAN_LIST={}

Export these variables to your environment for bash channel
completion.""".format(NDS_CHAN_LIST, EPICS_CHAN_LIST))
        sys.exit()

    params = nds2.parameters(HOST, PORT)

    chans = nds2.find_channels(
        channel_type_mask=nds2.channel.CHANNEL_TYPE_RAW,
        params=params,
    )

    os.makedirs(os.path.dirname(NDS_CHAN_LIST), exist_ok=True)
    os.makedirs(os.path.dirname(EPICS_CHAN_LIST), exist_ok=True)

    f_nds = open(NDS_CHAN_LIST+'.tmp', 'w')
    f_epics = open(EPICS_CHAN_LIST+'.tmp', 'w')

    for chan in sorted(chans, key=lambda c: c.name):
        f_nds.write(chan.name+'\n')
        if chan.sample_rate == 16:
            f_epics.write(chan.name+'\n')

    os.rename(NDS_CHAN_LIST+'.tmp', NDS_CHAN_LIST)
    os.rename(EPICS_CHAN_LIST+'.tmp', EPICS_CHAN_LIST)


if __name__ == '__main__':
    main()