FIX: Logic requiring pngmath was broken
[freefoam.git] / bin / freefoam.py.in
blobb0569966aabd203adf1c12049644d42e268757f2
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
35 #------------------------------------------------------------------------------
37 """Usage: freefoam@PY_SCRIPT_SUFFIX@ [options] <appName> [<appOptions>]
39 Runs a specific version of a FreeFOAM executable with given arguments. Can also
40 be used for parallel runs.
42 Options
43 -------
44 -b, -basedir Use a different base directory to search for applications
45 (default is @FOAM_LIBEXEC_DIR@).
46 -P, -path Also use the system PATH variable (searched last).
47 -p, -print Instead of executing the command, print the command line
48 command line that would be used. Useful for command substitution
49 for e.g. mpirun if your system doesn't support the execve(2) (or
50 similar) system call.
51 -h, -help Display this help message.
52 -v, -version Display the FreeFOAM version and exit.
53 <appName> Name of the FreeFOAM application to run.
54 <appOptions> Options and arguments to be passed to <appName>.
56 Set FREEFOAM_PATH to specify an alternative list of paths (colon-separated)
57 where to search for applications.
59 If the -P option is supplied, the system PATH variable will be appended to the
60 search path.
62 """
63 # want to be future proof
64 from FreeFOAM.compat import *
66 import FreeFOAM
67 import FreeFOAM.run
68 import FreeFOAM.path
69 import sys
71 # parse arguments (can't use optparse because of single-dash long options)
72 appName = None
73 useSysPath = False
74 baseDir = FreeFOAM.LIBEXEC_DIR
75 printOnly = False
76 args = sys.argv[1:]
77 while len(args) > 0:
78 a = args[0]
79 if a == '-b' or a == '-basedir':
80 if len(args) < 2:
81 sys.stderr.write('Error: The %s option requires an argument\n'%a)
82 sys.exit(1)
83 baseDir = args[1]
84 del args[0:2]
85 elif a == '-P' or a == '-path':
86 useSysPath = True
87 del args[0]
88 elif a == '-p' or a == '-print':
89 printOnly = True
90 del args[0]
91 elif a == '-v' or a == '-version':
92 print('FreeFOAM version '+FreeFOAM.VERSION_FULL)
93 sys.exit(0)
94 elif a == '-h' or a == '-help':
95 print(__doc__)
96 sys.exit(0)
97 else:
98 break
100 # get the application name and remove it from the argument list
101 if not len(args):
102 sys.stderr.write('Error: No FreeFOAM application specified\n')
103 sys.exit(1)
104 app = args[0]
105 del args[0]
107 # find -case and -parallel in arguments
108 case = None
109 if '-case' in args:
110 idx = args.index('-case')
111 if idx > len(args) - 2:
112 sys.stderr.write('Error: The -case option requires an argument\n')
113 sys.exit(1)
114 case = args[idx+1]
115 del args[idx:idx+2]
116 parallel = False
117 if '-parallel' in args:
118 parallel = True
119 args.remove('-parallel')
121 # construct search path
122 search_path = FreeFOAM.path.create_app_search_path(
123 basedir=baseDir, syspath=useSysPath)
125 # run the application
126 runner = FreeFOAM.run.Runner(search_path)
127 status = 0
128 try:
129 if printOnly:
130 print(runner.command_str(app, case=case, parallel=parallel, args=args))
131 else:
132 status = runner.run(app, case=case, parallel=parallel, args=args)
133 except FreeFOAM.run.ApplicationNotFoundError, e:
134 sys.stderr.write(str(e)+'\n')
135 status = 1
137 sys.exit(status)
139 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file