当前位置: 首页>>代码示例>>Python>>正文


Python os.env方法代码示例

本文整理汇总了Python中os.env方法的典型用法代码示例。如果您正苦于以下问题:Python os.env方法的具体用法?Python os.env怎么用?Python os.env使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.env方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_terminal_size

# 需要导入模块: import os [as 别名]
# 或者: from os import env [as 别名]
def get_terminal_size():
        def ioctl_GWINSZ(fd):
            try:
                import fcntl
                import termios
                import struct
                cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
                                                     '1234'))
            except:
                return None
            return cr
        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
        if not cr:
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass
        if not cr:
            try:
                cr = (os.env['LINES'], os.env['COLUMNS'])
            except:
                cr = (25, 80)
        return int(cr[1]), int(cr[0]) 
开发者ID:rakanalh,项目名称:pocket-cli,代码行数:27,代码来源:utils.py

示例2: call_graphviz

# 需要导入模块: import os [as 别名]
# 或者: from os import env [as 别名]
def call_graphviz(program, arguments, working_dir, **kwargs):
    # explicitly inherit `$PATH`, on Windows too,
    # with `shell=False`

    if program in DEFAULT_PROGRAMS:
        extension = get_executable_extension()
        program += extension

    if arguments is None:
        arguments = []

    env = {
        'PATH': os.environ.get('PATH', ''),
        'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''),
    }

    program_with_args = [program, ] + arguments

    process = subprocess.Popen(
        program_with_args,
        env=env,
        cwd=working_dir,
        shell=False,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE,
        **kwargs
    )
    stdout_data, stderr_data = process.communicate()

    return stdout_data, stderr_data, process


#
# Extended version of ASPN's Python Cookbook Recipe:
# Frozen dictionaries.
# https://code.activestate.com/recipes/414283/
#
# This version freezes dictionaries used as values within dictionaries.
# 
开发者ID:pydot,项目名称:pydot,代码行数:41,代码来源:pydot.py

示例3: _try_reserve_and_set_resources

# 需要导入模块: import os [as 别名]
# 或者: from os import env [as 别名]
def _try_reserve_and_set_resources(self, num_cpus, num_gpus):
        visible_cuda_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
        reserved_cuda_device = reserve_resources(num_cpus, num_gpus)
        if num_gpus == 0:
            return
        # This needs to be set even if torch.cuda is already
        # initialized because the env var is used later when
        # starting the DDP setup.
        os.environ["CUDA_VISIBLE_DEVICES"] = reserved_cuda_device
        if visible_cuda_devices:
            # We want to set the index on the visible devices list.
            if reserved_cuda_device not in visible_cuda_devices:
                raise RuntimeError(
                    "TorchTrainer reserved a device {} that was not in the "
                    "CUDA_VISIBLE_DEVICES {}. This may be because the "
                    "Ray cluster is not set with the right env vars. "
                    "If that is not the issue, please raise a Github "
                    "issue.".format(reserved_cuda_device,
                                    visible_cuda_devices))
            devices = visible_cuda_devices.split(",")
            scoped_index = devices.index(reserved_cuda_device)
            self._set_cuda_device(str(scoped_index))
        else:
            # Once cuda is initialized, torch.device ignores the os.env
            # so we have to set the right actual device.
            self._set_cuda_device(reserved_cuda_device) 
开发者ID:ray-project,项目名称:ray,代码行数:28,代码来源:distributed_torch_runner.py

示例4: startarp

# 需要导入模块: import os [as 别名]
# 或者: from os import env [as 别名]
def startarp(interface, gateway_ip, target_ip, packet):
    conf.iface = interface
    conf.verb = 0
    print(col.O + "[*] Using {} as interface [*]".format(interface) + col.W)

    # parse gateway's MAC address from ip
    gateway_mac = get_mac(gateway_ip)
    if gateway_mac is None:
        print(col.R + "[!] Failed! Cannot obtain Gateway MAC Address [!]" + col.W)
        sys.exit()
    else:
        print(col.O + "[*] Gateway IP %s is at %s [*]" % (gateway_ip, gateway_mac) + col.W)

    # parse target's MAC address from ip
    target_mac = get_mac(target_ip)
    if target_mac is None:
        print(col.F + "[!] Failed! Cannot obtain Target MAC Address [!]" + col.W)
        sys.exit()
    else:
        print(col.O + "[*] Target IP %s is at %s [*]" % (target_ip, target_mac) + col.W)

    # initialize thread for poisoning
    poison_thread = threading.Thread(target = poison_target, args=(gateway_ip, gateway_mac, \
        target_ip, target_mac))
    poison_thread.start()
    try:
        print(col.O + "[*] Starting sniffer for %s packets [*]" % (packet) + col.W)
        bpf_filter = 'IP host ' + target_ip
        packets = sniff(count=packet, iface=interface)
        wrpcap(f"{os.env['PWD']}/output.pcap", packets)
        restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
    except Scapy_Exception as msg:
        print(col.R + "[!] Error! ARPSpoof failed. Reason: [!]" + msg + col.W)
    except KeyboardInterrupt:
        restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
        sys.exit() 
开发者ID:archival-0x,项目名称:dedsploit,代码行数:38,代码来源:net.py


注:本文中的os.env方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。