Python os.putenv() Examples
The following are 30
code examples of os.putenv().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: env_process.py From avocado-vt with GNU General Public License v2.0 | 7 votes |
def process_command(test, params, env, command, command_timeout, command_noncritical): """ Pre- or post- custom commands to be executed before/after a test is run :param test: An Autotest test object. :param params: A dict containing all VM and image parameters. :param env: The environment (a dict-like object). :param command: Command to be run. :param command_timeout: Timeout for command execution. :param command_noncritical: If True test will not fail if command fails. """ # Export environment vars for k in params: os.putenv("KVM_TEST_%s" % k, str(params[k])) # Execute commands try: a_process.system( "cd %s; %s" % (test.bindir, command), shell=True) except a_process.CmdError as e: if command_noncritical: logging.warn(e) else: raise
Example #2
Source File: sign-tag.py From git-repo with Apache License 2.0 | 6 votes |
def sign(opts): """Tag the commit & sign it!""" # We use ! at the end of the key so that gpg uses this specific key. # Otherwise it uses the key as a lookup into the overall key and uses the # default signing key. i.e. It will see that KEYID_RSA is a subkey of # another key, and use the primary key to sign instead of the subkey. cmd = ['git', 'tag', '-s', opts.tag, '-u', f'{opts.key}!', '-m', f'repo {opts.tag}', opts.commit] key = 'GNUPGHOME' print('+', f'export {key}="{opts.gpgdir}"') oldvalue = os.getenv(key) os.putenv(key, opts.gpgdir) util.run(opts, cmd) if oldvalue is None: os.unsetenv(key) else: os.putenv(key, oldvalue)
Example #3
Source File: deploy.py From dockerbuilder with MIT License | 6 votes |
def download_file(tar_path): os.putenv('BUCKET_FILE', "/var/run/secrets/deis/objectstore/creds/builder-bucket") if os.getenv('BUILDER_STORAGE') == "minio": os.makedirs("/tmp/objectstore/minio") bucketFile = open('/tmp/objectstore/minio/builder-bucket', 'w') bucketFile.write('git') bucketFile.close() os.putenv('BUCKET_FILE', "/tmp/objectstore/minio/builder-bucket") elif os.getenv('BUILDER_STORAGE') in ["azure", "swift"]: os.putenv('CONTAINER_FILE', "/var/run/secrets/deis/objectstore/creds/builder-container") command = [ "objstorage", "--storage-type="+os.getenv('BUILDER_STORAGE'), "download", tar_path, "apptar" ] subprocess.check_call(command)
Example #4
Source File: minimize_bindiff.py From nightmare with GNU General Public License v2.0 | 6 votes |
def execute_command(self, cmd, timeout): ret = None if self.debugging_interface is None: cmd_obj = TimeoutCommand(cmd) ret = cmd_obj.run(timeout=self.timeout) if cmd_obj.stderr is not None: print cmd_obj.stderr else: self.iface.timeout = self.timeout if not has_pykd or self.iface != pykd_iface: if self.iface == asan_iface: crash = self.iface.main(asan_symbolizer_path=self.asan_symbolizer_path, args=cmd) else: crash = self.iface.main(cmd) else: # Avoid network timeouts and unnecessary delays when using pykd os.putenv("_NT_SYMBOL_PATH", "") crash = pykd_iface.main([cmd], timeout, mode=self.mode, windbg_path=self.windbg_path, exploitable_path=self.exploitable_path) if crash is not None: self.last_crash = crash ret = 0xC0000005 # Access violation in Windows return ret
Example #5
Source File: _environ.py From bugatsinho.github.io with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: utils.py From flashre with GNU Lesser General Public License v3.0 | 6 votes |
def get_r2pipe(filename, offset, options=None): """ Get a r2pipe handle ready to analyse a flashair binary. """ # Set the miasm architecture os.putenv("R2M2_ARCH", "mepl") # Use the r2m2 architecture default_options = ["-a", "r2m2"] # Map the binary at a given location default_options += ["-m", hex(offset)] # Decrease r2 verbosity default_options += ["-e", "bin.verbose=false"] # Add user specified options if isinstance(options, list): default_options += options return r2pipe.open(filename, default_options)
Example #7
Source File: patator_ext.py From project-black with GNU General Public License v2.0 | 6 votes |
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.
Example #8
Source File: apps.py From cua-arbiter with GNU General Public License v2.0 | 6 votes |
def ready(self): case_base_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "arbiter-cases") case_path = os.getenv("CASEPATH") case_base_path = os.path.join(case_base_path, case_path.split('/')[0]) case_base_path = case_base_path.replace("\\", "/") os.environ["PYTHONPATH"] = case_base_path os.putenv("PYTHONPATH", case_base_path) from arbiter.models import Git_Info from arbiter.core.models import CaseList from arbiter.models import Case_List try: if Git_Info.objects.count() > 0: git_info = Git_Info.objects.all().first() os.environ['GIT_USERNAME'] = git_info.user_name os.environ['GIT_PASSWORD'] = git_info.password case_list = Case_List.objects.get() case_list.name = "arbiter_cases" case_list.data = CaseList.getList() case_list.save() except: pass os.environ['GIT_ASKPASS'] = os.path.join( os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'core'), 'util'), 'askpass.py')
Example #9
Source File: patator.py From patator with GNU General Public License v2.0 | 6 votes |
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.
Example #10
Source File: tpm1.py From keylime with BSD 2-Clause "Simplified" License | 6 votes |
def __checkdeepquote_c(self, hAIK, vAIK, deepquoteFile, nonce): os.putenv('TPM_SERVER_PORT', '9999') os.putenv('TPM_SERVER_NAME', '9999') os.putenv('PATH', os.getenv('PATH') + ':/usr/local/bin') if common.STUB_TPM and common.TPM_CANNED_VALUES is not None: yamlIn = common.TPM_CANNED_VALUES if 'deepquote' in yamlIn: # YAML unicode-ifies strings, and C calls require byte strings (str) if 'nonce' in yamlIn['deepquote']: nonce = str(yamlIn['deepquote']['nonce']) else: raise Exception("Could not get deepquote from canned YAML!") cmd = 'checkdeepquote -aik {0} -deepquote {1} -nonce {2} -vaik {3}'.format(hAIK, deepquoteFile, nonce, vAIK) #logger.info('Running cmd %r', cmd) retDict = self.__run(cmd,lock=False) return retDict['retout']
Example #11
Source File: tpm1.py From keylime with BSD 2-Clause "Simplified" License | 6 votes |
def __check_quote_c(self, aikFile, quoteFile, extData): os.putenv('TPM_SERVER_PORT', '9999') os.putenv('TPM_SERVER_NAME', '9999') os.putenv('PATH', os.getenv('PATH') + ':/usr/local/bin') if common.STUB_TPM and common.TPM_CANNED_VALUES is not None: yamlIn = common.TPM_CANNED_VALUES if 'tpmquote' in yamlIn and 'nonce' in yamlIn['tpmquote']: # YAML unicode-ifies strings, and C calls require byte strings (str) extData = str(yamlIn['tpmquote']['nonce']) else: raise Exception("Could not get quote nonce from canned YAML!") #print('Executing "%s"' % ("checkquote -aik %s -quote %s -nonce %s"%(aikFile, quoteFile, extData),)) if common.USE_CLIME: import _cLime retout = _cLime.checkquote('-aik', aikFile, '-quote', quoteFile, '-nonce', extData) retout = [line + '\n' for line in retout.split('\n')] # Try and be transparent to tpm_quote.py return retout else: retDict = self.__run("checkquote -aik %s -quote %s -nonce %s"%(aikFile, quoteFile, extData),lock=False) return retDict['retout']
Example #12
Source File: utils.py From Commander with MIT License | 6 votes |
def add_environment_variables(params, endpoint, record, temp_files, non_shared): # type: (KeeperParams, str, Record, [str], dict) -> [str] rs = [] # type: [str] key_prefix = 'connect:{0}:env:'.format(endpoint) for cf in record.custom_fields: cf_name = cf['name'] # type: str if cf_name.startswith(key_prefix): key_name = cf_name[len(key_prefix):] if not key_name: continue cf_value = cf['value'] # type: str while True: m = endpoint_parameter_pattern.search(cf_value) if not m: break p = m.group(1) val = ConnectCommand.get_parameter_value(params, record, p, temp_files, non_shared) if not val: raise Exception('Add environment variable. Failed to resolve key parameter: {0}'.format(p)) cf_value = cf_value[:m.start()] + val + cf_value[m.end():] if cf_value: rs.append(key_name) os.putenv(key_name, cf_value) return rs
Example #13
Source File: mem.py From Fastir_Collector with GNU General Public License v3.0 | 6 votes |
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', '')
Example #14
Source File: EventMonkey.py From EventMonkey with Apache License 2.0 | 6 votes |
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.
Example #15
Source File: __init__.py From singularity-cli with Mozilla Public License 2.0 | 6 votes |
def set_verbosity(args): """determine the message level in the environment to set based on args. """ level = "INFO" if args.debug: level = "DEBUG" elif args.quiet: level = "QUIET" os.environ["MESSAGELEVEL"] = level os.putenv("MESSAGELEVEL", level) os.environ["SINGULARITY_MESSAGELEVEL"] = level os.putenv("SINGULARITY_MESSAGELEVEL", level) # Import logger to set from spython.logger import bot bot.debug("Logging level %s" % level) import spython bot.debug("Singularity Python Version: %s" % spython.__version__)
Example #16
Source File: pygame_learning_environment.py From tensorforce with Apache License 2.0 | 6 votes |
def __init__(self, level, visualize=False, frame_skip=1, fps=30): super().__init__() import ple if isinstance(level, str): assert level in PyGameLearningEnvironment.levels() level = getattr(ple.games, level)() if not visualize: os.putenv('SDL_VIDEODRIVER', 'fbcon') os.environ['SDL_VIDEODRIVER'] = 'dummy' self.environment = ple.PLE( game=level, fps=fps, frame_skip=frame_skip, display_screen=visualize # num_steps=1, reward_values={}, force_fps=True, add_noop_action=True, NOOP=K_F15, # state_preprocessor=None, rng=24 ) self.environment.init() self.has_game_state = self.environment.getGameStateDims() is not None self.available_actions = tuple(self.environment.getActionSet())
Example #17
Source File: test_process.py From vanilla with MIT License | 6 votes |
def test_env(self): h = vanilla.Hub() VAR1 = 'VANILLA_%s_VAR1' % os.getpid() VAR2 = 'VANILLA_%s_VAR2' % os.getpid() os.putenv(VAR1, 'VAR1') child = h.process.execv( ['/usr/bin/env', 'sh', '-c', 'echo $%s $%s' % (VAR1, VAR2)]) assert child.stdout.recv() == 'VAR1\n' child = h.process.execv( ['/usr/bin/env', 'sh', '-c', 'echo $%s $%s' % (VAR1, VAR2)], env={VAR2: 'VAR2'}) assert child.stdout.recv() == 'VAR2\n'
Example #18
Source File: analysis_utils.py From memory-analyzer with MIT License | 6 votes |
def __init__(self, pid, current_path, executable, template_out_path): """ Args: pid: numeric pid of the target current_path: the directory containing gdb_commands.py executable: the binary passed as the first arg to gdb template_out_path: the location that analysis.py rendered templates end up in. """ self.pid = pid self.fifo = f"/tmp/memanz_pipe_{self.pid}" self.current_path = current_path # These should all be the same, so safe for threads. os.putenv("MEMORY_ANALYZER_TEMPLATES_PATH", template_out_path) self.executable = executable
Example #19
Source File: dump.py From pgantomizer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def dump_db(dump_path, schema_path, password='', *db_args): schema = yaml.load(open(schema_path)) password = password or os.environ.get('DB_DEFAULT_PASS', '') os.putenv('PGPASSWORD', password) cmd = 'PGPASSWORD={password} pg_dump -Fc -Z 9 {args} {tables} -f {filename}'.format( password=password, args='-d {} -U {} -h {} -p {} '.format( *(db_args or [os.environ.get(var) for var in ['DB_DEFAULT_NAME', 'DB_DEFAULT_USER', 'DB_DEFAULT_SERVICE', 'DB_DEFAULT_PORT']])), tables=' '.join('-t {}'.format(table) for table in schema), filename=dump_path ) logging.debug('Dumping DB with following command: {}'.format(cmd)) subprocess.run(cmd, shell=True)
Example #20
Source File: shell.py From RSqueak with BSD 3-Clause "New" or "Revised" License | 5 votes |
def terminal(): module_path = os.path.abspath(os.path.dirname(__file__)) if module_path in sys.path: paths = sys.path[:sys.path.index(module_path)] else: paths = sys.path os.putenv("PYTHONPATH", os.pathsep.join(paths)) os.system(os.environ.get("COMSPEC") or os.environ.get("SHELL") or "/bin/sh")
Example #21
Source File: test_javashell.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testPutEnv( self ): "Put an environment variable and ensure that spawned processes see the change" value = "Value we set" os.putenv( "NEWVARIABLE", value ) newValue = os.popen( "echo $NEWVARIABLE" ).read().strip() if newValue == "$NEWVARIABLE": newValue = os.popen( "echo %NEWVARIABLE%" ).read().strip() if newValue == "%NEWVARIABLE%": raise test_support.TestSkipped( "Unable to find a subshell to execute echo" ) assert newValue == value, ( "Expected (%s) to equal value we set (%s)" % ( newValue, value ))
Example #22
Source File: integration_test.py From pyannotate with Apache License 2.0 | 5 votes |
def setUp(self): self.savedir = os.getcwd() os.putenv('PYTHONPATH', self.savedir) self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir)
Example #23
Source File: __init__.py From efs-utils with MIT License | 5 votes |
def find_command_path(command, install_method): try: env_path = '/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin' os.putenv('PATH', env_path) path = subprocess.check_output(['which', command]) except subprocess.CalledProcessError as e: fatal_error('Failed to locate %s in %s - %s' % (command, env_path, install_method), e) return path.strip().decode()
Example #24
Source File: test_subprocess.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_preexec(self): # preexec function p = subprocess.Popen([sys.executable, "-c", "import sys, os;" "sys.stdout.write(os.getenv('FRUIT'))"], stdout=subprocess.PIPE, preexec_fn=lambda: os.putenv("FRUIT", "apple")) self.addCleanup(p.stdout.close) self.assertEqual(p.stdout.read(), "apple")
Example #25
Source File: tfutil.py From multisensory with Apache License 2.0 | 5 votes |
def set_gpus(gpus): if gpus is None or gpus == [None]: os.putenv('CUDA_VISIBLE_DEVICES', '') return ['/cpu:0'] else: if np.ndim(gpus) == 0: gpus = [gpus] os.putenv('CUDA_VISIBLE_DEVICES', ','.join(map(str, gpus))) gpus = range(len(gpus)) return gpu_strs(gpus)
Example #26
Source File: anonymize.py From pgantomizer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_db_to_new_instance(filename, db_args): if not os.path.isfile(filename): raise IOError('Dump file {} is not a file.'.format(filename)) os.putenv('PGPASSWORD', db_args.get('password')) drop_schema(db_args) subprocess.run( 'PGPASSWORD={password} pg_restore -Fc -j 8 {db_args} {filename} {redirect}'.format( password=db_args.get('password'), db_args=get_psql_db_args(db_args), filename=filename, redirect='' if logging.getLogger().getEffectiveLevel() == logging.DEBUG else '>/dev/null 2>&1'), shell=True )
Example #27
Source File: tools.py From browbeat with Apache License 2.0 | 5 votes |
def gather_metadata(self): os.putenv("ANSIBLE_SSH_ARGS", " -F {}".format(self.config['ansible']['ssh_config'])) ansible_cmd = \ 'ansible-playbook -i {} {}' \ .format(self.config['ansible']['hosts'], self.config['ansible']['metadata_playbook']) self.run_cmd(ansible_cmd) if not self.check_metadata(): self.logger.warning("Metadata could not be gathered") return False else: self.logger.info("Metadata about cloud has been gathered") return True
Example #28
Source File: tfutil.py From multisensory with Apache License 2.0 | 5 votes |
def get_step(): print 'vars =', [x.name for x in tf.global_variables()] step = ut.find_first(lambda x : x.name.startswith('global_step:'), tf.global_variables()) return step # def set_gpus(gpus): # if gpus is not None: # if np.ndim(gpus) == 0: # gpus = [gpus] # os.putenv('CUDA_VISIBLE_DEVICES', ','.join(map(str, gpus)))
Example #29
Source File: tools.py From browbeat with Apache License 2.0 | 5 votes |
def common_logging(self, browbeat_uuid, logging_status): os.putenv("ANSIBLE_SSH_ARGS", " -F {}".format(self.config['ansible']['ssh_config'])) ansible_cmd = \ 'ansible-playbook -i {} {} -e "browbeat_uuid={} logging_status={}"' \ .format(self.config['ansible']['hosts'], self.config['ansible']['logging_playbook'], browbeat_uuid, logging_status) self.run_cmd(ansible_cmd)
Example #30
Source File: dumpdb.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def handle(self, *args, **options): s = settings.DATABASES['default'] db, user, pw = s['NAME'], s['USER'], s['PASSWORD'] fname = datetime.now().strftime('%Y%m%d_%H%M') + '.pgdump' if not os.path.exists(settings.BACKUP_DIR): os.mkdir(settings.BACKUP_DIR) path = os.path.join(settings.BACKUP_DIR, fname) os.putenv('PGPASSWORD', pw) subprocess.call(['pg_dump', '-Fc', db, '-U', user, '-f', path])