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


Python environ.copy方法代碼示例

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


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

示例1: disconnect_telepresence

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def disconnect_telepresence(namespace):
    # Kill off sshd server process the SSH client is talking to, forcing
    # disconnection:
    env = environ.copy()
    # Don't want torsocks messing with kubectl:
    for name in ["LD_PRELOAD", "DYLD_INSERT_LIBRARIES"]:
        if name in env:
            del env[name]
    # We can't tell if this succeeded, sadly, since it kills ssh session used
    # by kubectl exec!
    command = [
        "kubectl", "exec", "--namespace=" + namespace,
        "--container=" + environ["TELEPRESENCE_CONTAINER"],
        environ["TELEPRESENCE_POD"], "--", "/bin/sh", "-c",
        r"kill $(ps xa | tail -n +2 | " + r"sed 's/ *\([0-9][0-9]*\).*/\1/')"
    ]
    print("Using kubectl to kill Telepresence support processes:")
    print("\t{}".format(" ".join(command)), flush=True)

    run(command, env=env)
    sleep(10)
    # The test expects 3, which is how telepresence exits when one of its
    # subprocesses dies. That is, we expect to be killed before we reach this
    # point, if we exit with 66 that means disconnect-detection failed.
    raise SystemExit(66) 
開發者ID:telepresenceio,項目名稱:telepresence,代碼行數:27,代碼來源:probe_endtoend.py

示例2: setup_environment

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def setup_environment():
    """Setup test environment for some functions that are tested
    in this module. In particular this functions stores attributes
    and other things that we need to stub in some test functions.
    This needs to be done on a function level and not module level because
    each testfunction needs a pristine environment.
    """
    global GIVEN_ENV
    GIVEN_ENV['env'] = env.copy() 
開發者ID:ME-ICA,項目名稱:me-ica,代碼行數:11,代碼來源:test_environment.py

示例3: GetCompilerType

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def GetCompilerType(env):
    try:
        sysenv = environ.copy()
        sysenv['PATH'] = str(env['ENV']['PATH'])
        result = exec_command([env.subst("$CC"), "-v"], env=sysenv)
    except OSError:
        return None
    if result['returncode'] != 0:
        return None
    output = "".join([result['out'], result['err']]).lower()
    for type_ in ("clang", "gcc"):
        if type_ in output:
            return type_
    return None 
開發者ID:bq,項目名稱:web2board,代碼行數:16,代碼來源:piomisc.py

示例4: _set_build_env

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def _set_build_env(build_base_path: Optional[Path]) -> Dict[str, str]:
    build_environ = environ.copy()

    if not build_base_path or not build_base_path.exists():
        if build_base_path:
            LOG.error(
                f"Configured local build env path {build_base_path} does not exist"
            )
        return build_environ

    if build_base_path.exists():
        build_env_vars = [
            (
                ("PATH", build_base_path / "Scripts")
                if WINDOWS
                else ("PATH", build_base_path / "sbin")
            ),
            ("C_INCLUDE_PATH", build_base_path / "include"),
            ("CPLUS_INCLUDE_PATH", build_base_path / "include"),
        ]
        if not WINDOWS:
            build_env_vars.append(("PATH", build_base_path / "bin"))

        for var_name, value in build_env_vars:
            if var_name in build_environ:
                build_environ[var_name] = f"{value}:{build_environ[var_name]}"
            else:
                build_environ[var_name] = str(value)
    else:
        LOG.error(
            "{} does not exist. Not add int PATH + INCLUDE Env variables".format(
                build_base_path
            )
        )

    return build_environ 
開發者ID:facebookincubator,項目名稱:ptr,代碼行數:38,代碼來源:ptr.py

