-
Notifications
You must be signed in to change notification settings - Fork 0
/
BVServiceOpenFLUID.py
175 lines (115 loc) · 5.79 KB
/
BVServiceOpenFLUID.py
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
import os
import time
#import datetime
import subprocess
import shutil
#from BVServiceWPSProcess import BVServiceWPSProcess
#=============================================================================
#=============================================================================
# TODO
# - be consistent on local temporary directories
#=============================================================================
#=============================================================================
class BVServiceOpenFLUID:
def __init__(self,Project,Parameters):
self.Parameters = Parameters
self.CurrentDateTime = time.strftime("%Y%m%d-%H%M%S")
# self.SourceProjectsPath = "/var/bvservice/projects"
self.SourceProjectsPath = "/home/utop/bvservice/projects"
self.ProjectToRun = Project
self.ExecPath = "/tmp/BVServiceOpenFLUID"
self.SourceProject = self.SourceProjectsPath +"/"+ self.ProjectToRun
self.ExecProject = self.ExecPath +"/"+ self.ProjectToRun +"_"+ self.CurrentDateTime
# self.ExecProject = self.ExecPath +"/"+ self.ProjectToRun
self.ExecIN = self.ExecProject +"/IN"
self.ExecOUT = self.ExecProject +"/OUT"
self.ProcessLogfile = self.ExecProject+"/process.log"
# self.CurrentDateTime = time.strftime("%Y%m%d-%H%M%S")
#=============================================================================
#=============================================================================
def prepare(self):
shutil.rmtree(self.ExecProject,ignore_errors=True)
os.makedirs(self.ExecProject)
shutil.copytree(self.SourceProject+"/IN",self.ExecIN)
with open(self.ProcessLogfile, 'w') as Log:
Log.write("Process launched at "+self.CurrentDateTime+"\n")
Log.write("Parameters:\n")
Log.write(str(self.Parameters)+"\n")
Log.write("\n\n")
#=============================================================================
#=============================================================================
#=============================================================================
#=============================================================================
def run(self):
Command = ["openfluid","run","-p","/home/utop/.openfluid/wares/simulators/","-c",self.ExecIN,self.ExecOUT]
#Command = ["openfluid","run","-c",self.ExecIN,self.ExecOUT]
# openfluid run -p /root/.openfluid/wares/simulators -c /home/utop/bvservice/projects/BourdicOF_haies/IN /home/utop/bvservice/projects/BourdicOF_haies/OUT
Env = os.environ.copy()
Env["LD_LIBRARY_PATH"] = "/opt/lib"
with open(self.ProcessLogfile, 'a') as Log:
P = subprocess.Popen(Command,env=Env,stdout=Log,stderr=Log)
P.communicate()
P.wait()
#=============================================================================
#=============================================================================
def publishLayers(self):
# CurrentDateTime = self.CurrentDateTime
with open(self.ProcessLogfile,'a') as Log:
Log.write('\n')
Log.write("============== Publishing ==============\n\n")
for Layer,Params in self.Parameters["publishing"].iteritems():
# # setup of coordinate system
# Command = ['ogr2ogr',
# '-f','ESRI Shapefile',
# '-a_srs','EPSG:2154',
# self.ExecOUT+Params["outsubdir"]+'/'+Params["fileroot"]+self.CurrentDateTime+'.shp',
# self.ExecOUT+Params["outsubdir"]+'/'+Params["fileroot"]+'.shp']
#
# with open(self.ProcessLogfile,'a') as Log:
# Log.write(' '.join(Command))
# Log.write('\n')
# Log.write('\n')
#
#
# with open(self.ProcessLogfile,'a') as Log:
# P = subprocess.Popen(Command,stdout=Log,stderr=Log)
# P.communicate()
# P.wait()
# publication to bvservice.fr
Command = ['python',os.path.dirname(os.path.abspath(__file__))+'/layerpublisher.py',
# '--l',Params["fileroot"]+self.CurrentDateTime,
'--l',Params["fileroot"],
'--g','http://bvservice.fr/outputs/',
# '--d',self.ExecOUT+Params["outsubdir"]+'/',
'--d',self.ExecOUT+'/',
'--p','testadmin:corsen292!',
'--w',Params["workspace"],
'--st',Params["store"]+self.CurrentDateTime,
'--s',Params["sld"]]
# self.Parameters["publishing"][Layer]["wms"] = 'http://bvservice.fr/outputs/wms?'+Params["workspace"]+':'+Params["fileroot"]+self.CurrentDateTime
self.Parameters["publishing"][Layer]["wms"] = 'http://bvservice.fr/outputs/wms?'+Params["workspace"]+':'+Params["fileroot"]
with open(self.ProcessLogfile,'a') as Log:
Log.write('\n')
Log.write('\n')
Log.write(' '.join(Command))
Log.write('\n')
with open(self.ProcessLogfile, 'a') as Log:
P = subprocess.Popen(Command,stdout=Log,stderr=Log)
P.communicate()
P.wait()
#=============================================================================
#=============================================================================
def getPublishedLayer(self,Name):
return self.Parameters["publishing"][Name]["wms"]
#=============================================================================
#=============================================================================
def getVersion(self):
return subprocess.check_output(["openfluid","--version"]).replace("\n","")
#=============================================================================
#=============================================================================
def getLog(self):
Contents = "Not found!"
if os.path.isfile(self.ProcessLogfile):
with open (self.ProcessLogfile, "r") as Log:
Contents = Log.read()
return Contents