# -*- coding: iso-8859-1 -*- # #------------------------------------------------------------------------------- # Code_Saturne version 1.3 # ------------------------ # # # This file is part of the Code_Saturne User Interface, element of the # Code_Saturne CFD tool. # # Copyright (C) 1998-2007 EDF S.A., France # # contact: saturne-support@edf.fr # # The Code_Saturne User Interface 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. # # The Code_Saturne User Interface 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 the Code_Saturne Kernel; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA # #------------------------------------------------------------------------------- """ This module modify the "lance" script file - BatchRunningModel """ #------------------------------------------------------------------------------- # Standard modules import #------------------------------------------------------------------------------- import sys, unittest import os, sys, string, types, re #------------------------------------------------------------------------------- # Library modules import #------------------------------------------------------------------------------- import Base.Toolbox as Tool from SolutionDomainModel import SolutionDomainModel from CoalCombustion import CoalCombustionModel #------------------------------------------------------------------------------- # Class BatchRunningModel #------------------------------------------------------------------------------- class BatchRunningModel: """ This class modify saturne running file (lance) """ def __init__(self, case): """ Simple constructor. """ self.case = case # we get up batch script file key = self.case['computer'] # FIXME: la ligne suivante est-elle utile ? if not self.case['batchScript'][key]: return self.script1 = self.case['scripts_path'] + "/" \ + self.case['batchScript'][key] self.saveBatchScriptFile() # Read the batch script file line by line. # All lines are stored in a list called "self.lines". # f = open(self.script1, 'rw') self.lines = f.readlines() f.close() # DicoValues's initialisation self.initDicoValues() def saveBatchScriptFile(self): """ Save a backup file before any modification. There is only one backup for the entire session. """ key = self.case['computer'] script2 = self.script1 + "~" if self.case['backupBatchScript'][key] == "no" \ or not os.path.isfile(script2): os.popen('cp ' + self.script1 + " " +script2) self.case['backupBatchScript'][key] = "yes" def initDicoValues(self): """ Tkinter variables declaration. """ self.dicoValues = {} self.dicoValues['IFOENV'] = '1' self.dicoValues['LONGIA'] = '0' self.dicoValues['LONGRA'] = '0' self.dicoValues['PARAM'] = "" self.dicoValues['VERSION'] = "" self.dicoValues['NOMBRE_DE_PROCESSEURS'] = '1' self.dicoValues['LISTE_PROCESSEURS'] = "" self.dicoValues['FICHIERS_DONNEES_UTILISATEUR'] = "" self.dicoValues['FICHIERS_RESULTATS_UTILISATEUR'] = "" self.dicoValues['CS_TMP_PREFIX'] = "" self.dicoValues['MAILLAGE'] = "" self.dicoValues['COMMANDE_RC'] = "" self.dicoValues['COMMANDE_DF'] = "" self.dicoValues['COMMANDE_PERIO'] = "" self.dicoValues['COMMANDE_SYRTHES'] = "" self.dicoValues['PBS_JOB_NAME'] = "" self.dicoValues['PBS_nodes'] = '1' self.dicoValues['PBS_ppn'] = '2' self.dicoValues['PBS_walltime'] = '1:00:00' self.dicoValues['PBS_mem'] = '320' self.dicoValues['MODE_EXEC'] = "" self.dicoValues['OPTIMISATION'] = "" self.dicoValues['LISTE_LIB_SAT'] = "" self.dicoValues['OPTION_LIB_EXT'] = "" self.dicoValues['VALGRIND'] = "" self.dicoValues['ARG_CS_OUTPUT'] = "" self.dicoValues['ARG_CS_VERIF'] = "" self.dicoValues['DONNEES_THERMOCHIMIE'] = "" model = CoalCombustionModel(self.case).getCoalCombustionModel() if model == 'coal_homo': self.dicoValues['DONNEES_THERMOCHIMIE'] = 'dp_FCP' def getRegex(self, word): """ Get regular expression to extract line without comment """ ## fonctionne mais incomplète: regex = re.compile(r"""(^\s*""" + word + r""".*$)""") ## fonctionne en tenant compte des lignes commencant par # : ## regex = re.compile(r"""(^(?#)^\s*""" + word + r""".*$)""") #tient compte à la fois des commentaires et des "$word": regex = re.compile(r"""(^(?#)^\s*(?