1#!@PYTHON@ 2# -*- coding: utf-8 -*- 3 4#------------------------------------------------------------------------------- 5 6# This file is part of Code_Saturne, a general-purpose CFD tool. 7# 8# Copyright (C) 1998-2021 EDF S.A. 9# 10# This program is free software; you can redistribute it and/or modify it under 11# the terms of the GNU General Public License as published by the Free Software 12# Foundation; either version 2 of the License, or (at your option) any later 13# version. 14# 15# This program is distributed in the hope that it will be useful, but WITHOUT 16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 18# details. 19# 20# You should have received a copy of the GNU General Public License along with 21# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 22# Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 24#------------------------------------------------------------------------------- 25 26import os 27import sys 28 29#------------------------------------------------------------------------------- 30# Handle Python modules possible locations 31#------------------------------------------------------------------------------- 32 33# Store the installation path of Code_Saturne Python modules. 34cspath = '@pkgpythondir@' 35cslibdir = '@libdir@' 36 37# Store the information whether the installation is relocatable or not. 38relocatable = '@relocatable@' 39 40# Get the script rootdir (especially useful for relocatable installation) 41# When frozen with cx_freeze __file__ is not defined in code_saturne, 42# therefore we use two different ways of getting the script path. 43if hasattr(sys, 'frozen'): 44 rootdir = sys.executable 45else: 46 rootdir = os.path.realpath(__file__) 47 48# For a relocatable installation, reset cspath (i.e. for a standard Python 49# installation: lib/pythonX.Y/site-packages/code_saturne). We also assume 50# that the main script still lies in the bin directory. 51if relocatable == 'yes': 52 bindir = os.path.dirname(rootdir) 53 prefix = os.path.dirname(bindir) 54 sitedir = os.path.join(prefix, 55 'lib', 'python' + sys.version[:3], 'site-packages') 56 cspath = os.path.join(sitedir, 'code_saturne') 57 cslibdir = os.path.join(prefix, 'lib') 58 59#------------------------------------------------------------------------------- 60# Main 61#------------------------------------------------------------------------------- 62 63if __name__ == '__main__': 64 65 sitedir = os.path.split(cspath)[0] 66 67 if os.path.isdir(sitedir) and not sitedir in sys.path: 68 sys.path.insert(0, sitedir) 69 70 if sys.version > '3.3': 71 import importlib 72 importlib.invalidate_caches() 73 74 from code_saturne.cs_exec_environment import clean_os_environ_for_shell 75 clean_os_environ_for_shell() 76 77 try: 78 from code_saturne.cs_script import master_script 79 except Exception: 80 print(sys.path) 81 sys.exit(0) 82 83 # Retrieve package information (name, version, installation dirs, ...) 84 85 config_file = os.path.join(cslibdir, 'code_saturne_build.cfg') 86 87 from code_saturne.cs_package import package 88 pkg = package(config_file=config_file) 89 90 # Create an instance of the main script 91 cs = master_script(sys.argv[1:], pkg) 92 93 retcode = cs.execute() 94 95 if retcode == None: 96 retcode = 0 97 98 sys.exit(retcode) 99 100#------------------------------------------------------------------------------- 101# End 102#------------------------------------------------------------------------------- 103