FIX: Invalid HTML in FoamHeader.html.in
[freefoam.git] / bin / freefoam-copySettings.py.in
blob23a2e6e4aa7cebb2a0d6ca640cf956d2a8a292fb
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2011 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software; you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation; either version 2 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM; if not, write to the Free Software Foundation,
30 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 # Script
33 # freefoam-copySettings
35 # Description
36 # Copy FreeFOAM settings from one case to another, without copying
37 # the mesh or results
38 #------------------------------------------------------------------------------
40 """Usage: freefoam@PY_SCRIPT_SUFFIX@ copySettings [-h, -help] <src> <dst>
42 Copy FreeFOAM settings from one case to another, without copying the mesh or
43 results.
45 Options
46 -------
47 <src> Source case directory to copy the settings from
48 <dst> Destination case directory to copy the settings to
49 -h, -help Display this help message.
51 """
53 # want to be future proof
54 from FreeFOAM.compat import *
56 import shutil
57 import sys
58 import os
59 import os.path
60 import re
62 # parse options
63 if sys.argv[1] == '-h' or sys.argv[1] == '-help':
64 print(__doc__)
65 sys.exit(0)
67 if len(sys.argv[1:]) != 2:
68 sys.stderr.write('Error: exactly two arguments required\n')
69 sys.stderr.write(__doc__+'\n')
70 sys.exit(1)
72 srcDir = os.path.abspath(sys.argv[1])
73 dstDir = os.path.abspath(sys.argv[2])
75 for d in ('constant', 'system'):
76 dd = os.path.join(srcDir, d)
77 if not os.path.isdir(dd):
78 sys.stderr.write('Error: no "%s" directory in "%s\n"'%(d, srcDir))
79 sys.stderr.write(' This does not appear to be a FreeFOAM case\n')
80 sys.exit(1)
82 # TODO:
83 # - verify that it works with multiple mesh regions
84 # - special treatment for starting with negative crank angles
85 # - or even better, parse startTime in controlDict if available
87 for parent, dirs, files in os.walk(srcDir):
88 # remove processor, time (except 0) and polyMesh directories
89 for d in dirs:
90 if re.match(r'processor[0-9]+|[1-9].*|\d+\.\d+|polyMesh$', d):
91 print('skipped', os.path.join(parent, d))
92 dirs.remove(d)
93 # remove log and queuing system output
94 for f in files:
95 if re.match(r'log.*|.*\.log|foam\.[eo][1-9]*', f):
96 print('skipped', os.path.join(parent, f))
97 continue
98 # now copy the file
99 subdir = os.path.relpath(parent, srcDir)
100 s = os.path.join(parent, f)
101 d = os.path.join(dstDir, subdir, f)
102 print('%s\t->\t%s'%(s,d))
103 shutil.copy2(s, d)
105 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file