Skip to content

Commit 6452ac1

Browse files
authored
Merge pull request #72 from SpheMakh/prepare-0.2.5
Prepare release 0.2.5
2 parents 21236ce + 74b3edd commit 6452ac1

96 files changed

Lines changed: 6973 additions & 6379 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@
1313
* Add lwimager, wslcean, casa imagers (instead of a single imager image)
1414
* Add owlcat base image
1515
* Add container, docker image, and job loging
16+
17+
# 0.2.5
18+
- Improve hnadling of ctrl+c. Send terminate
19+
signal to container.
20+
- Improve handling of FITS images when predicting
21+
visibilities; allow for minimal FITS images.
22+
- Add clean fuction to help clean up after stimela
23+
- Improve/Fx logging of images and containers

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM stimela/base
2+
ADD . /Stimela
3+
WORKDIR /Stimela
4+
RUN pip install /Stimela

bin/stimela

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,4 @@ import stimela
1010
if not os.path.exists(stimela.LOG_HOME):
1111
os.mkdir(stimela.LOG_HOME)
1212

13-
if not os.path.exists(stimela.LOG_IMAGES):
14-
with open(stimela.LOG_IMAGES, "w") as std:
15-
pass
16-
17-
18-
if not os.path.exists(stimela.LOG_CONTAINERS):
19-
with open(stimela.LOG_CONTAINERS, "w") as std:
20-
pass
21-
22-
if not os.path.exists(stimela.LOG_PROCESS):
23-
with open(stimela.LOG_PROCESS, "w") as std:
24-
pass
25-
26-
if not os.path.exists(stimela.LOG_CABS):
27-
with open(stimela.LOG_CABS, "w") as std:
28-
pass
29-
3013
stimela.main([a for a in sys.argv[1:]])

examples/simulation_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"telescope" : "meerkat", # Telescope name
2525
"direction" : "J2000,0deg,-30deg", # Phase tracking centre of observation
2626
"synthesis" : 0.125, # Synthesis time of observation
27-
"dtime" : 30, # Exposure time
27+
"dtime" : 4, # Integration time in seconds
2828
"freq0" : "750MHz", # Start frequency of observation
2929
"dfreq" : "1MHz", # Channel width
3030
"nchan" : 1 # Number of channels

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
except ImportError as e:
88
from distutils.core import setup
99

10-
import stimela_version
10+
from stimela_misc import version
1111

1212
setup(name = "stimela",
13-
version = stimela_version.version,
13+
version = version.version,
1414
description = "Dockerized radio interferometry scripting framework",
1515
author = "Sphesihle Makhathini",
1616
author_email = "Sphesihle Makhathini <sphemakh@gmail.com>",
1717
url = "https://github.com/sphemakh/Stimela",
18-
packages = ["stimela","stimela_version", "stimela/cargo","stimela/utils", "stimela/cargo/cab"],
18+
packages = ["stimela","stimela_misc", "stimela/cargo","stimela/utils", "stimela/cargo/cab"],
1919
package_data = { "stimela/cargo" : ["cab/*/Dockerfile",
2020
"base/*/Dockerfile",
2121
"cab/*/src/*.py",

stimela/__init__.py

Lines changed: 114 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
from recipe import Recipe, PipelineException
1717
from stimela import docker
1818

19-
from stimela.utils import stimela_logger
19+
from stimela.utils import logger
2020

2121
LOG_HOME = os.path.expanduser("~/.stimela")
22-
LOG_IMAGES = LOG_HOME + "/stimela_images.log"
23-
LOG_CONTAINERS = LOG_HOME + "/stimela_containers.log"
24-
LOG_PROCESS = LOG_HOME + "/stimela_process.log"
25-
LOG_CABS = LOG_HOME + "/stimela_cab.log"
22+
LOG_FILE = LOG_HOME + "/stimela_logfile.json"
2623

2724

2825
BASE = os.listdir(cargo.BASE_PATH)
@@ -83,13 +80,18 @@ def build(argv):
8380
help="Do not use cache when building the image")
8481

8582
args = parser.parse_args(argv)
83+
log = logger.StimelaLogger(LOG_FILE)
8684

8785
if args.base:
8886
for image in BASE:
8987
dockerfile = "{:s}/{:s}".format(cargo.BASE_PATH, image)
9088
image = "stimela/{0}:{1}".format(image, __version__)
9189
docker.build(image,
9290
dockerfile)
91+
92+
log.log_image(image, replace=True)
93+
log.write()
94+
9395
return 0
9496

9597
workdir = "/home/{}/output/".format(USER)
@@ -101,6 +103,7 @@ def build(argv):
101103

102104
no_cache = ["--no-cache"] if args.no_cache else []
103105

106+
104107
if args.cab:
105108
cab_args = args.cab.split(",")
106109

@@ -115,15 +118,10 @@ def build(argv):
115118
path,
116119
build_args=build_args, args=no_cache)
117120

118-
img = stimela_logger.Image(LOG_CABS)
119-
img.add(dict(name=cab))
120-
img.write()
121+
log.log_image(image, replace=True, cab=True)
122+
log.write()
121123
return
122124

123-
# clear old cabs
124-
img = stimela_logger.Image(LOG_CABS)
125-
img.clear()
126-
127125
for image in CAB:
128126
IGNORE = args.ignore_cabs.split(",")
129127
if image in NOT_PUBLIC+IGNORE:
@@ -135,9 +133,9 @@ def build(argv):
135133
dockerfile,
136134
build_args=build_args, args=no_cache)
137135

