Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / Tools / padder / unittests / usecase_meshJobManager.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2012  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author(s): Guillaume Boulant (23/03/2011)
21 #
22
23 # This script illustrates the standard use case of the component
24 # MeshJobManager from within a SALOME script.
25
26
27 #
28 # Preparing the configuration parameters
29 #
30 import os
31 from salome.smesh.spadder.configreader import ConfigReader, printConfig
32
33 configReader = ConfigReader()
34 defaultConfig = configReader.getDefaultConfig()
35 printConfig(defaultConfig)
36
37 from salome.smesh import spadder
38 file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
39 file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
40
41 import salome
42 import MESHJOB
43
44 #
45 # Setup the configuration in the component. When first have to load
46 # the catalog of SPADDER components, then load the component
47 # MeshJobManager, and finally configure this component.
48 #
49 spadder.loadSpadderCatalog()
50
51 salome.salome_init()
52 component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
53 config = MESHJOB.ConfigParameter(resname=defaultConfig.resname,
54                                  binpath=defaultConfig.binpath,
55                                  envpath=defaultConfig.envpath)
56 component.configure("localhost",config)
57
58 #
59 # Prepare the job parameters and initialize the job
60 #
61 meshJobParameterList = []
62 param = MESHJOB.MeshJobParameter(file_name=file_concrete,
63                                  file_type=MESHJOB.MED_CONCRETE,
64                                  group_name="concrete")
65 meshJobParameterList.append(param)
66
67 param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
68                                  file_type=MESHJOB.MED_STEELBAR,
69                                  group_name="steelbar")
70 meshJobParameterList.append(param)
71 jobid = component.initialize(meshJobParameterList, "localhost")
72
73 #
74 # Start the execution of the job identified by its job id.
75 #
76 ok=component.start(jobid)
77
78 #
79 # This part illustrates how you can follow the execution of the job.
80 #
81 run_states = ["CREATED", "IN_PROCESS", "QUEUED", "RUNNING", "PAUSED"];
82 end_states = ["FINISHED", "ERROR"]
83 all_states = run_states+end_states;
84
85 ended  = False
86 nbiter = 0
87 import time
88 while not ended:
89     state = component.getState(jobid)
90     print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
91     if state not in run_states:
92         ended=True
93     time.sleep(0.5)
94     nbiter+=1
95         
96 if state not in end_states:
97     print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
98 else:
99     print "OK:  jobid = "+str(jobid)+" ended with state="+str(state)
100     meshJobResults = component.finalize(jobid)
101     print meshJobResults
102     print "You will find the results files in the directory:\n%s"%meshJobResults.results_dirname