Repository navigation
Expand file tree
/
Copy pathcs_package.py
More file actions
265 lines (195 loc) · 9 KB
/
Copy pathcs_package.py
File metadata and controls
265 lines (195 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# -*- coding: utf-8 -*-
# Package information, generated from cs_package.py.in by make.
#-------------------------------------------------------------------------------
# This file is part of code_saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2022 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
#-------------------------------------------------------------------------------
import configparser
import os
import sys
try:
from code_saturne.base import cs_config
except Exception:
import cs_config
r_config_file_path = None
r_config_dict = {}
# Package information
#--------------------
class package:
def __init__(self,
scriptdir=None,
alternate_config=False,
config_file=r_config_file_path,
install_prefix=None,
install_mode=False,
name='code_saturne'):
# Global variables
global r_config_file_path
global r_config_dict
# Load configration from file if needed and not already done.
config_dict = r_config_dict
if config_file and config_file != r_config_file_path:
config_parser = configparser.ConfigParser()
config_parser.read(config_file)
config_dict = dict(config_parser)
if alternate_config == False: # Cache result in case of new call
r_config_file_path = config_file
r_config_dict = config_dict
base_package = 'code_saturne'
# System configuration (compilers, pre-requisites, ...)
self.config = cs_config.config(config_dict)
# Package information
# -------------------
self.name = name
d = config_dict.get('package', {})
for k in ('pkgversion', 'string', 'bugreport', 'url',
'version', 'version_full', 'version_short',
'revision'):
fallback = '<' + str(k) + ':undefined>'
s = d.get(k, fallback)
setattr(self, k, s)
self.code_name = "Code_Saturne"
self.preprocessor = "cs_preprocess" + self.config.exeext
self.solver = self.config.solver_modules[name]['solver']
self.check_syntax = "cs_check_syntax" + self.config.exeext
self.io_dump = "cs_io_dump" + self.config.exeext
self.runcase = "runcase" + self.config.shext
self.runsolver = "run_solver" + self.config.shext
self.configfile = "code_saturne" + self.config.cfgext
self.scratchdir = 'tmp_Saturne'
# Installation directories
# ------------------------
if install_prefix is None:
install_prefix = os.getenv('CS_ROOT_DIR')
python_version = "%d.%d" % (sys.version_info.major, sys.version_info.minor)
pythondir_rel = os.path.join('lib', 'python' + python_version,
'site-packages')
# Otherwise, assume that the standard tree structure is used
if install_prefix is None:
install_prefix = os.path.dirname(os.path.realpath(__file__))
i = install_prefix.find(pythondir_rel)
if i > -1:
install_prefix = os.path.dirname(install_prefix[:i+1])
exec_prefix = install_prefix
pythondir = os.path.join(exec_prefix, pythondir_rel)
datarootdir = os.path.join(install_prefix, 'share')
self.dirs = {'prefix': install_prefix,
'exec_prefix': exec_prefix,
'bindir': os.path.join(exec_prefix, 'bin'),
'includedir': os.path.join(exec_prefix, 'include'),
'pkgincludedir': os.path.join(install_prefix, 'include',
base_package),
'libdir': os.path.join(exec_prefix, 'lib'),
'libexecdir': os.path.join(exec_prefix, 'libexec'),
'pkglibexecdir': os.path.join(exec_prefix, 'libexec',
base_package),
'pythondir': pythondir,
'pkgpythondir': os.path.join(pythondir, base_package),
'localedir': os.path.join(datarootdir, 'locale'),
'datarootdir': datarootdir,
'datadir': datarootdir,
'pkgdatadir': os.path.join(datarootdir, base_package),
'docdir': os.path.join(datarootdir, 'doc', base_package),
'sysconfdir': os.path.join(install_prefix, 'etc')}
# If the build is not relocatable, read paths from configuration
if self.config.features['relocatable'] == "no" or install_mode:
d = config_dict.get('install', {})
for k in d.keys():
self.dirs[k] = d[k]
# Adjust docdir for additional modules.
# We should try to find a cleaner/more consistant solution,
# perhaps storing all documents in the main module's
# directory (code_saturne).
docdir_1 = self.dirs['docdir']
docdir_1 = os.path.join(os.path.split(docdir_1)[0], name)
self.dirs['docdir'] = os.path.join(os.path.split(docdir_1)[0], name)
def get_dir(self, installdir):
return self.dirs[installdir]
def get_preprocessor(self):
if self.config.features['frontend'] == "no":
raise Exception("This " + self.name + " build does not " + \
"include the front-end and Preprocessor.")
return os.path.join(self.get_dir("pkglibexecdir"),
self.preprocessor)
def get_io_dump(self):
return os.path.join(self.get_dir("pkglibexecdir"),
self.io_dump)
def get_solver(self):
return os.path.join(self.get_dir("pkglibexecdir"),
self.solver)
def get_check_syntax(self):
return os.path.join(self.get_dir("pkglibexecdir"),
self.check_syntax)
def get_io_dump(self):
return os.path.join(self.get_dir("pkglibexecdir"),
self.io_dump)
def get_global_configfile(self):
# Windows: C:\ProgramData
# Linux and co: /etc
if sys.platform.startswith("win"):
configdir = os.path.join(os.getenv("PROGRAMDATA"),
self.code_name, self.version_short)
else:
configdir = self.get_dir("sysconfdir")
return [os.path.join(configdir, self.configfile)]
def get_user_configfile(self):
# Windows: C:\Users\{user}\AppData\Roaming
# Linux and co: /home/{user} (or similar)
if sys.platform.startswith("win"):
configdir = os.path.join(os.getenv("APPDATA"),
self.code_name, self.version_short)
return [os.path.join(configdir, self.configfile)]
else:
configdir = os.path.expanduser("~")
return [os.path.join(configdir, "." + self.configfile)]
def get_configfiles(self):
u_cfg = self.get_user_configfile()
g_cfg = self.get_global_configfile()
return g_cfg + u_cfg
def get_batchdir(self):
return os.path.join(self.get_dir("pkgdatadir"),
'batch')
def get_pkgdatadir_script(self, script):
return os.path.join(self.get_dir("pkgdatadir"),
script)
def get_alternate_version(self, version):
"""
Return alternate version package object
"""
if not version:
return self
pkg = None
# Determine path (by absolute or local name)
pythondir = os.path.normpath(version)
prefix = os.path.normpath(self.get_dir("exec_prefix"))
if not os.path.isabs(version):
version = os.path.join(os.path.split(prefix)[0], version)
prefix = os.path.normpath(version)
config_file = os.path.join(prefix, 'lib', 'code_saturne_build.cfg')
# load alternate package
pkg = package(alternate_config=True,
name=self.name,
config_file=config_file,
install_prefix=prefix)
return pkg
def get_cross_compile(self):
"""
Return cross-conpilation info
"""
return self.config.features['build_os']
#-------------------------------------------------------------------------------