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


Python os.O_RDWR属性代码示例

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


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

示例1: daemonize

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def daemonize(logfile = None):
    # Fork once
    if os.fork() != 0:
        os._exit(0)
    # Create new session
    os.setsid()
    if os.fork() != 0:
        os._exit(0)
    os.chdir('/')
    fd = os.open('/dev/null', os.O_RDWR)
    os.dup2(fd, sys.__stdin__.fileno())
    if logfile != None:
        fake_stdout = open(logfile, 'a', 1)
        sys.stdout = fake_stdout
        sys.stderr = fake_stdout
        fd = fake_stdout.fileno()
    os.dup2(fd, sys.__stdout__.fileno())
    os.dup2(fd, sys.__stderr__.fileno())
    if logfile == None:
        os.close(fd) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:22,代码来源:misc.py

示例2: __connect

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def __connect(self):
        device_addr, hidraw_device, event_device = self.__find_device()
        if device_addr is None:
            return False
        self.__report_fd = os.open(hidraw_device, os.O_RDWR | os.O_NONBLOCK)
        self.__fd = FileIO(self.__report_fd, "rb+", closefd=False)
        self.__input_device = InputDevice(event_device)
        self.__input_device.grab()
        buf = bytearray(38)
        buf[0] = 0x02
        try:
            return bool(fcntl.ioctl(self.__fd, 3223734279, bytes(buf)))
        except:
            pass
        if self.recv():
            self.update_controller() 
开发者ID:notkarol,项目名称:derplearning,代码行数:18,代码来源:joystick.py

示例3: freebsd_tun_alloc

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def freebsd_tun_alloc(self, dev, flags):
		try:
			sockfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			ifr = struct.pack('<16si', 'tun', 0)
			self.iface_name = fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCIFCREATE2, ifr)
			self.iface_name = self.iface_name.rstrip("\x00")

			buff = array.array('c', dev+"\x00")
			caddr_t, _ = buff.buffer_info()
			ifr = struct.pack('16sP', self.iface_name, caddr_t);

			fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCSIFNAME, ifr)
			tun = os.open("/dev/"+self.iface_name, os.O_RDWR | os.O_NONBLOCK)
			self.iface_name = dev

		except IOError as e:
			print e
			common.internal_print("Error: Cannot create tunnel. Is {0} in use?".format(dev), -1)
			sys.exit(-1)

		return tun 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:23,代码来源:interface.py

示例4: store_acs_service_principal

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def store_acs_service_principal(subscription_id, client_secret, service_principal,
                                file_name='acsServicePrincipal.json'):
    obj = {}
    if client_secret:
        obj['client_secret'] = client_secret
    if service_principal:
        obj['service_principal'] = service_principal

    config_path = os.path.join(get_config_dir(), file_name)
    full_config = load_service_principals(config_path=config_path)
    if not full_config:
        full_config = {}
    full_config[subscription_id] = obj

    with os.fdopen(os.open(config_path, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600),
                   'w+') as spFile:
        json.dump(full_config, spFile) 
开发者ID:Azure,项目名称:azure-cli-extensions,代码行数:19,代码来源:custom.py

示例5: slave_open

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def slave_open(tty_name):
    """slave_open(tty_name) -> slave_fd
    Open the pty slave and acquire the controlling terminal, returning
    opened filedescriptor.
    Deprecated, use openpty() instead."""

    result = os.open(tty_name, os.O_RDWR)
    try:
        from fcntl import ioctl, I_PUSH
    except ImportError:
        return result
    try:
        ioctl(result, I_PUSH, "ptem")
        ioctl(result, I_PUSH, "ldterm")
    except IOError:
        pass
    return result 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:pty.py

示例6: _open

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def _open(self, in_files):
        """
        Open devices and return array of descriptors

        :param in_files: Files array
        :return: Array of descriptor
        """
        f = []

        for item in in_files:
            path = self.ports[item]["path"]
            if (path in self.files):
                f.append(self.files[path])
            else:
                try:
                    self.files[path] = os.open(path, os.O_RDWR)
                    if (self.ports[item]["is_console"] == "yes"):
                        print(os.system("stty -F %s raw -echo" % (path)))
                        print(os.system("stty -F %s -a" % (path)))
                    f.append(self.files[path])
                except Exception as inst:
                    print("FAIL: Failed to open file %s" % (path))
                    raise inst
        return f 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:26,代码来源:virtio_console_guest.py

示例7: open

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def open(self, in_file, attempts=1):
        """
        Direct open devices.

        :param in_file: Array of files.
        :return: Array of descriptors.
        """
        opened = False
        for i in xrange(attempts):
            try:
                name = self.ports[in_file]["path"]
                self.files[name] = os.open(name, os.O_RDWR)
                if (self.ports[in_file]["is_console"] == "yes"):
                    print(os.system("stty -F %s raw -echo" % (name)))
                opened = True
                break
            except Exception as exc:
                print(str(exc))
                time.sleep(0.1)
        if opened:
            print("PASS: All files opened correctly. (%d)" % i)
        else:
            print("FAIL: Failed open file %s" % name) 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:25,代码来源:virtio_console_guest.py

示例8: DelFromXML

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def DelFromXML(self, fileName, attribute, value):
        Log.Debug('Need to delete element with an attribute named "%s" with a value of "%s" from file named "%s"' % (
            attribute, value, fileName))
        if Platform.OS == 'MacOSX':
            Log.Info('Mac OSx detected')
            try:
                xmlFile = os.fdopen(os.open(fileName, os.O_RDWR), "r+")
                with xmlFile as f:
                    tree = ElementTree.parse(f)
                    root = tree.getroot()
                    mySubtitles = root.findall('.//Subtitle')
                    for Subtitles in root.findall("Language[Subtitle]"):
                        for node in Subtitles.findall("Subtitle"):
                            myValue = node.attrib.get(attribute)
                            if myValue:
                                if '_' in myValue:
                                    drop, myValue = myValue.split("_")
                                if myValue == value:
                                    Subtitles.remove(node)
                    tree.write(f, encoding='utf-8', xml_declaration=True)
            except Exception, e:
                Log.Exception('Exception in DelFromXML was %s' % e) 
开发者ID:ukdtom,项目名称:WebTools.bundle,代码行数:24,代码来源:pmsV3.py

示例9: _open

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def _open(self, devpath):
        # Open i2c device
        try:
            self._fd = os.open(devpath, os.O_RDWR)
        except OSError as e:
            raise I2CError(e.errno, "Opening I2C device: " + e.strerror)

        self._devpath = devpath

        # Query supported functions
        buf = array.array('I', [0])
        try:
            fcntl.ioctl(self._fd, I2C._I2C_IOC_FUNCS, buf, True)
        except (OSError, IOError) as e:
            self.close()
            raise I2CError(e.errno, "Querying supported functions: " + e.strerror)

        # Check that I2C_RDWR ioctl() is supported on this device
        if (buf[0] & I2C._I2C_FUNC_I2C) == 0:
            self.close()
            raise I2CError(None, "I2C not supported on device \"{:s}\"".format(devpath))

    # Methods 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:25,代码来源:i2c.py

示例10: lin_tun_alloc

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def lin_tun_alloc(self, dev, flags):
		try:
			tun = os.open(Interface.LINUX_CLONEDEV, os.O_RDWR|os.O_NONBLOCK, 0)
			ifr = struct.pack('16sH', dev, flags)
			fcntl.ioctl(tun, self.IOCTL_LINUX_TUNSETIFF, ifr)

		except IOError:
			common.internal_print("Error: Cannot create tunnel. Is {0} in use?".format(dev), -1)
			sys.exit(-1)

		return tun 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:13,代码来源:interface.py

示例11: _get_devnull

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def _get_devnull(self):
        if not hasattr(self, '_devnull'):
            self._devnull = os.open(os.devnull, os.O_RDWR)
        return self._devnull 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:subprocess.py

示例12: dev_null

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def dev_null(self, request):
        fd = os.open(os.devnull, os.O_RDWR)

        def close_dev_null():
            os.close(fd)

        request.addfinalizer(close_dev_null)
        return fd 
开发者ID:latchset,项目名称:custodia,代码行数:10,代码来源:base.py

示例13: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def __init__(self, filepath, parent=None):
        super().__init__(parent)
        self._filepath = filepath
        # We open as R/W so we never get EOF and have to reopen the pipe.
        # See http://www.outflux.net/blog/archives/2008/03/09/using-select-on-a-fifo/
        # We also use os.open and os.fdopen rather than built-in open so we
        # can add O_NONBLOCK.
        # pylint: disable=no-member,useless-suppression
        fd = os.open(filepath, os.O_RDWR | os.O_NONBLOCK)
        # pylint: enable=no-member,useless-suppression
        self._fifo = os.fdopen(fd, 'r')
        self._notifier = QSocketNotifier(typing.cast(sip.voidptr, fd),
                                         QSocketNotifier.Read, self)
        self._notifier.activated.connect(  # type: ignore[attr-defined]
            self.read_line) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:17,代码来源:userscripts.py

示例14: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def __init__(self):
        # Open a pair of null files
        self.null_fds = [os.open(os.devnull, os.O_RDWR) for _ in range(2)]

        # Save the actual stdout (1) and stderr (2) file descriptors.
        self.save_fds = (os.dup(1), os.dup(2)) 
开发者ID:thenetcircle,项目名称:dino,代码行数:8,代码来源:__init__.py

示例15: acquire

# 需要导入模块: import os [as 别名]
# 或者: from os import O_RDWR [as 别名]
def acquire(self, blocking=True):
        """Acquire the lock if possible.

        If the lock is in use and ``blocking`` is ``False``, return
        ``False``.

        Otherwise, check every `self.delay` seconds until it acquires
        lock or exceeds `self.timeout` and raises an exception.

        """
        start = time.time()
        while True:
            try:
                fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR)
                with os.fdopen(fd, 'w') as fd:
                    fd.write('{0}'.format(os.getpid()))
                break
            except OSError as err:
                if err.errno != errno.EEXIST:  # pragma: no cover
                    raise
                if self.timeout and (time.time() - start) >= self.timeout:
                    raise AcquisitionError('Lock acquisition timed out.')
                if not blocking:
                    return False
                time.sleep(self.delay)

        self._locked = True
        return True 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:30,代码来源:workflow.py


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