Skip to content
Snippets Groups Projects
Unverified Commit 176068fb authored by Xavier Robin's avatar Xavier Robin
Browse files

fix: SCHWED-5913 support bad OST_ROOT

parent cf3fb6f0
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,14 @@ class StreamLogSink(LogSink): ...@@ -32,6 +32,14 @@ class StreamLogSink(LogSink):
self._stream.write(message) self._stream.write(message)
def _GetPrefixFromPythonPath():
"""Get the prefix from this file's path"""
prefix_path = __file__
for _ in range(5):
prefix_path = os.path.dirname(prefix_path)
return prefix_path
def _SetupOstPrefix(): def _SetupOstPrefix():
""" This function attempts to set the OST prefix path if $OST_ROOT was not """ This function attempts to set the OST prefix path if $OST_ROOT was not
set already. set already.
...@@ -44,12 +52,11 @@ def _SetupOstPrefix(): ...@@ -44,12 +52,11 @@ def _SetupOstPrefix():
try: try:
# $OST_ROOT was set # $OST_ROOT was set
# Note: this doesn't mean set to a valid prefix
GetPrefixPath() GetPrefixPath()
except RuntimeError: except RuntimeError:
# Setup from this file's path # Setup from this file's path
prefix_path = __file__ prefix_path = _GetPrefixFromPythonPath()
for _ in range(5):
prefix_path = os.path.dirname(prefix_path)
SetPrefixPath(prefix_path) SetPrefixPath(prefix_path)
...@@ -71,6 +78,8 @@ def _SetupCompoundsLib(): ...@@ -71,6 +78,8 @@ def _SetupCompoundsLib():
1. The $OST_COMPOUNDS_CHEMLIB environment variable 1. The $OST_COMPOUNDS_CHEMLIB environment variable
2. The 'compounds.chemlib' file in the shared path under the folder pointed 2. The 'compounds.chemlib' file in the shared path under the folder pointed
by the $OST_ROOT environment variable by the $OST_ROOT environment variable
3. The 'compounds.chemlib' file in the shared path under the OST prefix where
the ost python module is installed.
If no compound library can be loaded with any of these strategies, a warning If no compound library can be loaded with any of these strategies, a warning
message is issued. message is issued.
...@@ -94,6 +103,24 @@ def _SetupCompoundsLib(): ...@@ -94,6 +103,24 @@ def _SetupCompoundsLib():
else: else:
return return
# If OST_ROOT was pointing to a root with no compound lib or to an invalid
# root, try
try:
old_prefix = GetPrefixPath() # This is set by now and won't raise
prefix_path = _GetPrefixFromPythonPath()
SetPrefixPath(prefix_path)
compound_lib_path = os.path.join(GetSharedDataPath(), 'compounds.chemlib')
_TrySetCompoundsLib(compound_lib_path)
except (RuntimeError, ValueError):
SetPrefixPath(old_prefix)
else:
# If we're here, OST root was set but the prefix did not contain a compound
# lib, but the root obtained from the python path contained one.
# Most likely OST_ROOT was set incorrectly
LogWarning("$OST_ROOT is pointing to an invalid OST prefix: '%s'" % (
os.getenv("OST_ROOT")))
return
LogWarning("Compound library not available. Some functionality may not " \ LogWarning("Compound library not available. Some functionality may not " \
"work as expected.") "work as expected.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment