當前位置: 首頁>>代碼示例>>Python>>正文


Python os.putenv方法代碼示例

本文整理匯總了Python中os.putenv方法的典型用法代碼示例。如果您正苦於以下問題:Python os.putenv方法的具體用法?Python os.putenv怎麽用?Python os.putenv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.putenv方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_r2pipe

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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) 
開發者ID:guedou,項目名稱:flashre,代碼行數:24,代碼來源:utils.py

示例2: __setitem__

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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 
開發者ID:bugatsinho,項目名稱:bugatsinho.github.io,代碼行數:22,代碼來源:_environ.py

示例3: process_command

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:27,代碼來源:env_process.py

示例4: execute_command

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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 
開發者ID:joxeankoret,項目名稱:nightmare,代碼行數:26,代碼來源:minimize_bindiff.py

示例5: __init__

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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. 
開發者ID:lanjelot,項目名稱:patator,代碼行數:21,代碼來源:patator.py

示例6: __checkdeepquote_c

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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'] 
開發者ID:keylime,項目名稱:keylime,代碼行數:21,代碼來源:tpm1.py

示例7: __check_quote_c

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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'] 
開發者ID:keylime,項目名稱:keylime,代碼行數:25,代碼來源:tpm1.py

示例8: add_environment_variables

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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 
開發者ID:Keeper-Security,項目名稱:Commander,代碼行數:26,代碼來源:utils.py

示例9: __init__

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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. 
開發者ID:devgc,項目名稱:EventMonkey,代碼行數:21,代碼來源:EventMonkey.py

示例10: set_verbosity

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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__) 
開發者ID:singularityhub,項目名稱:singularity-cli,代碼行數:24,代碼來源:__init__.py

示例11: __init__

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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()) 
開發者ID:tensorforce,項目名稱:tensorforce,代碼行數:24,代碼來源:pygame_learning_environment.py

示例12: test_env

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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' 
開發者ID:cablehead,項目名稱:vanilla,代碼行數:18,代碼來源:test_process.py

示例13: __init__

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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 
開發者ID:facebookincubator,項目名稱:memory-analyzer,代碼行數:18,代碼來源:analysis_utils.py

示例14: sign

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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) 
開發者ID:GerritCodeReview,項目名稱:git-repo,代碼行數:20,代碼來源:sign-tag.py

示例15: __init__

# 需要導入模塊: import os [as 別名]
# 或者: from os import putenv [as 別名]
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', '') 
開發者ID:SekoiaLab,項目名稱:Fastir_Collector,代碼行數:21,代碼來源:mem.py


注:本文中的os.putenv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。