# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1547458232 -10800
# Node ID 8dbdf20f795b2038ba729cfb1189ac2652a319d4
# Parent  3487fd4fb9bf18412cb571ca678c4731ed36abaf
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'

diff -r 3487fd4fb9bf -r 8dbdf20f795b 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: