Use custom copytree function and don't copy svn directories
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 15 Apr 2009 16:19:32 +0000 (16:19 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 15 Apr 2009 16:19:32 +0000 (16:19 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2512 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/bertos_utils.py
wizard/const.py
wizard/copytree.py [new file with mode: 0644]

index 91ab05ad0d99363d987de81d7b38b882bc0e98b8..fe346e8f12f41d8a19cb30ce736115efaa157c34 100644 (file)
@@ -4,7 +4,7 @@
 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
 # All rights reserved.
 #
-# $Id:$
+# $Id$
 #
 # Author: Lorenzo Berni <duplo@develer.com>
 #
@@ -14,6 +14,8 @@ import fnmatch
 import glob
 import re
 import shutil
+# Use custom copytree function
+import copytree
 import pickle
 
 import const
@@ -37,7 +39,7 @@ def createBertosProject(project_info):
     # Destination source dir
     srcdir = directory + "/bertos"
     shutil.rmtree(srcdir, True)
-    shutil.copytree(sources_dir + "/bertos", srcdir)
+    copytree.copytree(sources_dir + "/bertos", srcdir, ignore_list=const.IGNORE_LIST)
     # Destination makefile
     makefile = directory + "/Makefile"
     if os.path.exists(makefile):
index c478697f0d2e83494df607057d5bad8ef9e6f43c..37e9f93b26b2f98cb5e71affa3a325613f0072aa 100644 (file)
@@ -4,7 +4,7 @@
 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
 # All rights reserved.
 #
-# $Id:$
+# $Id$
 #
 # Author: Lorenzo Berni <duplo@develer.com>
 #
@@ -58,6 +58,10 @@ EXTENSION_FILTER = (
     "Makefile",
 )
 
+IGNORE_LIST = (
+    "*svn*",
+)
+
 MODULE_DEFINITION = {
     "module_name": "module_name",
     "module_configuration": "module_configuration",
diff --git a/wizard/copytree.py b/wizard/copytree.py
new file mode 100644 (file)
index 0000000..4e568de
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+# All rights reserved.
+#
+# $Id:$
+#
+# Author: Lorenzo Berni <duplo@develer.com>
+#
+
+import os
+import fnmatch
+from shutil import *
+
+def copytree(src, dst, symlinks=False, ignore_list=[]):
+    """
+    Reimplementation of the shutil.copytree function that use ignore_list.
+    ignore_list is a list containing patterns to ignore during the copy.
+    """
+    names = os.listdir(src)
+    os.makedirs(dst)
+    errors = []
+    for name in names:
+        srcname = os.path.join(src, name)
+        dstname = os.path.join(dst, name)
+        try:
+            ignored = False
+            for ignore in ignore_list:
+                if fnmatch.fnmatch(srcname, ignore):
+                    ignored = True
+                    break
+            if ignored:
+                continue
+            if symlinks and os.path.islink(srcname):
+                linkto = os.readlink(srcname)
+                os.symlink(linkto, dstname)
+            elif os.path.isdir(srcname):
+                copytree(srcname, dstname, symlinks)
+            else:
+                copy2(srcname, dstname)
+            # XXX What about devices, sockets etc.?
+        except (IOError, os.error), why:
+            errors.append((srcname, dstname, str(why)))
+        # catch the Error from the recursive copytree so that we can
+        # continue with other files
+        except Error, err:
+            errors.extend(err.args[0])
+    try:
+        copystat(src, dst)
+    except WindowsError:
+        # can't copy file access times on Windows
+        pass
+    except OSError, why:
+        errors.extend((src, dst, str(why)))
+    if errors:
+        raise Error, errors