2 #-------------------------------------------------------------------------------
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 #-------------------------------------------------------------------------------
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
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/>.
34 #------------------------------------------------------------------------------
36 """Usage: freefoam@PY_SCRIPT_SUFFIX@ [options] <appName> [<appOptions>]
38 Runs a specific version of a FreeFOAM executable with given arguments. Can also
39 be used for parallel runs.
43 -b, -basedir Use a different base directory to search for applications
44 (default is @FOAM_LIBEXEC_DIR@).
45 -P, -path Also use the system PATH variable (searched last).
46 -p, -print Instead of executing the command, print the command line that
47 would be used. Useful for command substitution for e.g. mpirun if
48 your system doesn't support the execve(2) (or similar) system
50 -h, -help Display this help message.
51 -v, -version Display the FreeFOAM version and exit.
52 <appName> Name of the FreeFOAM application to run.
53 <appOptions> Options and arguments to be passed to <appName>.
55 Set FREEFOAM_PATH to specify an alternative list of paths (colon-separated)
56 where to search for applications.
58 If the -P option is supplied, the system PATH variable will be appended to the
64 # want to be future proof
65 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
66 from FreeFOAM
.compat
import *
72 # parse arguments (can't use optparse because of single-dash long options)
75 baseDir
= FreeFOAM
.LIBEXEC_DIR
80 if a
== '-b' or a
== '-basedir':
82 sys
.stderr
.write('Error: The %s option requires an argument\n'%a
)
86 elif a
== '-P' or a
== '-path':
89 elif a
== '-p' or a
== '-print':
92 elif a
== '-v' or a
== '-version':
93 print('FreeFOAM version '+FreeFOAM
.VERSION_FULL
)
95 elif a
== '-h' or a
== '-help':
101 # get the application name and remove it from the argument list
103 sys
.stderr
.write('Error: No FreeFOAM application specified\n')
108 # find -case and -parallel in arguments
111 idx
= args
.index('-case')
112 if idx
> len(args
) - 2:
113 sys
.stderr
.write('Error: The -case option requires an argument\n')
118 if '-parallel' in args
:
120 args
.remove('-parallel')
122 # construct search path
123 search_path
= FreeFOAM
.path
.create_app_search_path(
124 basedir
=baseDir
, syspath
=useSysPath
)
126 # run the application
127 runner
= FreeFOAM
.run
.Runner(search_path
)
131 print(runner
.command_str(app
, case
=case
, parallel
=parallel
, args
=args
))
133 status
= runner
.run(app
, case
=case
, parallel
=parallel
, args
=args
)
134 except FreeFOAM
.run
.ApplicationNotFoundError
, e
:
135 sys
.stderr
.write(str(e
)+'\n')
140 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file