diff --git a/src/dynamic-srv.py b/src/dynamic-srv.py index 662b39574bbff223a201f331a428cc6d0c31d9f0..7536a1677cc97d9b669bba646d290fef98950693 100755 --- a/src/dynamic-srv.py +++ b/src/dynamic-srv.py @@ -11,6 +11,7 @@ from collections import UserDict import PyTango import numpy as np import importlib +import shutil def fromPyTango2NumpyType(pytango_type): """ Return the numpy type based on the PyTango type @@ -503,7 +504,37 @@ class Dynamic(PyTango.Device_4Impl): self.myattrs = CaseLessDict() self.read_functions = CaseLessDict() self.write_functions = CaseLessDict() - + +#------------------------------------------------------------------ +# Load config from remote location +#------------------------------------------------------------------ + + def LoadCfgFile(self, argin): + """ Load the file content as a String. Overwrite the existing cfg file. + :param argin: file content as String. + :type: PyTango.DevString + :return: + :rtype: PyTango.DevVoid + """ + # self.debug_stream("In LoadWorkingFile()") + if len(self.attr_WorkingFile_read) == 0: + self.error_stream('WorkingFile not defined, cannot procede.') + self.set_status('WorkingFile not defined, cannot procede.') + return + file_name = self.ConfiguratorScript + if os.path.isfile(file_name): + # File exists + backup_file = file_name + '.bak' + shutil.copyfile(file_name, backup_file) + try: + conf_file = open(file_name, 'w') + conf_file.write(argin) + self.debug_stream('Wrote file ' + file_name) + except Exception as ex: + self.error_stream('Unable to write file ' + file_name + ': ' + str(ex)) + self.set_status('Unable to write file ' + self.ConfiguratorScript) + finally: + conf_file.close() #================================================================== # # DynamicClass class utilities