138-
img.add(dict(name=image))
136+
log.log_image(image, replace=True, cab=True)
137+
log.write()
139138

140-
img.write()
141139

142140

143141
def info(cabname, header=False):
@@ -206,7 +204,6 @@ def run(argv):
206204
args = parser.parse_args(argv)
207205
tag = None
208206

209-
210207
_globals = dict(STIMELA_INPUT=args.input, STIMELA_OUTPUT=args.output,
211208
STIMELA_MSDIR=args.msdir,
212209
CAB_TAG=tag)
@@ -248,14 +245,14 @@ def pull(argv):
248245
help="Tag")
249246

250247
args = parser.parse_args(argv)
248+
log = logger.StimelaLogger(LOG_FILE)
251249

252250
if args.image:
253251
for image in args.image:
254-
img = stimela_logger.Image(LOG_IMAGES)
255252

256253
if not img.find(image):
257254
docker.pull(image)
258-
img.add(dict(name=image, tag=tagargs.tag))
255+
log.log_image(image)
259256
else:
260257

261258
base = []
@@ -266,11 +263,11 @@ def pull(argv):
266263
base = set(base)
267264

268265
for image in base:
269-
img = stimela_logger.Image(LOG_IMAGES)
270-
271-
if not img.find(image) and image not in ["stimela/ddfacet", "radioastro/ddfacet"]:
266+
if image not in ["stimela/ddfacet", "radioastro/ddfacet"]:
272267
docker.pull(image)
273-
img.add(dict(name=image, tag=args.tag))
268+
log.log_image(image)
269+
270+
log.write()
274271

275272

276273
def images(argv):
@@ -282,15 +279,16 @@ def images(argv):
282279
add = parser.add_argument
283280

284281
add("-c", "--clear", action="store_true",
285-
help="Clear images log file")
282+
help="Clear the logfile that keeps track of stimela images. This does not do anythig to the images.")
286283

287284
args = parser.parse_args(argv)
288285

289-
img = stimela_logger.Image(stimela.LOG_IMAGES)
290-
img.display()
286+
log = logger.StimelaLogger(LOG_FILE)
287+
log.display('images')
291288

292289
if args.clear:
293-
img.clear()
290+
log.clear('images')
291+
log.write()
294292

295293

296294
def containers(argv):
@@ -302,14 +300,15 @@ def containers(argv):
302300
add = parser.add_argument
303301

304302
add("-c", "--clear", action="store_true",
305-
help="Clear containers log file")
303+
help="Clear the log file that keeps track of stimela containers. This doesn't do anything to the containers.")
306304

307305
args = parser.parse_args(argv)
308306

309-
conts = stimela_logger.Container(stimela.LOG_CONTAINERS)
310-
conts.display()
307+
log = logger.StimelaLogger(LOG_FILE)
308+
log.display('containers')
311309
if args.clear:
312-
conts.clear()
310+
log.clear('containers')
311+
log.write()
313312

314313

315314
def ps(argv):
@@ -321,14 +320,15 @@ def ps(argv):
321320
add = parser.add_argument
322321

323322
add("-c", "--clear", action="store_true",
324-
help="Clear Log file")
323+
help="Clear logfile that keeps track of stimela processes. This doesn't do anything ot the processes themselves.")
325324

326325
args = parser.parse_args(argv)
327326

328-
procs = stimela_logger.Process(stimela.LOG_PROCESS)
329-
procs.display()
327+
log = logger.StimelaLogger(LOG_FILE)
328+
log.display('processes')
330329
if args.clear:
331-
procs.clear()
330+
log.clear('processes')
331+
log.write()
332332

333333

334334
def kill(argv):
@@ -344,42 +344,96 @@ def kill(argv):
344344

345345
args = parser.parse_args(argv)
346346

347-
procs = stimela_logger.Process(LOG_PROCESS)
347+
log = logger.StimelaLogger(LOG_FILE)
348348

349-
for pid in map(int, args.pid):
349+
for pid in args.pid:
350350