示例5: raster2pgsql

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def raster2pgsql():
    """
    Imports SRTM v4.1 tiles to PostGIS.
    
    :raises subprocess.CalledProcessError: Raised when raster2pgsql throws an error.
    """
    
    pg_settings = SETTINGS['provider_parameters']
    
    # Copy all env variables and add PGPASSWORD
    env_current = environ.copy()
    env_current['PGPASSWORD'] = pg_settings['password']
    
    # Tried to import every raster individually by user-specified xyrange 
    # similar to download(), but raster2pgsql fuck it up somehow.. The PostGIS
    # raster will not be what one would expect. Instead doing a bulk import of all files.
    cmd_raster2pgsql = r"raster2pgsql -s 4326 -a -C -M -P -t 50x50 {filename} {table_name} | psql -q -h {host} -p {port} -U {user_name} -d {db_name}"
    # -s: raster SRID
    # -a: append to table (assumes it's been create with 'create()')
    # -C: apply all raster Constraints
    # -P: pad tiles to guarantee all tiles have the same width and height
    # -M: vacuum analyze after import
    # -t: specifies the pixel size of each row. Important to keep low for performance!
    
    cmd_raster2pgsql = cmd_raster2pgsql.format(**{'filename': path.join(TILES_DIR, '*.tif'),
                                                  **pg_settings})
    
    proc = subprocess.Popen(cmd_raster2pgsql,
                         stdout=subprocess.PIPE, 
                         stderr=subprocess.STDOUT,
                         shell=True,
                         env=env_current
                         )
    
#    for line in proc.stdout:
#        log.debug(line.decode())
#    proc.stdout.close()
    return_code = proc.wait()
    if return_code:
        raise subprocess.CalledProcessError(return_code, cmd_raster2pgsql) 
開發者ID:GIScience,項目名稱:openelevationservice,代碼行數:42,代碼來源:filestreams.py

示例6: without_jira_vars

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def without_jira_vars():
    backup = environ.copy()
    del environ['JIRA_PROJECT']
    del environ['JIRA_USER']
    del environ['JIRA_PASSWORD']
    del environ['JIRA_URL']
    reload(jira)
    yield
    environ.update(backup)
    reload(jira) 
開發者ID:snowflakedb,項目名稱:SnowAlert,代碼行數:12,代碼來源:SP1099_missing_jira_env_vars.py

示例7: call_exit_errors

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def call_exit_errors(command):
    print("+ {}".format(" ".join(command)))
    rc = call(command, env=environ.copy())
    if rc > 0:
       exit(rc) 
開發者ID:mozilla,項目名稱:telemetry-airflow,代碼行數:7,代碼來源:telemetry_batch_view.py

示例8: __init__

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def __init__(self):
        makedirs(DAGS_FOLDER, mode=0o0775, exist_ok=True)
        extend_env = {"AIRFLOW__CORE__LOGGING_LEVEL": "ERROR"}
        self.env = environ.copy()
        self.env.update(extend_env) 
開發者ID:Barski-lab,項目名稱:cwl-airflow,代碼行數:7,代碼來源:backend.py

示例9: execute_reproducer

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def execute_reproducer(self, cgroup, inputfile, functionname):
        menv = environ.copy()
        menv["ASAN_OPTIONS"] = "detect_leaks=0"
        infd = open(inputfile, "r")
        (returncode, stdoutdata, stderrdata) = cgroups_run_timed_subprocess(
            [self.reproducer, "--fuzz-driver=" + functionname], cgroup=cgroup, stdin=infd, env=menv)
        ret = AsanResult(stderrdata, inputfile, functionname)
        infd.close()
        return ret

    # Function to check for saturation of AFL 
開發者ID:tum-i22,項目名稱:macke,代碼行數:13,代碼來源:Fuzzer.py

示例10: execute_afl_tmin

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def execute_afl_tmin(self, cgroup, inputfile, outputfile, functionname):
        asan_env = environ.copy()
        asan_env["AFL_USE_ASAN"] = "1"
        return cgroups_run_checked_silent_subprocess([AFLTMIN, "-e", "-t", "50", "-i", inputfile, "-o", outputfile, "-m", "none", "--", self.minimizer, "--fuzz-driver=" + functionname], cgroup, env=asan_env) 
