/usr/lib/aster/Stanley/salomeRunScript.py is in code-aster 11.5.0+dfsg2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # coding=utf-8
# CONFIGURATION MANAGEMENT OF EDF VERSION
# ======================================================================
# COPYRIGHT (C) 1991 - 2012 EDF R&D WWW.CODE-ASTER.ORG
# 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 EDF R&D CODE_ASTER,
# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
# ======================================================================
import tempfile
import re
import os
debug = False
# ----------------------------------------------------------------------------------------------------------------------
def MakeTempScript(SALOMESCRIPT, **args):
"""
Construit un nouveau script en remplacant les variables par leur valeur
args contient le dictionnaire des champs a remplacer (entoures de $ dans le script) et leur valeur
"""
try:
import aster
from Utilitai.Utmess import UTMESS
except:
def UTMESS(code='I', txt='',valk='', vali='', valr=''):
print 'Le champs :"%s" n''a pas été trouvé dans le script Salome, mais il n''est peut être pas nécessaire.' % valk
try:
# Recupere le script Salome
f = open(SALOMESCRIPT, 'r')
txt = f.read()
f.close()
# Remplace les champs par leur valeur
for para, pval in args.items():
#print para, pval
if pval: pval = "'%s'" % str(pval)
else: pval = "''"
if not txt.find(para)!=-1: UTMESS('I', 'EXECLOGICIEL0_19', valk=para)
exp = re.compile('^( *)(%s *=.*)$' % para, re.MULTILINE)
txt = exp.sub('\g<1>%s = %s' % (para, pval), txt)
# Ecrire le nouveau script
fw = tempfile.NamedTemporaryFile(mode='w', suffix='.py')
# tmpfile = fw.name
tmpfile = os.path.join(os.getcwd(), os.path.basename(fw.name) )
fw.close()
# tmpfile = TempFileName(mode='w', suffix='.py')
fw = open(tmpfile, 'w')
fw.write( txt + '\n' )
fw.close()
except Exception, e:
raise Exception("Erreur : \n%s" % e)
if debug: print "tmpfile: %s" % tmpfile
return tmpfile
# ----------------------------------------------------------------------------------------------------------------------
def DelTempScript(SALOMESCRIPT):
"""
Efface le script temporaire
"""
try:
os.remove(SALOMESCRIPT)
except Exception, e:
print "Impossible d'effacer le script : %s\n\nErreur : %s" % (SALOMESCRIPT, e)
# ----------------------------------------------------------------------------------------------------------------------
def RunScript(SALOMESCRIPT, CHOIX, INPUTFILE):
"""
Lance le script temporaire et l'efface
"""
tmpfile = MakeTempScript( SALOMESCRIPT=SALOMESCRIPT, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
if not debug: DelTempScript(tmpfile)
# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
if __name__ == '__main__':
# --------------------------------------------------------
# ---------------------------------------------------------
# Tests unitaire a lancer depuis Salome
# Remplacer les deux chemins ci-dessous par vos surcharges, sinon le script tentera de detecter l'installation d'Aster
# root_astest = '/home/assire/DEV/PYLOTAGE/astest'
# salomeScript = '/home/assire/DEV/PYLOTAGE/bibpyt/Templates/salomeScript.py'
root_astest = ''
salomeScript = ''
# ---------------------------------------------------------
# ---------------------------------------------------------
# Essaye de detecter le repertoire d'Aster
lst_aster = ['/aster', '/local00/aster', '/home/aster']
lst_vers = ['NEW11', 'NEW10', 'NEW9', 'STA11.3', 'STA11.2', 'STA11.1', 'STA10.3', 'STA10.2', 'STA10.1']
# Essaye de detecter le script Salome
if not salomeScript or not os.path.isfile(salomeScript):
salomeScript = False
for rep in lst_aster:
for vers in lst_vers:
p = os.path.join(rep, vers)
script = os.path.join(p, 'bibpyt', 'Templates', 'salomeScript.py')
if os.path.isfile(script):
salomeScript = script
root_astest = os.path.join(p, 'astest')
print "Script Salome detecte : %s" % salomeScript
break
# Essaye de detecter le repertoire astest
if not root_astest or not os.path.isdir(root_astest):
root_astest = False
for rep in lst_aster:
for vers in lst_vers:
p = os.path.join(rep, vers)
astest = os.path.join(p, 'astest')
if os.path.isdir(astest):
root_astest = astest
print "Repertoire astest detecte : %s" % root_astest
break
if not root_astest:
raise Exception("Impossible de detecter le repertoire Aster. Remplir la variable root_astest.")
if not salomeScript:
raise Exception("Impossible de detecter le script Salome. Remplir la variable salomeScript.")
# Les fichiers de donnes sont des fichiers du test zzzz141a
prefix = os.path.join(root_astest, 'zzzz141a.')
# ---------------------------------------------------------
# ---------------------------------------------------------
# Tests unitaires
# Detection des etudes Salome
script = os.path.join( os.path.dirname(salomeScript), 'salomeGetStudies.py' )
tmpfile = MakeTempScript( SALOMESCRIPT=script )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
CHOIX = 'DEPL'
INPUTFILE = prefix + '91' # Stanley_DEPL.rmed
tmpfile = MakeTempScript( SALOMESCRIPT=salomeScript, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
CHOIX = 'GAUSS'
INPUTFILE = prefix + '92' # Stanley_ELGA.rmed
tmpfile = MakeTempScript( SALOMESCRIPT=salomeScript, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
CHOIX = 'ISO'
INPUTFILE = prefix + '93' # Stanley_NOEU.rmed
tmpfile = MakeTempScript( SALOMESCRIPT=salomeScript, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
CHOIX = 'ISO'
INPUTFILE = prefix + '94' # Stanley_ELNO.rmed
tmpfile = MakeTempScript( SALOMESCRIPT=salomeScript, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
CHOIX = 'COURBE'
INPUTFILE = prefix + '95' # Stanley_Table.txt
tmpfile = MakeTempScript( SALOMESCRIPT=salomeScript, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
CHOIX = 'ON_DEFORMED'
INPUTFILE = prefix + '96' # Stanley_SIGM_DEPL.rmed
tmpfile = MakeTempScript( SALOMESCRIPT=salomeScript, CHOIX=CHOIX, INPUTFILE=INPUTFILE, OUTPUTFILE=False, STUDY=False )
execfile(r"%s" % tmpfile)
DelTempScript(tmpfile)
|