-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSE.py
97 lines (87 loc) · 4.26 KB
/
GSE.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
# coding=utf-8
# Copyright (C) 2020-2022 CS GROUP – France, https://www.csgroup.eu
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# author : Esquis Benjamin for CSGroup
#
import glob
import os
import shutil
import subprocess
from lxml import etree as et
import FileUtils
class GSE(object):
def __init__(self, exe_dir, version, gipp_dir, work_dir, sad_backup_dir, datastrip, sensing_start, sensing_stop,
logfile, errfile):
self._exe_dir = exe_dir
self._version = version
self._gipp_dir = gipp_dir
self._work_dir = work_dir
self._backup_dir = sad_backup_dir
self._datastrip = datastrip
self._sensing_start = sensing_start
self._sensing_stop = sensing_stop
self._logfilename = logfile
self._errfilename = errfile
def run(self):
# Find the needed GIPPs
gip_spamods = glob.glob(os.path.join(self._gipp_dir, "*GIP_SPAMOD*xml"))
if len(gip_spamods) == 0:
raise Exception("GSE: No SPAMOD in " + self._gipp_dir + " !!!!")
if len(gip_spamods) != 1:
raise Exception("GSE: More than one SPAMOD in " + self._gipp_dir + " : cannot decide")
the_gip_spamod = gip_spamods[0]
# patch JobOrder
gse_working_dir = os.path.join(self._work_dir, "GSE")
gse_backup_dir = os.path.join(gse_working_dir, "BACKUP_SAD")
gse_job_order = os.path.join(gse_working_dir, "JobOrderGSE.xml")
if not os.path.exists(gse_working_dir):
FileUtils.create_directory(gse_working_dir)
if not os.path.exists(gse_backup_dir):
FileUtils.create_directory(gse_backup_dir)
shutil.copy(os.path.join(os.path.dirname(os.path.realpath(__file__)), "data",
"JobOrderTemplates", "job_order_GSE_template.xml"),
gse_job_order)
tree_hdr = et.parse(gse_job_order)
root_hdr = tree_hdr.getroot()
sensing_start_node = root_hdr.xpath("//Ipf_Job_Order/Ipf_Conf/Sensing_Time/Start")[0]
sensing_start_node.text = self._sensing_start
sensing_stop_node = root_hdr.xpath("//Ipf_Job_Order/Ipf_Conf/Sensing_Time/Stop")[0]
sensing_stop_node.text = self._sensing_stop
version_node = root_hdr.xpath("//List_of_Ipf_Procs/Ipf_Proc/Task_Version")[0]
version_node.text = str(self._version)
filenames_nodes = root_hdr.xpath("//List_of_Ipf_Procs/Ipf_Proc/List_of_Inputs/Input"
"/List_of_File_Names/File_Name")
for f in filenames_nodes:
if f.text is not None:
f.text = f.text.replace("***DS_ANC_DATA***", os.path.join(self._datastrip, "ANC_DATA"))
f.text = f.text.replace("***GIP_SPAMOD***", the_gip_spamod)
filenames_nodes = root_hdr.xpath(
"//List_of_Ipf_Procs/Ipf_Proc/List_of_Outputs/Output/File_Name")
for f in filenames_nodes:
if f.text is not None:
f.text = f.text.replace("***DS_ANC_DATA***", os.path.join(self._datastrip, "ANC_DATA"))
f.text = f.text.replace("***WORK***", gse_working_dir)
f.text = f.text.replace("***DS_ANC_BACKUP_DATA***", self._backup_dir)
tree_hdr.write(gse_job_order, encoding="UTF-8")
# launch the process
logfile = open(self._logfilename, 'wb')
errfile = open(self._errfilename, 'wb')
gse_process = subprocess.Popen([
os.path.join(self._exe_dir, "GSE", self._version, "scripts", "GSE.bash"), gse_job_order]
, stdout=logfile, stderr=errfile)
gse_process.wait()
logfile.close()
errfile.close()
if gse_process.returncode != 0:
raise Exception("Problem launching GSE !!! check logs : "+self._logfilename + " / "+self._errfilename)