528 |
528 |
529 fobj, path, _md5sum = blob |
529 fobj, path, _md5sum = blob |
530 os.close(fobj) |
530 os.close(fobj) |
531 shutil.move(path, newpath) |
531 shutil.move(path, newpath) |
532 |
532 |
|
533 def _extra_files_log_path(self): |
|
534 return os.path.join(self.workingdir, "extra_files.txt") |
|
535 |
|
536 @RunInMain |
|
537 def PurgePLC(self): |
|
538 |
|
539 extra_files_log = self._extra_files_log_path() |
|
540 |
|
541 old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \ |
|
542 if self.CurrentPLCFilename is not None \ |
|
543 else None |
|
544 |
|
545 try: |
|
546 os.remove(old_PLC_filename) |
|
547 for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]: |
|
548 try: |
|
549 os.remove(os.path.join(self.workingdir, filename.strip())) |
|
550 except Exception: |
|
551 pass |
|
552 except Exception: |
|
553 pass |
|
554 |
|
555 self.PLCStatus = PlcStatus.Empty |
|
556 |
|
557 # TODO: PLCObject restart |
|
558 |
533 @RunInMain |
559 @RunInMain |
534 def NewPLC(self, md5sum, plc_object, extrafiles): |
560 def NewPLC(self, md5sum, plc_object, extrafiles): |
535 if self.PLCStatus in [PlcStatus.Stopped, PlcStatus.Empty, PlcStatus.Broken]: |
561 if self.PLCStatus in [PlcStatus.Stopped, PlcStatus.Empty, PlcStatus.Broken]: |
536 NewFileName = md5sum + lib_ext |
562 NewFileName = md5sum + lib_ext |
537 extra_files_log = os.path.join(self.workingdir, "extra_files.txt") |
563 extra_files_log = self._extra_files_log_path() |
538 |
564 |
539 old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \ |
|
540 if self.CurrentPLCFilename is not None \ |
|
541 else None |
|
542 new_PLC_filename = os.path.join(self.workingdir, NewFileName) |
565 new_PLC_filename = os.path.join(self.workingdir, NewFileName) |
543 |
566 |
544 self.UnLoadPLC() |
567 self.UnLoadPLC() |
545 |
568 |
|
569 self.PurgePLC() |
|
570 |
546 self.LogMessage("NewPLC (%s)" % md5sum) |
571 self.LogMessage("NewPLC (%s)" % md5sum) |
547 self.PLCStatus = PlcStatus.Empty |
|
548 |
|
549 try: |
|
550 os.remove(old_PLC_filename) |
|
551 for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]: |
|
552 try: |
|
553 os.remove(os.path.join(self.workingdir, filename.strip())) |
|
554 except Exception: |
|
555 pass |
|
556 except Exception: |
|
557 pass |
|
558 |
572 |
559 try: |
573 try: |
560 # Create new PLC file |
574 # Create new PLC file |
561 self._BlobAsFile(plc_object, new_PLC_filename) |
575 self._BlobAsFile(plc_object, new_PLC_filename) |
562 |
576 |