You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.3 KiB

# Copyright (C) 2005-2023 Splunk Inc. All Rights Reserved.
import sys
import os
try:
from splunk.clilib.bundle_paths import make_splunkhome_path
except ImportError:
# Added the below method for DATF compatibility
def make_splunkhome_path(path_list):
relpath = os.path.normpath(os.path.join(*path_list))
splunk_home = os.environ.get("SPLUNK_HOME", '')
fullpath = os.path.normpath(os.path.join(splunk_home, relpath))
# Check that we haven't escaped from intended parent directories.
if os.path.relpath(fullpath, splunk_home)[0:2] == '..':
raise ValueError('Illegal escape from parent directory "%s": %s' %
(splunk_home, fullpath))
return fullpath
def add_to_sys_path(paths, prepend=False):
for path in paths:
if prepend:
if path in sys.path:
sys.path.remove(path)
sys.path.insert(0, path)
elif path not in sys.path:
sys.path.append(path)
def add_python_version_specific_paths():
'''
Adds extra paths for libraries specific to Python2 or Python3,
determined at a runtime
'''
# We should not rely on core enterprise packages:
if sys.version_info >= (3, 0):
add_to_sys_path([make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib', 'py3'])], prepend=True)
else:
add_to_sys_path([make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib', 'py2'])], prepend=True)
# Common libraries like future
add_to_sys_path([make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib', 'py23'])], prepend=True)
from six.moves import reload_module
try:
if 'future' in sys.modules:
import future
reload_module(future)
except Exception:
'''noop: future was not loaded yet'''
# Add lib path to import paths for packages
add_to_sys_path([make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib'])])
# Ensure the following paths are resolved first to avoid potential conflicts from other apps
add_to_sys_path([make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib', 'SA_ITOA_app_common'])], prepend=True)
add_to_sys_path([make_splunkhome_path(['etc', 'apps', 'SA-UserAccess', 'lib'])])
# Add extra python2 or python3 paths
add_python_version_specific_paths()