Salome HOME
Add the -DWITHOUT_MPI=1 possibility
[modules/kernel.git] / salome_adm / cmake_files / copytree1.py
1 import os
2 import sys
3 import stat
4 from os.path import abspath
5 import fnmatch
6
7 import shutil
8
9 class Error(EnvironmentError):
10     pass
11 try:
12     WindowsError
13 except NameError:
14     WindowsError = None
15
16 def ignore_patterns(*patterns):
17     """Function that can be used as copytree() ignore parameter.
18
19     Patterns is a sequence of glob-style patterns
20     that are used to exclude files"""
21     def _ignore_patterns(path, names):
22         ignored_names = []
23         for pattern in patterns:
24             ignored_names.extend(fnmatch.filter(names, pattern))
25         return set(ignored_names)
26     return _ignore_patterns
27
28 def copytree(src, dst, symlinks=False, ignore=None):
29     """Recursively copy a directory tree using shutil.copy2().
30
31     The destination directory must not already exist.
32     If exception(s) occur, an Error is raised with a list of reasons.
33
34     If the optional symlinks flag is true, symbolic links in the
35     source tree result in symbolic links in the destination tree; if
36     it is false, the contents of the files pointed to by symbolic
37     links are copied.
38
39     The optional ignore argument is a callable. If given, it
40     is called with the `src` parameter, which is the directory
41     being visited by copytree(), and `names` which is the list of
42     `src` contents, as returned by os.listdir():
43
44         callable(src, names) -> ignored_names
45
46     Since copytree() is called recursively, the callable will be
47     called once for each directory that is copied. It returns a
48     list of names relative to the `src` directory that should
49     not be copied.
50
51     XXX Consider this example code rather than the ultimate tool.
52
53     """
54     names = os.listdir(src)
55     if ignore is not None:
56         ignored_names = ignore(src, names)
57     else:
58         ignored_names = set()
59
60     os.makedirs(dst)
61     errors = []
62     for name in names:
63         if name in ignored_names:
64             continue
65         srcname = os.path.join(src, name)
66         dstname = os.path.join(dst, name)
67         try:
68             if symlinks and os.path.islink(srcname):
69                 linkto = os.readlink(srcname)
70                 os.symlink(linkto, dstname)
71             elif os.path.isdir(srcname):
72                 copytree(srcname, dstname, symlinks, ignore)
73             else:
74                 shutil.copy2(srcname, dstname)
75             # XXX What about devices, sockets etc.?
76         except (IOError, os.error), why:
77             errors.append((srcname, dstname, str(why)))
78         # catch the Error from the recursive copytree so that we can
79         # continue with other files
80         except Error, err:
81             errors.extend(err.args[0])
82     try:
83         shutil.copystat(src, dst)
84     except OSError, why:
85         if WindowsError is not None and isinstance(why, WindowsError):
86             # Copying file access times may fail on Windows
87             pass
88         else:
89             errors.extend((src, dst, str(why)))
90     if errors:
91         raise Error, errors