開發者ID:tum-i22,項目名稱:macke,代碼行數:6,代碼來源:Fuzzer.py

示例11: build_notebook

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def build_notebook(nb_file, no_embed=False, tag=""):
    env = environ.copy()  # Pass argument to exporter via environment
    yaml_path = mktemp('.yaml')
    py_path = ''
    code = ''
    if no_embed:
        py_path = mktemp('.py')
        env[env_keys.code_target_path] = py_path
    env[env_keys.drop_nb_outputs] = 'y'

    cmd = [
        executable, '-m', 'nbconvert',
        '--to', 'nuclio.export.NuclioExporter',
        '--output', yaml_path,
        nb_file,
    ]
    out = run(cmd, env=env, stdout=PIPE, stderr=PIPE)
    if out.returncode != 0:
        print(out.stdout.decode('utf-8'))
        print(out.stderr.decode('utf-8'), file=stderr)
        raise BuildError('cannot convert notebook')

    if not path.isfile(yaml_path):
        raise BuildError('failed to convert, tmp file %s not found', yaml_path)

    with open(yaml_path) as yp:
        config_data = yp.read()
    config = yaml.safe_load(config_data)
    os.remove(yaml_path)

    if py_path:
        with open(py_path) as pp:
            code = pp.read()
        os.remove(py_path)

    return config, code 
開發者ID:nuclio,項目名稱:nuclio-jupyter,代碼行數:38,代碼來源:build.py

示例12: pipe_output

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def pipe_output(read, write):
    from os import environ
    environ = environ.copy()

    from subprocess import Popen
    vupdate = Popen(
        ('venv-update', 'venv=', '--version'),
        env=environ,
        stdout=write,
        close_fds=True,
    )

    from os import close
    from testing.capture_subprocess import read_all
    close(write)
    result = read_all(read)
    vupdate.wait()

    result = result.decode('US-ASCII')
    print(result)
    uncolored = uncolor(result)
    assert uncolored.startswith('> ')
    # FIXME: Sometimes this is 'python -m', sometimes 'python2.7 -m'. Weird.
    import virtualenv
    assert uncolored.endswith('''
> virtualenv --version
%s
''' % virtualenv.__version__)

    return result, uncolored 
開發者ID:Yelp,項目名稱:venv-update,代碼行數:32,代碼來源:simple_test.py

示例13: run

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def run(*cmd, **env):
    if env:
        from os import environ
        tmp = env
        env = environ.copy()
        env.update(tmp)
    else:
        env = None

    from .capture_subprocess import capture_subprocess
    from venv_update import info, colorize
    info('\nTEST> ' + colorize(cmd))
    out, err = capture_subprocess(cmd, env=env)
    err = strip_coverage_warnings(err)
    return out, err 
開發者ID:Yelp,項目名稱:venv-update,代碼行數:17,代碼來源:__init__.py

示例14: patch_and_capture_env_for_download_all_image_descriptions

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def patch_and_capture_env_for_download_all_image_descriptions(testcase):
    class CaptureEnv:
        """Fake function; records a copy of the environment."""

        def __call__(self, *args, **kwargs):
            self.args = args
            self.env = environ.copy()
            return MagicMock()

    capture = testcase.patch(
        bootsources, "download_all_image_descriptions", CaptureEnv()
    )
    return capture 
開發者ID:maas,項目名稱:maas,代碼行數:15,代碼來源:test_bootsources.py

示例15: patch_and_capture_env_for_download_all_boot_resources

# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import copy [as 別名]
def patch_and_capture_env_for_download_all_boot_resources(self):
        class CaptureEnv:
            """Fake function; records a copy of the environment."""

            def __call__(self, *args, **kwargs):
                self.args = args
                self.env = environ.copy()

        capture = self.patch(
            bootresources, "download_all_boot_resources", CaptureEnv()
        )
        return capture 
開發者ID:maas,項目名稱:maas,代碼行數:14,代碼來源:test_bootresources.py


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