Commit e960529f authored by Rashad Kanavath's avatar Rashad Kanavath

fix wrapper script for binary packages

we have to tip toe around otbcli script due to settings such as
PATH and PYTHONPATH in otbenv.profile and otbenv.bat.
Now the solution is not specific to binary packages but rather to
existence of otbenv which is only available in binary packages
parent a5087c62
......@@ -108,65 +108,58 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
self.setActive(False)
raise ValueError(self.tr("Cannot find '{}'. OTB will be disabled".format(os.path.join(v,'bin', otb_exe_file('otbApplicationLauncherCommandLine')))))
# install_dir #otb issue 1557
version_file = os.path.join(v, 'share', 'doc', 'OTB-6.6', 'VERSION')
# build_dir
if not os.path.isfile(version_file):
version_file = os.path.join(v, 'VERSION')
if os.path.isfile(version_file):
with open(version_file) as vf:
vlines = vf.readlines()
vlines = [l.strip() for l in vlines]
vline = vlines[0]
if 'OTB Version:' in vline:
self.version = vline.split(':')[1].strip()
#ProcessingConfig.setSettingValue(OTBUtils.VERSION, self.version)
env_profile = os.path.join(v, 'otbenv.profile')
cli_filepath = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli')
if os.name == 'nt':
env_profile = os.path.join(v, 'otbenv.bat')
cli_filepath = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli.bat')
if os.path.isfile(env_profile):
lines = None
gdal_data_dir = None
geotiff_csv_dir = None
with open(env_profile) as f:
lines = f.readlines()
lines = [x.strip() for x in lines]
for line in lines:
if not line or line.startswith('#'):
continue
if 'GDAL_DATA=' in line:
gdal_data_dir = line
if 'GEOTIFF_CSV='in line:
geotiff_csv_dir = line
# print("GDAL_DATA", gdal_data_dir)
# print("GEOTIFF_CSV", geotiff_csv_dir)
first_line = '#!/bin/sh'
export_cmd = 'export '
otb_app_launcher = os.path.join(v, 'bin', otb_exe_file('otbApplicationLauncherCommandLine'))
cli_filepath = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli')
if os.name == 'nt':
first_line = '@echo off'
export_cmd = 'set '
cli_filepath = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli.bat')
if not os.path.exists(cli_filepath) or not os.path.isfile(cli_filepath):
with open(cli_filepath, 'w') as otb_cli_file:
otb_cli_file.write(first_line + os.linesep)
otb_cli_file.write(export_cmd + 'LC_NUMERIC=C' + os.linesep)
otb_cli_file.write(export_cmd + 'GDAL_DATA=' + gdal_data_dir + os.linesep)
otb_cli_file.write(export_cmd + 'GDAL_DRIVER_PATH=disable' + os.linesep)
otb_cli_file.write(export_cmd + 'GEOTIFF_CSV=' + geotiff_csv_dir + os.linesep)
otb_app_dirs = OTBUtils.appFolder()
otb_cli_file.write(export_cmd + 'OTB_APPLICATION_PATH=' + otb_app_dirs + os.linesep)
if os.name == 'nt':
otb_cli_file.write(otb_app_launcher + " %*" + os.linesep)
else:
otb_cli_file.write(otb_app_launcher + " $@" + os.linesep)
if not os.name == 'nt':
os.chmod(cli_filepath, 0o744)
self.write_otbcli_wrapper_script(v)
# if OTBUtils.appFolder() is None:
# ProcessingConfig.setSettingValue(OTBUtils.APP_FOLDER, os.path.join(v, 'lib', 'otb', 'applications'))
def write_otbcli_wrapper_script(self, otb_install_dir):
app_vargs = " $@"
export_cmd = 'export '
first_line = '#!/bin/sh'
env_profile = os.path.join(v, 'otbenv.profile')
otb_app_launcher = os.path.join(v, 'bin', 'otbApplicationLauncherCommandLine')
cli_filepath = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli')
lines = None
gdal_data_dir = None
geotiff_csv_dir = None
with open(env_profile) as f:
lines = f.readlines()
lines = [x.strip() for x in lines]
for line in lines:
if not line or line.startswith('#'):
continue
if 'GDAL_DATA=' in line:
gdal_data_dir = line
if 'GEOTIFF_CSV='in line:
geotiff_csv_dir = line
if os.name == 'nt':
app_vargs = " %*"
export_cmd = 'SET '
first_line = ':: Setup environment for OTB package. Generated by QGIS plugin'
otb_app_launcher = os.path.join(otb_install_dir, 'bin', 'otbApplicationLauncherCommandLine.exe')
cli_filepath = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli.bat')
gdal_data_dir = os.path.join(otb_install_dir, 'share' , 'data')
geotiff_csv_dir = os.path.join(otb_install_dir, 'share' , 'epsg_csv')
with open(cli_filepath, 'w') as otb_cli_file:
otb_cli_file.write(first_line + os.linesep)
otb_cli_file.write(export_cmd + "LC_NUMERIC=C" + os.linesep)
otb_cli_file.write(export_cmd + "GDAL_DRIVER_PATH=disable" + os.linesep)
otb_cli_file.write(export_cmd + "GDAL_DATA=\"" + gdal_data_dir + "\"" + os.linesep)
otb_cli_file.write(export_cmd + "GEOTIFF_CSV=\"" + geotiff_csv_dir + "\"" + os.linesep)
otb_cli_file.write(export_cmd + "OTB_APPLICATION_PATH=\"" + OTBUtils.appFolder() + "\"" + os.linesep)
otb_cli_file.write("\"" + otb_app_launcher + "\"" + app_vargs + os.linesep)
if not os.name == 'nt':
os.chmod(cli_filepath, 0o744)
def load(self):
group = self.name()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment