Here are the examples of the python api sys.python_path.insert taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: splunk-sdk-python Source File: app.py
def initialize():
from os import path
from sys import modules, path as python_path
import platform
module_dir = path.dirname(path.realpath(__file__))
system = platform.system()
for packages in path.join(module_dir, 'packages'), path.join(path.join(module_dir, 'packages', system)):
if not path.isdir(packages):
break
python_path.insert(0, path.join(packages))
configuration_file = path.join(module_dir, '_pydebug_conf.py')
if not path.exists(configuration_file):
return
debug_client = path.join(module_dir, '_pydebug.egg')
if not path.exists(debug_client):
return
_remote_debugging = {
'client_package_location': debug_client,
'is_enabled': False,
'host': None,
'port': 5678,
'suspend': True,
'stderr_to_server': False,
'stdout_to_server': False,
'overwrite_prev_trace': False,
'patch_multiprocessing': False,
'trace_only_current_thread': False}
execfile(configuration_file, {'__builtins__': __builtins__}, _remote_debugging)
python_path.insert(1, debug_client)
from splunklib.searchcommands import splunklib_logger as logger
import pydevd
def _settrace():
host, port = _remote_debugging['host'], _remote_debugging['port']
logger.debug('Connecting to Python debug server at %s:%d', host, port)
try:
pydevd.settrace(
host=host,
port=port,
suspend=_remote_debugging['suspend'],
stderrToServer=_remote_debugging['stderr_to_server'],
stdoutToServer=_remote_debugging['stdout_to_server'],
overwrite_prev_trace=_remote_debugging['overwrite_prev_trace'],
patch_multiprocessing=_remote_debugging['patch_multiprocessing'],
trace_only_current_thread=_remote_debugging['trace_only_current_thread'])
except SystemExit as error:
logger.error('Failed to connect to Python debug server at %s:%d: %s', host, port, error)
else:
logger.debug('Connected to Python debug server at %s:%d', host, port)
global remote_debugging
remote_debugging = _remote_debugging
global settrace
settrace = _settrace
global stoptrace
stoptrace = pydevd.stoptrace
remote_debugging_is_enabled = _remote_debugging['is_enabled']
if isinstance(remote_debugging_is_enabled, (list, set, tuple)):
app_name = path.splitext(path.basename(modules['__main__'].__file__))[0]
remote_debugging_is_enabled = app_name in remote_debugging_is_enabled
if remote_debugging_is_enabled is True:
settrace()
return