From 766fb176e1944e953bc744cc22e4eb15f577c11b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABlle=20USSEGLIO?= <gaelle.usseglio@cnes.fr>
Date: Mon, 14 Sep 2020 09:15:31 +0000
Subject: [PATCH] ENH : Add a parameter for tmp dir into SAR_MultiSlc_IW

---
 json_schemas/schema_MultiSlc_IW.json          |  3 ++-
 python_src/SAR_MultiSlc_IW.py                 | 21 +++++++++++++++----
 .../ex_config/ex_config_MultiSlc_IW.json      |  3 ++-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/json_schemas/schema_MultiSlc_IW.json b/json_schemas/schema_MultiSlc_IW.json
index b74d7b7..48ff17d 100644
--- a/json_schemas/schema_MultiSlc_IW.json
+++ b/json_schemas/schema_MultiSlc_IW.json
@@ -43,7 +43,8 @@
 		    "additionalProperties": false,
 		    "properties": {"clean": {"type": "string", "default": "yes"},
 				   "burst_index": {"type": "string", "default": "0-8"},
-				  "optram": {"type": "number", "default": 4000}}
+				   "optram": {"type": "number", "default": 4000},
+				   "tmpdir_into_outputdir": {"type": "string", "default": "yes"}}
 		}
 	    },
 	    "additionalProperties": false,
diff --git a/python_src/SAR_MultiSlc_IW.py b/python_src/SAR_MultiSlc_IW.py
index 854c9e4..74b50ca 100644
--- a/python_src/SAR_MultiSlc_IW.py
+++ b/python_src/SAR_MultiSlc_IW.py
@@ -134,6 +134,7 @@ if __name__ == "__main__":
     burst_index = "0-8"
     ram = str(4000)
     light_version = "yes"
+    tmpdir_into_outputdir = "no"
     if 'parameter' in dict_Global: 
         if 'optram' in dict_Global['parameter']:
             ram =  str(dict_Global['parameter']['optram'])
@@ -143,7 +144,10 @@ if __name__ == "__main__":
             light_version = dict_Global['parameter']['clean']
         if 'burst_index' in dict_Global['parameter']:
             burst_index = dict_Global['parameter']['burst_index']
+        if 'tmpdir_into_outputdir' in dict_Global['parameter']:
+            tmpdir_into_outputdir = dict_Global['parameter']['tmpdir_into_outputdir']
     light_version = func_utils.str2bool(light_version)
+    tmpdir_into_outputdir = func_utils.str2bool(tmpdir_into_outputdir)
     print(burst_index)###############################################################################
     exclude = "-9999"
     if 'Exclude' in dict_Global['in']:
@@ -500,7 +504,12 @@ if __name__ == "__main__":
         firstBurst = validBurstMaster[0]
         lastBurst = validBurstMaster[len(validBurstMaster)-1]
         # ===== Create directory for each burst
-        temp_dir = tempfile.mkdtemp()
+        temp_dir = ""
+        if tmpdir_into_outputdir :
+            temp_dir = tempfile.mkdtemp(dir=output_dir)
+        else :
+            temp_dir = tempfile.mkdtemp()
+
         for burstId in range(firstBurst, lastBurst+1):
             os.makedirs(os.path.join(temp_dir, "burst" + str(burstId)))
 
@@ -515,8 +524,13 @@ if __name__ == "__main__":
         if counter <= 1:
             func_utils.printOnStd("\n Master Pre_Processing chain \n")
             func_utils.log(logging.INFO, "Master Pre_Processing Application")
-            Master_temp_dir = tempfile.mkdtemp()
-
+            
+            Master_temp_dir = ""
+            if tmpdir_into_outputdir :
+                Master_temp_dir = tempfile.mkdtemp(dir=master_data_dir)
+            else :
+                Master_temp_dir = tempfile.mkdtemp()
+            
             for id_loop in range(0, len(validBurstMaster)):
                 burstId = validBurstMaster[id_loop]
                 os.makedirs(os.path.join(Master_temp_dir, "burst" + str(burstId)))
@@ -588,7 +602,6 @@ if __name__ == "__main__":
         # Slave
         func_utils.printOnStd("\n Slave Ground chain \n")
         func_utils.log(logging.INFO, "Slave Ground Application")
-        slave_demproj_dir = tempfile.mkdtemp()
 
         paramGroundSlave = {}
         paramGroundSlave['nodata'] = -32768
diff --git a/python_src/ex_config/ex_config_MultiSlc_IW.json b/python_src/ex_config/ex_config_MultiSlc_IW.json
index f86a423..8079915 100644
--- a/python_src/ex_config/ex_config_MultiSlc_IW.json
+++ b/python_src/ex_config/ex_config_MultiSlc_IW.json
@@ -18,7 +18,8 @@
         {
             "clean" : "true",
             "burst_index": "0-8",
-            "optram" : 256
+            "optram" : 256,
+	    "tmpdir_into_outputdir": "yes"
         }
     },
 
-- 
GitLab