-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_nids.py
executable file
·61 lines (47 loc) · 1.62 KB
/
test_nids.py
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
61
#!/usr/bin/env python
# Copyright (c) 2015-2016 University Corporation for Atmospheric Research/Unidata
# Distributed under the terms of the MIT License.
# SPDX-License-Identifier: MIT
from datetime import datetime
import struct
import boto3
meta_struct = struct.Struct('6IQiII')
len_struct = struct.Struct('I')
def write_str(fobj, s):
fobj.write(len_struct.pack(len(s)))
fobj.write(s.encode('ascii'))
def write_product(out):
bucket = boto3.session.Session().resource('s3').Bucket('unidata-nexrad-level3')
obj = bucket.Object('RAX_NST_2020_04_12_22_01_33')
block = obj.get()['Body'].read()
prod_id = 'SDUS55 KBOU 280701 /pNCRFTG'
origin = 'foobar'
out.write(meta_struct.pack(meta_struct.size + 2 * len_struct.size + len(prod_id) + len(origin),
1, 2, 3, 4, len(block), 1, 1, 1, 2))
write_str(out, prod_id)
write_str(out, origin)
out.write(block)
out.flush()
if __name__ == '__main__':
import subprocess
import sys
import time
timeout = False
sig_hup = False
if len(sys.argv) > 1:
if sys.argv[1] == 'timeout':
timeout = True
elif sys.argv[1] == 'hup':
sig_hup = True
proc = subprocess.Popen(['./upload_nids.py', '-vv', '-b', 'foo'],
stdout=sys.stdout, stdin=subprocess.PIPE, universal_newlines=False,
bufsize=40)
write_product(proc.stdin)
for chunk in range(2, 3):
write_product(proc.stdin)
time.sleep(0.25)
proc.stdin.flush()
if timeout:
time.sleep(timeout + 15)
proc.stdin.close()
proc.wait()