Debian Codegraph @

cmake/scripts/copy-test-demo-data.py

raw ◀ ▶
1 Debian patch touch this file
1 # Copyright (C) 2013 Johan Hake
2 #
3 # This file is part of DOLFIN.
4 #
5 # DOLFIN is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # DOLFIN is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Copy all data, tests and demo to a given directory relative to the top dolfin
19 # source directory
20
21 import os
22 import sys
23 import re
24 import shutil
25
26 # Subdirectories
27 sub_directories = ['demo', 'test', 'bench']
28
29 # Copy all files with the following suffixes
30 suffix_patterns = ["py", "h", "cpp", "cpp.rst", "ufl", "ufl.rst", "xdmf",
31 "xml", "xml.gz", "off", "inp", "msh", "supp", "rst",
32 "py.rst", "ele", "node", "grid", "edge", "sh"]
33
•34 suffix_pattern = re.compile("(%s)," % ("|".join(r"[\w-]+\.%s" % pattern
35 for pattern in suffix_patterns)))
36
37 script_rel_path = os.sep.join(__file__.split(os.sep)[:-1])
38 script_rel_path = script_rel_path or "."
39 dolfin_dir = os.path.abspath(os.path.join(script_rel_path, os.pardir, os.pardir))
40
41
42 def copy_data(top_destdir):
43
44 abs_destdir = top_destdir if os.path.isabs(top_destdir) else os.path.join(dolfin_dir, top_destdir)
45
46 if abs_destdir == dolfin_dir:
47 raise RuntimeError("destination directory cannot be the same as "
48 "the dolfin source directory")
49
50 if not os.path.isdir(abs_destdir):
51 raise RuntimeError("%s is not a directory." % abs_destdir)
52
53 for subdir in sub_directories:
54
55 top_dir = os.path.join(dolfin_dir, subdir)
56 for dirpath, dirnames, filenames in os.walk(top_dir):
57 destdir = dirpath.replace(dolfin_dir, abs_destdir)
58 if not os.path.isdir(destdir):
59 os.makedirs(destdir)
60 for f in re.findall(suffix_pattern, " ".join("%s," % f for f in filenames)):
61 srcfile = os.path.join(dirpath, f)
62 shutil.copy(srcfile, destdir)
63
64
65 if __name__ == "__main__":
66 # Expecting a destination argument
67 if len(sys.argv) != 2:
68 raise RuntimeError("Expecting 1 argument with the destination directory")
69
70 copy_data(sys.argv[-1])