From 0766963bc9873ffcecd9b1f4440926d04e224142 Mon Sep 17 00:00:00 2001 From: duplo Date: Wed, 15 Apr 2009 16:19:32 +0000 Subject: [PATCH] Use custom copytree function and don't copy svn directories git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2512 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/bertos_utils.py | 6 +++-- wizard/const.py | 6 ++++- wizard/copytree.py | 57 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 wizard/copytree.py diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 91ab05ad..fe346e8f 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -4,7 +4,7 @@ # Copyright 2008 Develer S.r.l. (http://www.develer.com/) # All rights reserved. # -# $Id:$ +# $Id$ # # Author: Lorenzo Berni # @@ -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): diff --git a/wizard/const.py b/wizard/const.py index c478697f..37e9f93b 100644 --- a/wizard/const.py +++ b/wizard/const.py @@ -4,7 +4,7 @@ # Copyright 2008 Develer S.r.l. (http://www.develer.com/) # All rights reserved. # -# $Id:$ +# $Id$ # # Author: Lorenzo Berni # @@ -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 index 00000000..4e568dea --- /dev/null +++ b/wizard/copytree.py @@ -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 +# + +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 -- 2.25.1