Skip to content
Snippets Groups Projects
Commit c7fcce54 authored by Gaëlle USSEGLIO's avatar Gaëlle USSEGLIO
Browse files

ENH : Display OTB and DiapOTB version in log file

parent 7a9a98e2
No related branches found
No related tags found
3 merge requests!52Merge for v1.1.0,!50Finalize Python chains (v1.1.0),!49Add python tests
...@@ -44,9 +44,11 @@ import time ...@@ -44,9 +44,11 @@ import time
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from enum import Enum from enum import Enum
import h5py import h5py
import subprocess
from diapotb.lib.core.DiapOTBExceptions import DiapOTBException from diapotb.lib.core.DiapOTBExceptions import DiapOTBException
from diapotb.lib.core.DiapOTBEnums import Satellite from diapotb.lib.core.DiapOTBEnums import Satellite
from diapotb.__meta__ import __version__
import otbApplication as otb import otbApplication as otb
...@@ -96,6 +98,10 @@ class MetadataKeyInGeom(Enum): ...@@ -96,6 +98,10 @@ class MetadataKeyInGeom(Enum):
return self.value return self.value
# TODO : Gather and re-deifne some functions
# TODO : Find an uniform format for our logger
# Streamer to our log file # Streamer to our log file
class StreamToLogger(object): class StreamToLogger(object):
""" """
...@@ -161,6 +167,9 @@ def init_filelog(output_dir): ...@@ -161,6 +167,9 @@ def init_filelog(output_dir):
STDOUT_SAVE.write = stdout_save_write # Restore stdout.write into STDOUT_SAVE STDOUT_SAVE.write = stdout_save_write # Restore stdout.write into STDOUT_SAVE
STDOUT_SAVE.flush = stdout_save_flush # Restore stdout.write into STDOUT_SAVE STDOUT_SAVE.flush = stdout_save_flush # Restore stdout.write into STDOUT_SAVE
# Print current versions
log_otb_diapotb_versions()
def log(level, msg): def log(level, msg):
""" """
...@@ -176,6 +185,32 @@ def print_on_std(msg): ...@@ -176,6 +185,32 @@ def print_on_std(msg):
# Print on STDOUT_SAVE aka the original/true stdout # Print on STDOUT_SAVE aka the original/true stdout
print(msg, file=STDOUT_SAVE) print(msg, file=STDOUT_SAVE)
def otb_version():
""" Get the current OTB version (through ReadImageInfo)
Call ReadImageInfo -version only once (result is cached)
"""
if "version" not in otb_version.__dict__:
try:
r = subprocess.run(['otbcli_ReadImageInfo', '-version'], stdout=subprocess.PIPE , stderr=subprocess.STDOUT )
version = r.stdout.decode('utf-8').strip('\n')
version = re.search(r'\d+(\.\d+)+$', version)[0]
otb_version.version = version
except Exception as exp:
raise RuntimeError("Cannot retrieve current OTB version : {exp}".format(exp=exp))
return otb_version.version
def log_otb_diapotb_versions():
""" Log OTB and DiapOTB versions
"""
msg = "Current versions are : {diapotb_version} for DiapOTB (python scripts) and " \
"{otb_version} for OTB"
msg = msg.format(diapotb_version=__version__, otb_version=otb_version())
logger.log(logging.INFO, msg)
def exception_tolerance(func): def exception_tolerance(func):
"""Decorator to allow exceptions in some cases (ie : in SARMultiSlc*) """Decorator to allow exceptions in some cases (ie : in SARMultiSlc*)
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment