def _prependToEnvVar(self, newVal, envVar):
path = self._getEnvVarAsList(envVar)
foundValue = False
for entry in path:
# Search to determine if the new value is already in the path
try:
if os.path.samefile(entry, newVal):
# The value is already in the path
foundValue = True
break
except OSError:
# If we can't find concrete files to compare, fall back to string compare
if entry == newVal:
# The value is already in the path
foundValue = True
break
if not foundValue:
# The value does not already exist
if os.environ.has_key(envVar):
newpath = newVal+os.path.pathsep + os.getenv(envVar)+os.path.pathsep
else:
newpath = newVal+os.path.pathsep
os.putenv(envVar, newpath)
os.environ[envVar] = newpath
python类putenv()的实例源码
def __setitem__(self, key, value):
key = _norm_key(path2fsn(key))
value = path2fsn(value)
if is_win and PY2:
# this calls putenv, so do it first and replace later
try:
os.environ[_fsn2legacy(key)] = _fsn2legacy(value)
except OSError:
raise ValueError
try:
set_windows_env_var(key, value)
except WindowsError:
# py3+win fails for invalid keys. try to do the same
raise ValueError
try:
self._env[key] = value
except OSError:
raise ValueError
def setUp(self):
os.putenv("KMP_DUPLICATE_LIB_OK", "TRUE")
self.X_class, self.y_class = datasets.make_classification(random_state=42)
self.X_reg, self.y_reg = datasets.make_regression(random_state=42)
self.classification_optimizers = [XGBoostOptimizer, RandomForestOptimizer]
self.regression_optimizers = [XGBoostOptimizer, RandomForestOptimizer]
self.class_scorer = Scorer("auc_error", lambda y_pred, y_true: 1 - metrics.roc_auc_score(y_pred, y_true))
self.reg_scorer = Scorer("mse", metrics.mean_squared_error)
self.classification_task_split = \
Task("class_split", self.X_class, self.y_class, "classification", test_size=0.1, random_state=42)
self.regression_task_split = \
Task("reg_split", self.X_class, self.y_class, "regression", test_size=0.1, random_state=42)
self.classification_task_cv = \
Task("class_cv", self.X_reg, self.y_reg, "classification", cv=5, random_state=42)
self.regression_task_cv = \
Task("reg_cv", self.X_reg, self.y_reg, "regression", cv=5, random_state=42)
def set_gst_grapviz_tracing(enabled=True):
if enabled:
os.environ[
"GST_DEBUG_DUMP_DOT_DIR"] = "/home/pi/dev/bossjones-github/scarlett_os/_debug" # noqa
os.putenv('GST_DEBUG_DUMP_DIR_DIR',
'/home/pi/dev/bossjones-github/scarlett_os/_debug')
else:
if os.environ.get('GST_DEBUG_DUMP_DOT_DIR'):
del os.environ['GST_DEBUG_DUMP_DOT_DIR']
# source: http://pyrasite.readthedocs.io/en/latest/Payloads.html
# def create_call_graph():
# import pycallgraph
# pycallgraph.start_trace()
# pycallgraph.make_dot_graph('callgraph.png')
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def proxy_command(command, command_args, credentials):
# Unset variables for sanity sake
os.unsetenv('AWS_DEFAULT_PROFILE')
os.unsetenv('AWS_PROFILE')
os.unsetenv('AWS_ACCESS_KEY_ID')
os.unsetenv('AWS_SECRET_ACCESS_KEY')
os.unsetenv('AWS_SESSION_TOKEN')
os.unsetenv('AWS_SECURITY_TOKEN')
# Set AWS/Boto environemnt variables before executing target command
os.putenv('AWS_ACCESS_KEY_ID', (credentials['AccessKeyId']))
os.putenv('AWS_SECRET_ACCESS_KEY', (credentials['SecretAccessKey']))
os.putenv('AWS_SESSION_TOKEN', (credentials['SessionToken']))
os.putenv('AWS_SECURITY_TOKEN', (credentials['SessionToken']))
command_status = os.system(command + " " + " ".join(command_args))
exit(os.WEXITSTATUS(command_status))
def get_session(profile_config):
session_profile = profile_config['profile_name']
if 'source_profile' in profile_config:
session_profile = profile_config['source_profile']
if 'region' in profile_config:
os.putenv('AWS_DEFAULT_REGION', profile_config['region'])
os.putenv('AWS_REGION', profile_config['region'])
# Create a session using profile or EC2 Instance Role
# To use Instance Role set `source_profile` to empty string in aws profile
# configuration file
session = boto3.Session(profile_name=session_profile)
return session
def __init__(self, query, target_id, database, tk_root, tk_config, pseudo=True, ss=True, cpu=1):
self.tk_root = tk_root
self.tk_config = tk_config
self.hhlib = os.path.join(tk_root, "bioprogs", "hhsuite")
if 'TK_ROOT' not in os.environ or not os.environ['TK_ROOT']:
os.putenv('TK_ROOT', self.tk_root)
if 'HHLIB' not in os.environ or not os.environ['HHLIB']:
os.putenv('HHLIB', self.hhlib)
os.environ["PATH"] += os.pathsep + os.path.join(self.hhlib, "bin")
self.query = query
self.accession = target_id[:-1]
self.chain = target_id[-1]
self.database = database
self.pseudo = bool(pseudo)
self.ss = bool(ss)
self.cpu = cpu
self._input = None
self._a3m = None
self._hhm = None
self.configure_input()
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
# Last character is stripped in C-loader. We have to add
# '/' or '\\' at the end.
os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def setProcessEnvironment(process):
envvar_list = {
"PATH" : getGdalBinPath(),
"PYTHONPATH" : getGdalPymodPath(),
"GDAL_FILENAME_IS_UTF8" : "NO"
}
sep = os.pathsep
for name, val in envvar_list.iteritems():
if val == None or val == "":
continue
envval = os.getenv(name)
if envval == None or envval == "":
envval = str(val)
elif (platform.system() == "Windows" and val.lower() not in envval.lower().split( sep )) or \
(platform.system() != "Windows" and val not in envval.split( sep )):
envval += "%s%s" % (sep, str(val))
else:
envval = None
if envval != None:
os.putenv( name, envval )
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def cli(config: str, command):
"""Command line entry point"""
main_config = get_main_config(config)
set_env_values_from_conf(main_config)
project_name = main_config.get('project_name')
os.putenv('COMPOSE_PROJECT_NAME', project_name)
# What to load
compose_file = package_utils.get_file('static', 'docker-compose.yml')
activated_services = get_enabled_services(main_config.get('services'))
# Create the command
services = []
for service in activated_services:
services.append('-f')
services.append(service)
base_cmd = ['docker-compose', '-f', compose_file] + services + ['-p', project_name]
msg = click.style('[VERBOSE] ', fg='green')
msg += 'Compose command: ' + ' '.join(base_cmd + list(command))
click.echo(msg, err=True)
subprocess.call(base_cmd + list(command))
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
enhance_goodreads_export_gui.py 文件源码
项目:Enhance-GoodReads-Export
作者: PaulKlinger
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
pyi_multiprocess_forking.py 文件源码
项目:mac-package-build
作者: persepolisdm
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
# Last character is stripped in C-loader. We have to add
# '/' or '\\' at the end.
os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __get_driver(self):
has_driver = False
for driver in self._drivers:
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
print('Driver: {} not loaded.'.format(driver))
continue
print('Driver: {} used.'.format(driver))
has_driver = True
break
if not has_driver:
raise AssertionError('No video driver available for use!')
def _setup_video():
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ['x11', 'fbcon', 'directfb', 'svgalib', 'Quartz']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
logger.error('Driver: {0} failed.'.format(driver))
continue
found = True
break
if not found:
logger.error('No suitable SDL video driver found to start the event subsystem, pygame joysticks may not work.')
def set(self):
os.putenv("LD_LIBRARY_PATH", self.ld_lib_path)
os.putenv("PYTHONPATH", self.pythonpath)
os.putenv("CLASSPATH", self.classpath)
os.putenv("OCTAVE_PATH", self.octave_path)
os.environ["LD_LIBRARY_PATH"] = self.ld_lib_path
os.environ["PYTHONPATH"] = self.pythonpath
os.environ["CLASSPATH"] = self.classpath
os.environ["OCTAVE_PATH"] = self.octave_path
def __exit__(self,exc_type,exc_value,traceback):
os.putenv("LD_LIBRARY_PATH", self.ld_lib_path)
os.putenv("PYTHONPATH", self.pythonpath)
os.putenv("CLASSPATH", self.classpath)
os.putenv("OCTAVE_PATH", self.octave_path)
os.environ["LD_LIBRARY_PATH"] = self.ld_lib_path
os.environ["PYTHONPATH"] = self.pythonpath
os.environ["CLASSPATH"] = self.classpath
os.environ["OCTAVE_PATH"] = self.octave_path
def putenv(key, value):
"""Like `os.putenv` but takes unicode under Windows + Python 2
Args:
key (pathlike): The env var to get
value (pathlike): The value to set
Raises:
ValueError
"""
key = path2fsn(key)
value = path2fsn(value)
if is_win and PY2:
try:
set_windows_env_var(key, value)
except WindowsError:
# py3 + win fails here
raise ValueError
else:
try:
os.putenv(key, value)
except OSError:
# win + py3 raise here for invalid keys which is probably a bug.
# ValueError seems better
raise ValueError
def init_display():
"""
set up the pygame display, full screen
"""
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ['fbcon', 'directfb', 'svgalib', 'directx', 'windib']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
# logging.warn('Driver: %s failed.' % driver)
continue
found = True
logging.debug('using %s driver', driver)
break
if not found:
raise Exception('No suitable video driver found!')
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
pygame.mouse.set_visible(0)
if driver != 'directx': # debugging hack runs in a window on Windows
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
else:
logging.info('running in windowed mode')
# set window origin for windowed usage
os.putenv('SDL_VIDEO_WINDOW_POS', '0,0')
# size = (size[0]-10, size[1] - 30)
screen = pygame.display.set_mode(size, pygame.NOFRAME)
logging.debug('display size: %d x %d', size[0], size[1])
# Clear the screen to start
screen.fill(BLACK)
return screen, size