ENH: Update FreeFOAM contributions to GPL v3
[freefoam.git] / bin / freefoam-clearPolyMesh.py.in
blobdf0f57be4227ea6771705905be1ef3b90e550854
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 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 3 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, see <http://www.gnu.org/licenses/>.
31 # Script
32 # freefoam-clearPolyMesh
34 # Description
35 # Remove the contents of the constant/polyMesh directory
36 # as per the Foam::polyMesh::removeFiles() method.
38 #------------------------------------------------------------------------------
40 """Usage: freefoam@PY_SCRIPT_SUFFIX@ clearPolyMesh [-h, -help] [-case <dir>] [-region <name>]
42 Remove the contents of the constant/polyMesh directory as per the
43 Foam::polyMesh::removeFiles() method.
45 Options
46 -------
47 -case <dir> The case directory from which to clear the polyMesh
48 -region <name> The mesh region to clear
49 -h, -help Display this help message.
51 """
53 import sys
54 # want to be future proof
55 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
56 from FreeFOAM.compat import *
57 import FreeFOAM.util
59 # parse options
60 case = None
61 region = None
62 args = sys.argv[1:]
63 while len(args) > 0:
64 a = args[0]
65 if a == '-case':
66 if len(args) < 2:
67 sys.stderr.write('Error: The -case option requires an argument\n')
68 sys.exit(1)
69 case = args[1]
70 del args[0:2]
71 elif a == '-region':
72 if len(args) < 2:
73 sys.stderr.write('Error: The -region option requires an argument\n')
74 sys.exit(1)
75 region = args[1]
76 del args[0:2]
77 elif a == '-h' or a == '-help':
78 print(__doc__)
79 sys.exit(0)
80 else:
81 sys.stderr.write('Error: unknown argument "%s"\n'%a)
82 sys.stderr.write(__doc__+'\n')
83 sys.exit(1)
85 try:
86 FreeFOAM.util.clear_polymesh(case, region)
87 except FreeFOAM.util.NoPolyMeshDirectoryError, e:
88 sys.stderr.write('Error: '+str(e)+'\n')
89 sys.exit(1)
91 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file