diff -r 62c5c3589769 -r f1e182818434 runtime/PLCObject.py --- a/runtime/PLCObject.py Thu Apr 11 13:45:27 2019 +0200 +++ b/runtime/PLCObject.py Mon Apr 15 13:34:09 2019 +0200 @@ -530,31 +530,45 @@ os.close(fobj) shutil.move(path, newpath) + def _extra_files_log_path(self): + return os.path.join(self.workingdir, "extra_files.txt") + + @RunInMain + def PurgePLC(self): + + extra_files_log = self._extra_files_log_path() + + old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \ + if self.CurrentPLCFilename is not None \ + else None + + try: + os.remove(old_PLC_filename) + for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]: + try: + os.remove(os.path.join(self.workingdir, filename.strip())) + except Exception: + pass + except Exception: + pass + + self.PLCStatus = PlcStatus.Empty + + # TODO: PLCObject restart + @RunInMain def NewPLC(self, md5sum, plc_object, extrafiles): if self.PLCStatus in [PlcStatus.Stopped, PlcStatus.Empty, PlcStatus.Broken]: NewFileName = md5sum + lib_ext - extra_files_log = os.path.join(self.workingdir, "extra_files.txt") - - old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \ - if self.CurrentPLCFilename is not None \ - else None + extra_files_log = self._extra_files_log_path() + new_PLC_filename = os.path.join(self.workingdir, NewFileName) self.UnLoadPLC() + self.PurgePLC() + self.LogMessage("NewPLC (%s)" % md5sum) - self.PLCStatus = PlcStatus.Empty - - try: - os.remove(old_PLC_filename) - for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]: - try: - os.remove(os.path.join(self.workingdir, filename.strip())) - except Exception: - pass - except Exception: - pass try: # Create new PLC file