Add infrastructure for recognize modules supported by the selected cpu
[bertos.git] / wizard / copytree.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13 import fnmatch
14 from shutil import *
15
16 def copytree(src, dst, symlinks=False, ignore_list=[]):
17     """
18     Reimplementation of the shutil.copytree function that use ignore_list.
19     ignore_list is a list containing patterns to ignore during the copy.
20     """
21     names = os.listdir(src)
22     os.makedirs(dst)
23     errors = []
24     for name in names:
25         srcname = os.path.join(src, name)
26         dstname = os.path.join(dst, name)
27         try:
28             ignored = False
29             for ignore in ignore_list:
30                 if fnmatch.fnmatch(srcname, ignore):
31                     ignored = True
32                     break
33             if ignored:
34                 continue
35             if symlinks and os.path.islink(srcname):
36                 linkto = os.readlink(srcname)
37                 os.symlink(linkto, dstname)
38             elif os.path.isdir(srcname):
39                 copytree(srcname, dstname, symlinks)
40             else:
41                 copy2(srcname, dstname)
42             # XXX What about devices, sockets etc.?
43         except (IOError, os.error), why:
44             errors.append((srcname, dstname, str(why)))
45         # catch the Error from the recursive copytree so that we can
46         # continue with other files
47         except Error, err:
48             errors.extend(err.args[0])
49     try:
50         copystat(src, dst)
51     except WindowsError:
52         # can't copy file access times on Windows
53         pass
54     except OSError, why:
55         errors.extend((src, dst, str(why)))
56     if errors:
57         raise Error, errors