2 #-------------------------------------------------------------------------------
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 #-------------------------------------------------------------------------------
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
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
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.
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
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
63 # want to be future proof
64 from FreeFOAM
.compat
import *
71 # parse arguments (can't use optparse because of single-dash long options)
74 baseDir
= FreeFOAM
.LIBEXEC_DIR
79 if a
== '-b' or a
== '-basedir':
81 sys
.stderr
.write('Error: The %s option requires an argument\n'%a
)
85 elif a
== '-P' or a
== '-path':
88 elif a
== '-p' or a
== '-print':
91 elif a
== '-v' or a
== '-version':
92 print('FreeFOAM version '+FreeFOAM
.VERSION_FULL
)
94 elif a
== '-h' or a
== '-help':
100 # get the application name and remove it from the argument list
102 sys
.stderr
.write('Error: No FreeFOAM application specified\n')
107 # find -case and -parallel in arguments
110 idx
= args
.index('-case')
111 if idx
> len(args
) - 2:
112 sys
.stderr
.write('Error: The -case option requires an argument\n')
117 if '-parallel' in args
:
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
)
130 print(runner
.command_str(app
, case
=case
, parallel
=parallel
, args
=args
))
132 status
= runner
.run(app
, case
=case
, parallel
=parallel
, args
=args
)
133 except FreeFOAM
.run
.ApplicationNotFoundError
, e
:
134 sys
.stderr
.write(str(e
)+'\n')
139 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file