def _addCustomData(self, value, name, **kwargs):
'''
The custom data will be added as a comment line in the form::
#C name : value
..note:: non-scalar values (or name/values containing end-of-line) will not be written
'''
if self.filename is None:
self.info(
'Custom data "%s" will not be stored in SPEC file. Reason: uninitialized file', name)
return
if numpy.rank(value) > 0: # ignore non-scalars
self.info(
'Custom data "%s" will not be stored in SPEC file. Reason: value is non-scalar', name)
return
v = str(value)
if '\n' in v or '\n' in name: # ignore if name or the string representation of the value contains end-of-line
self.info(
'Custom data "%s" will not be stored in SPEC file. Reason: unsupported format', name)
return
fileWasClosed = self.fd is None or self.fd.closed
if fileWasClosed:
try:
self.fd = open(self.filename, 'a')
except:
self.info(
'Custom data "%s" will not be stored in SPEC file. Reason: cannot open file', name)
return
self.fd.write('#C %s : %s\n' % (name, v))
self.fd.flush()
if fileWasClosed:
self.fd.close() # leave the file descriptor as found
评论列表
文章目录