351-
found = procs.find(pid)
351+
found = pid in log.info['processes'].keys()
352352

353353
if not found:
354-
print "Could not find process {0}".format(pid)
354+
print("Could not find process {0}".format(pid))
355355
continue
356356

357-
conts = stimela_logger.Container(LOG_CONTAINERS)
358-
lines = []
357+
try:
358+
os.kill(int(pid), signal.SIGINT)
359+
except OSError:
360+
raise OSError('Process with PID {} could not be killed'.format(pid))
361+
362+
log.remove('processes', pid)
363+
log.write()
359364

360-
procs.rm(pid)
361-
procs.write()
362365

363-
for cont in conts.lines:
364-
if cont.find(str(pid)) > 0:
365-
lines.append(cont)
366+
def clean(argv):
367+
for i, arg in enumerate(argv):
368+
if (arg[0] == '-') and arg[1].isdigit(): argv[i] = ' ' + arg
366369

367-
for line in lines:
368-
cont, _id, utime, _pid, status = line.split()
369-
if status.find("removed")<0:
370-
cont_ = docker.Container(None, cont, None, None)
371-
cont_.started = True
372-
cont_.stop()
373-
cont_.remove()
370+
parser = ArgumentParser(description='Convience tools for cleaning up after stimela')
371+
add = parser.add_argument
374372

375-
conts.rm(line)
373+
add("-ai", "--all-images", action="store_true",
374+
help="Remove all images pulled/built by stimela. This include CAB images")
375+
376+
add("-ab", "--all-base", action="store_true",
377+
help="Remove all base images")
376378

377-
conts.write()
379+
add("-ac", "--all-cabs", action="store_true",
380+
help="Remove all CAB images")
381+
382+
add("-aC", "--all-containers", action="store_true",
383+
help="Stop and/or Remove all stimela containers")
384+
385+
args = parser.parse_args(argv)
386+
387+
log = logger.StimelaLogger(LOG_FILE)
388+
389+
if args.all_images:
390+
images = log.info['images'].keys()
391+
for image in images:
392+
utils.xrun('docker', ['rmi', image])
393+
log.remove('images', image)
394+
log.write()
395+
396+
if args.all_base:
397+
images = log.info['images'].keys()
398+
for image in images:
399+
if log.info['images'][image]['CAB'] is False:
400+
utils.xrun('docker', ['rmi', image])
401+
log.remove('images', image)
402+
log.write()
403+
404+
if args.all_cabs:
405+
images = log.info['images'].keys()
406+
for image in images:
407+
if log.info['images'][image]['CAB']:
408+
utils.xrun('docker', ['rmi', image])
409+
log.remove('images', image)
410+
log.write()
411+
412+
413+
if args.all_containers:
414+
containers = log.info['containers'].keys()
415+
for container in containers:
416+
cont = docker.Container(log.info['containers'][container]['IMAGE'], container)
417+
try:
418+
status = cont.info()['State']['Status']
419+
except OSError:
420+
print('Could not inspect container {}. It probably doesn\'t exist, will remove it from log'.format(container))
421+
status = False
422+
log.remove('containers', container)
423+
log.write()
424+
continue
425+
426+
if status == 'running':
427+
# Kill the container instead of stopping it, so that effect can be felt py parent process
428+
utils.xrun('docker', ['kill', container])
429+
cont.remove()
430+
log.remove('containers', container)
431+
log.write()
432+
elif status == 'exited':
433+
cont.remove()
434+
log.remove('containers', container)
435+
log.write()
378436

379-
try:
380-
os.kill(pid, signal.SIGKILL)
381-
except OSError:
382-
pass
383437

384438
def main(argv):
385439
for i, arg in enumerate(argv):
@@ -404,7 +458,8 @@ def main(argv):
404458
options = []
405459
commands = dict(pull=pull, build=build, run=run,
406460
images=images, cabs=cabs, ps=ps,
407-
containers=containers, kill=kill)
461+
containers=containers, kill=kill,
462+
clean=clean)
408463

409464
command = "failure"
410465

@@ -438,6 +493,7 @@ def main(argv):
438493
cabs : List active stimela containers
439494
ps : List running stimela scripts
440495
kill : Gracefully kill runing stimela process
496+
clean : Clean up tools for stimela
441497
442498
""")
443499

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
FROM stimela/base:0.2.4
1+
FROM stimela/base:0.2.5
22
RUN docker-apt-install aoflagger

stimela/cargo/base/astropy/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM stimela/base:0.2.4
1+
FROM stimela/base:0.2.5
22
RUN pip install astropy \
33
numpy \
44
scipy \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM stimela/base:0.2.4
1+
FROM stimela/base:0.2.5
22
RUN docker-apt-install casarest python-owlcat casacore-data
33
RUN pip install msutils

0 commit comments

Comments
 (0)