From 6a5c2a6ae6049abbc889a362e0284016816781b6 Mon Sep 17 00:00:00 2001 From: Roberto Javier Homs Puron Date: Mon, 20 Sep 2021 12:15:45 +0200 Subject: [PATCH] Fix Spec user custom data --- src/sardana/macroserver/recorders/storage.py | 11 +++++++++-- src/sardana/sardanacustomsettings.py | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sardana/macroserver/recorders/storage.py b/src/sardana/macroserver/recorders/storage.py index 729a1b7d6c..e470698f26 100644 --- a/src/sardana/macroserver/recorders/storage.py +++ b/src/sardana/macroserver/recorders/storage.py @@ -45,6 +45,7 @@ from sardana.macroserver.scan.recorder import (BaseFileRecorder, BaseNAPI_FileRecorder, SaveModes) +from sardana.sardanacustomsettings import SPEC_CUSTOM_DATA_FORMAT from taurus.core.util.containers import chunks @@ -496,7 +497,7 @@ def _endRecordList(self, recordlist): self.fd.flush() self.fd.close() - def _addCustomData(self, value, name, **kwargs): + def _addCustomData(self, value, name, spec_custom_fmt=None, **kwargs): ''' The custom data will be added as a comment line in the form:: @@ -526,7 +527,13 @@ def _addCustomData(self, value, name, **kwargs): self.info( 'Custom data "%s" will not be stored in SPEC file. Reason: cannot open file', name) return - self.fd.write(str('#C %s : %s\n' % (name, v))) + if spec_custom_fmt is None: + spec_custom_fmt = SPEC_CUSTOM_DATA_FORMAT + + if '\n' not in spec_custom_fmt: + spec_custom_fmt += '\n' + + self.fd.write(spec_custom_fmt.format(value=v, name=name)) self.fd.flush() if fileWasClosed: self.fd.close() # leave the file descriptor as found diff --git a/src/sardana/sardanacustomsettings.py b/src/sardana/sardanacustomsettings.py index b8d8a68d90..628f10bb21 100644 --- a/src/sardana/sardanacustomsettings.py +++ b/src/sardana/sardanacustomsettings.py @@ -124,3 +124,9 @@ #: places are not called in simple mv-based macros but only in scan-based #: macros PRE_POST_MOVE_HOOK_IN_MV = True + + +#: Default SPEC custom data format. +#: +#: For backward compatibility change to: '#C {name} : {value}\n' +SPEC_CUSTOM_DATA_FORMAT = '#UVAR {name} {value}\n'