Skip to content

Commit

Permalink
Fixes github issue opencadc#81. Added statements to close opened files.
Browse files Browse the repository at this point in the history
  • Loading branch information
yeunga committed Jun 12, 2018
1 parent aed7d45 commit d612575
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions caom2repo/caom2repo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,14 @@ def update(self, observation, **kwargs):
format(len(visited), len(updated), len(skipped), len(failed)))

elif args.cmd == 'create':
logger.info("Create")
obs_reader = ObservationReader()
client.put_observation(obs_reader.read(args.observation))
with args.observation as observation:
try:
logger.info("Create")
obs_reader = ObservationReader()
client.put_observation(obs_reader.read(observation))
finally:
if observation is not None:
observation.close()
elif args.cmd == 'read':
logger.info("Read")
observation = client.get_observation(args.collection,
Expand All @@ -727,10 +732,15 @@ def update(self, observation, **kwargs):
else:
observation_writer.write(observation, sys.stdout)
elif args.cmd == 'update':
logger.info("Update")
obs_reader = ObservationReader()
# TODO not sure if need to read in string first
client.post_observation(obs_reader.read(args.observation))
with args.observation as observation:
try:
logger.info("Update")
obs_reader = ObservationReader()
# TODO not sure if need to read in string first
client.post_observation(obs_reader.read(observation))
finally:
if observation is not None:
observation.close()
else:
logger.info("Delete")
client.delete_observation(collection=args.collection,
Expand Down

0 comments on commit d612575

Please sign in to comment.