fix 'SaveAs' in case of overwriting existing project
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 14 Jan 2019 12:30:32 +0300
changeset 2506 8dbdf20f795b
parent 2505 3487fd4fb9bf
child 2507 0f6dae98ddc5
child 2508 9076249f11eb
fix 'SaveAs' in case of overwriting existing project

Traceback (most recent call last):
File "/home/developer/WorkData/PLC/beremiz/beremiz/BeremizIDE.py", line 959, in OnSaveProjectAsMenu
self.CTR.SaveProjectAs()
File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 600, in SaveProjectAs
self.SaveProject(old_project_path)
File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 579, in SaveProject
self._getProjectFilesPath(self.ProjectPath))
File "/usr/lib/python2.7/shutil.py", line 200, in copytree
os.makedirs(dst)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 17] File exists: '/tmp/tests/project_files'
ProjectController.py
--- a/ProjectController.py	Mon Jan 14 12:17:48 2019 +0300
+++ b/ProjectController.py	Mon Jan 14 12:30:32 2019 +0300
@@ -40,6 +40,7 @@
 from datetime import datetime
 from weakref import WeakKeyDictionary
 from functools import reduce
+from distutils.dir_util import copy_tree
 from six.moves import xrange
 
 import wx
@@ -574,8 +575,8 @@
                 old_projectfiles_path = self._getProjectFilesPath(
                     from_project_path)
                 if os.path.isdir(old_projectfiles_path):
-                    shutil.copytree(old_projectfiles_path,
-                                    self._getProjectFilesPath(self.ProjectPath))
+                    copy_tree(old_projectfiles_path,
+                              self._getProjectFilesPath(self.ProjectPath))
             self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml'))
             result = self.CTNRequestSave(from_project_path)
             if result: