|
1 | | -# -*- coding: future_fstrings -*- |
2 | | -import sys |
3 | | -from scabha import config, parameters_dict, prun |
| 1 | +import os |
| 2 | +import sys |
| 3 | +import re |
| 4 | +import yaml |
| 5 | +import subprocess |
| 6 | +import shlex |
| 7 | +import glob |
4 | 8 |
|
| 9 | +CONFIG = os.environ['CONFIG'] |
| 10 | +INPUT = os.environ['INPUT'] |
| 11 | +OUTPUT = os.environ['OUTPUT'] |
| 12 | +MSDIR = os.environ['MSDIR'] |
| 13 | + |
| 14 | +with open(CONFIG, "r") as _std: |
| 15 | + cab = yaml.safe_load(_std) |
| 16 | + |
| 17 | +params = cab['parameters'] |
| 18 | +junk = cab["junk"] |
5 | 19 | args = [] |
6 | | -for name, value in parameters_dict.items(): |
| 20 | + |
| 21 | +for param in params: |
| 22 | + name = param['name'] |
| 23 | + value = param['value'] |
| 24 | + |
7 | 25 | if name == 'msname': |
8 | 26 | if isinstance(value, str): |
9 | 27 | mslist = value |
|
21 | 39 | value = '{0}asec'.format(value) |
22 | 40 |
|
23 | 41 | elif name in 'size trim nwlayers-for-size beam-shape channel-range interval'.split(): |
24 | | - if isinstance(value, (int, float)): |
25 | | - value = [value]*2 |
26 | | - elif isinstance(value, list): |
| 42 | + if isinstance(value, int): |
| 43 | + value = '{0} {0}'.format(value) |
| 44 | + elif hasattr(value, '__iter__'): |
27 | 45 | if len(value) == 1: |
28 | | - value = value*2 |
| 46 | + value.append(value[0]) |
| 47 | + value = ' '.join(map(str, value)) |
| 48 | + |
| 49 | + elif name in 'spws multiscale-scales pol'.split(): |
| 50 | + if hasattr(value, '__iter__'): |
| 51 | + value = ','.join(map(str, value)) |
29 | 52 |
|
30 | 53 | if value is True: |
31 | | - arg = [f'{config.prefix}{name}'] |
| 54 | + arg = '{0}{1}'.format(cab['prefix'], name) |
32 | 55 | else: |
33 | | - if isinstance(value, list): |
34 | | - value = list(map(str, value)) |
35 | | - elif isinstance(value, str): |
36 | | - value = value.split() |
37 | | - elif not isinstance(value, str): |
38 | | - value = [str(value)] |
39 | | - else: |
40 | | - value = [value] |
41 | | - arg = [f'{config.prefix}{name}' ] + value |
| 56 | + arg = '{0}{1} {2}'.format(cab['prefix'], name, value) |
42 | 57 |
|
43 | | - args += arg |
| 58 | + args.append(arg) |
44 | 59 |
|
45 | | -args = [config.binary] + args + [mslist] |
| 60 | +_runc = " ".join([cab["binary"]] + args + [mslist]) |
46 | 61 |
|
47 | | -if prun(args) is not 0: |
48 | | - sys.exit(1) |
| 62 | +try: |
| 63 | + subprocess.check_call(shlex.split(_runc)) |
| 64 | +finally: |
| 65 | + for item in junk: |
| 66 | + for dest in [OUTPUT, MSDIR]: # these are the only writable volumes in the container |
| 67 | + items = glob.glob("{dest}/{item}".format(**locals())) |
| 68 | + for f in items: |
| 69 | + if os.path.isfile(f): |
| 70 | + os.remove(f) |
| 71 | + elif os.path.isdir(f): |
| 72 | + shutil.rmtree(f) |
| 73 | + # Leave other types |
0 commit comments