ENH: Update FreeFOAM contributions to GPL v3
[freefoam.git] / data / python / FreeFOAM / __init__.py.in
blob6a347db3549425b064eda5b447ce314e929f8530
1 #-------------------------------------------------------------------------------
2 # ______ _ ____ __ __
3 # | ____| _| |_ / __ \ /\ | \/ |
4 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
5 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
6 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
7 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
9 # FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
12 # Gerber van der Graaf <gerber_graaf@users.sf.net>
13 #-------------------------------------------------------------------------------
14 # License
15 # This file is part of FreeFOAM.
17 # FreeFOAM is free software: you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by the
19 # Free Software Foundation, either version 3 of the License, or (at your
20 # option) any later version.
22 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 # for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
30 # Description
31 # Useful Python functionality for the FreeFOAM scripts.
33 #-------------------------------------------------------------------------------
35 """A package for scripting @PROJECT_NAME@ with Python.
37 Modules
38 -------
39 FreeFOAM : Basic information (paths, version etc.)
40 FreeFOAM.path : Search path handling (mostly used internally)
41 FreeFOAM.run : Classes and functions used for running and compiling.
43 Classes
44 -------
45 VersionError : Exception class which is raised if the Python version is
46 smaller than 2.6.
47 NoConfigDirError : Exception class which is raised if no global configuration
48 directory could be located.
50 Variables in `FreeFOAM`
51 -----------------------
52 VERSION_FULL : String containing the full version ('major.minor.patch')
53 version_info : List containing version information
54 ([major, minor, patch])
55 LIBEXEC_DIR : Base directory where all @PROJECT_NAME@ applications have
56 been installed into.
57 CONFIG_DIR : Name of the directory where the global configuration files
58 are installed.
59 DATA_DIR : Directory where architecture-independent data files are
60 installed.
61 PY_SCRIPT_SUFFIX : Suffix used for executable Python scripts ('.py' on Windows,
62 the empty string on Unix-like platforms).
63 EXE_PREFIX : Prefix used in front of @PROJECT_NAME@ executable names.
64 EXE_SUFFIX : Extension used for binary executable files ('.exe' on
65 Windows, the empty string on Unix-like platforms).
66 CMAKE_COMMAND : Path to the 'cmake' executable.
67 CMAKE_GENERATOR : The generator used to compile @PROJECT_NAME@.
68 CMAKE_C_COMPILER : The C compiler used to compile @PROJECT_NAME@.
69 CMAKE_CXX_COMPILER : The C++ compiler used to compile @PROJECT_NAME@.
70 config_dir : Configuration directory containing the global
71 `controlDict` file. Set to None if it can't be found.
72 search_path : Search path on which to find @PROJECT_NAME@ applications. Refer
73 to the documentation of
74 FreeFOAM.path.create_app_search_path on how it is
75 initialized.
77 """
79 import sys as _sys
80 import os as _os
81 import os.path as _op
83 from FreeFOAM.compat import *
85 class VersionError(Exception):
86 """Raised when the Python version is smaller than required."""
87 def __init__(self, *args):
88 Exception.__init__(self, *args)
90 class NoConfigDirError(Exception):
91 """Raised when no global configuration directory could be found."""
92 def __init__(self, *args):
93 Exception.__init__(self, *args)
95 # Ensure that we have Python2.0 or newer
96 if _sys.hexversion < 0x020000f0:
97 raise VersionError('@PROJECT_NAME@ requires at least Python version 2.0 to run')
98 elif _sys.hexversion < 0x020400f0:
99 # warn if < 2.4 (untested)
100 echo('WARNING: Only Python versions >= 2.4 are tested with @PROJECT_NAME@', file=_sys.stderr)
102 # Some universal variables
103 VERSION_FULL = '@FOAM_VERSION_FULL@'
104 version_info = (@FOAM_VERSION_MAJOR@, @FOAM_VERSION_MINOR@, @FOAM_VERSION_PATCH@)
106 LIBEXEC_DIR = _op.abspath('@FOAM_LIBEXEC_DIR@')
107 CONFIG_DIR = _op.abspath('@FOAM_CONFIG_DIR@')
108 DATA_DIR = _op.abspath('@FOAM_DATA_DIR@')
110 PY_SCRIPT_SUFFIX = '@FOAM_PY_SCRIPT_SUFFIX@'
111 EXE_PREFIX = '@FOAM_EXE_PREFIX@'
112 EXE_SUFFIX = '@CMAKE_EXECUTABLE_SUFFIX@'
114 CMAKE_COMMAND = _op.abspath('@CMAKE_COMMAND@')
115 CMAKE_GENERATOR ='@CMAKE_GENERATOR@'
116 CMAKE_C_COMPILER = _op.abspath('@CMAKE_C_COMPILER@')
117 CMAKE_CXX_COMPILER = _op.abspath('@CMAKE_CXX_COMPILER@')
119 BUILD_TYPE = '@CMAKE_BUILD_TYPE@'
121 # configuration search path
122 _config_path = [
123 _op.abspath(_op.expanduser('~/.FreeFOAM/@FOAM_VERSION_FULL@')),
124 _op.abspath(_op.expanduser('~/.FreeFOAM')),
125 CONFIG_DIR
127 if 'FREEFOAM_CONFIG_DIR' in _os.environ:
128 _config_path.insert(0, _os.environ['FREEFOAM_CONFIG_DIR'])
130 # configuration directory
131 config_dir = None
132 for d in _config_path:
133 if (_op.isfile(_op.join(d,'controlDict')) and
134 _op.isfile(_op.join(d,'cellModels'))):
135 config_dir = d
136 break
137 if config_dir is None:
138 raise NoConfigDirError('Failed to find a global configuration directory')
140 # MUST be at the end
141 import FreeFOAM.path as _fp
142 search_path = _fp.create_app_search_path(LIBEXEC_DIR, False)
144 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file