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


Python os.O_APPEND屬性代碼示例

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


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

示例1: write_port_interface_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def write_port_interface_file(self, netns_interface, fixed_ips, mtu,
                                  interface_file_path, template_port):
        # write interface file

        # If we are using a consolidated interfaces file, just append
        # otherwise clear the per interface file as we are rewriting it
        # TODO(johnsom): We need a way to clean out old interfaces records
        if CONF.amphora_agent.agent_server_network_file:
            flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND
        else:
            flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC

        # mode 00644
        mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH

        with os.fdopen(os.open(interface_file_path, flags, mode),
                       'w') as text_file:
            text = self._generate_network_file_text(
                netns_interface, fixed_ips, mtu, template_port)
            text_file.write(text) 
開發者ID:openstack,項目名稱:octavia,代碼行數:22,代碼來源:osutils.py

示例2: mode2flags

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def mode2flags(mode):
    """mode2flags(modestring)
    Converts a file mode in string form (e.g. "w+") to an integer flag value
    suitable for os.open().  """
    flags = os.O_LARGEFILE # XXX only when Python compiled with large file support
    if mode == "a":
        flags = flags | os.O_APPEND | os.O_WRONLY
    elif mode == "a+":
        flags = flags | os.O_APPEND | os.O_RDWR | os.O_CREAT
    elif mode == "w":
        flags = flags | os.O_WRONLY | os.O_CREAT
    elif mode == "w+":
        flags = flags | os.O_RDWR | os.O_CREAT
    elif mode == "r":
        pass # O_RDONLY is zero already
    elif mode == "r+":
        flags = flags | os.O_RDWR
    return flags


# precompute the O_ flag list, and stash it in the os module 
開發者ID:kdart,項目名稱:pycopia,代碼行數:23,代碼來源:UserFile.py

示例3: _convert_pflags

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def _convert_pflags(self, pflags):
        "convert SFTP-style open() flags to python's os.open() flags"
        if (pflags & SFTP_FLAG_READ) and (pflags & SFTP_FLAG_WRITE):
            flags = os.O_RDWR
        elif pflags & SFTP_FLAG_WRITE:
            flags = os.O_WRONLY
        else:
            flags = os.O_RDONLY
        if pflags & SFTP_FLAG_APPEND:
            flags |= os.O_APPEND
        if pflags & SFTP_FLAG_CREATE:
            flags |= os.O_CREAT
        if pflags & SFTP_FLAG_TRUNC:
            flags |= os.O_TRUNC
        if pflags & SFTP_FLAG_EXCL:
            flags |= os.O_EXCL
        return flags 
開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:19,代碼來源:sftp_server.py

示例4: _convert_pflags

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def _convert_pflags(self, pflags):
        """convert SFTP-style open() flags to Python's os.open() flags"""
        if (pflags & SFTP_FLAG_READ) and (pflags & SFTP_FLAG_WRITE):
            flags = os.O_RDWR
        elif pflags & SFTP_FLAG_WRITE:
            flags = os.O_WRONLY
        else:
            flags = os.O_RDONLY
        if pflags & SFTP_FLAG_APPEND:
            flags |= os.O_APPEND
        if pflags & SFTP_FLAG_CREATE:
            flags |= os.O_CREAT
        if pflags & SFTP_FLAG_TRUNC:
            flags |= os.O_TRUNC
        if pflags & SFTP_FLAG_EXCL:
            flags |= os.O_EXCL
        return flags 
開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:19,代碼來源:sftp_server.py

示例5: _start_by_conf

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def _start_by_conf(self, proc_conf):
        """
        Start subprocess using ProcConfiguration object
        :param proc_conf: 
        :return: Popen object instance
        """
        assert isinstance(proc_conf, config.ProcessConfiguration)

        args = list(proc_conf.cmd.split(' '))
        self.log.info("Starting: %s on %s", proc_conf.cmd, gpu.format_gpu_id(proc_conf.gpu_indices))
        if proc_conf.gpu_indices is not None:
            env = {"CUDA_VISIBLE_DEVICES": ",".join(map(str, sorted(proc_conf.gpu_indices)))}
        else:
            env = None
        if proc_conf.log is None:
            stdout = None
        else:
            stdout = os.open(proc_conf.log, os.O_APPEND if os.path.exists(proc_conf.log) else os.O_CREAT)
        p = subprocess.Popen(args, cwd=proc_conf.dir, env=env, stdout=stdout, stderr=subprocess.STDOUT)
        return p 
開發者ID:Shmuma,項目名稱:gpu_mon,代碼行數:22,代碼來源:proc.py

示例6: _create_base_aws_cli_config_files_if_needed

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def _create_base_aws_cli_config_files_if_needed(adfs_config):
    def touch(fname, mode=0o600):
        flags = os.O_CREAT | os.O_APPEND
        with os.fdopen(os.open(fname, flags, mode)) as f:
            try:
                os.utime(fname, None)
            finally:
                f.close()

    aws_config_root = os.path.dirname(adfs_config.aws_config_location)

    if not os.path.exists(aws_config_root):
        os.mkdir(aws_config_root, 0o700)

    if not os.path.exists(adfs_config.aws_credentials_location):
        touch(adfs_config.aws_credentials_location)

    aws_credentials_root = os.path.dirname(adfs_config.aws_credentials_location)

    if not os.path.exists(aws_credentials_root):
        os.mkdir(aws_credentials_root, 0o700)

    if not os.path.exists(adfs_config.aws_config_location):
        touch(adfs_config.aws_config_location) 
開發者ID:venth,項目名稱:aws-adfs,代碼行數:26,代碼來源:prepare.py

示例7: wtrf

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def wtrf():
    if sys.platform != "win32":
        wt = int(os.environ['MYHDL_TO_PIPE'])
        rf = int(os.environ['MYHDL_FROM_PIPE'])
    else:
        wt = msvcrt.open_osfhandle(int(os.environ['MYHDL_TO_PIPE']), os.O_APPEND | os.O_TEXT)
        rf = msvcrt.open_osfhandle(int(os.environ['MYHDL_FROM_PIPE']), os.O_RDONLY | os.O_TEXT)

    return wt, rf 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:11,代碼來源:test_Cosimulation.py

示例8: flags

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def flags(self, *which):
        import fcntl, os

        if which:
            if len(which) > 1:
                raise TypeError, 'Too many arguments'
            which = which[0]
        else: which = '?'

        l_flags = 0
        if 'n' in which: l_flags = l_flags | os.O_NDELAY
        if 'a' in which: l_flags = l_flags | os.O_APPEND
        if 's' in which: l_flags = l_flags | os.O_SYNC

        file = self._file_

        if '=' not in which:
            cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
            if '!' in which: l_flags = cur_fl & ~ l_flags
            else: l_flags = cur_fl | l_flags

        l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)

        if 'c' in which:
            arg = ('!' not in which)    # 0 is don't, 1 is do close on exec
            l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)

        if '?' in which:
            which = ''                  # Return current flags
            l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
            if os.O_APPEND & l_flags: which = which + 'a'
            if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
                which = which + 'c'
            if os.O_NDELAY & l_flags: which = which + 'n'
            if os.O_SYNC & l_flags: which = which + 's'
            return which 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:38,代碼來源:posixfile.py

示例9: test_send

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def test_send(self):
        d1 = "Come again?"
        d2 = "I want to buy some cheese."
        fd = os.open(TESTFN, os.O_WRONLY | os.O_APPEND)
        w = asyncore.file_wrapper(fd)
        os.close(fd)

        w.write(d1)
        w.send(d2)
        w.close()
        self.assertEqual(file(TESTFN).read(), self.d + d1 + d2) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_asyncore.py

示例10: write_vip_interface_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def write_vip_interface_file(self, interface_file_path,
                                 primary_interface, vip, ip, broadcast,
                                 netmask, gateway, mtu, vrrp_ip, vrrp_version,
                                 render_host_routes, template_vip):
        # write interface file

        mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH

        # If we are using a consolidated interfaces file, just append
        # otherwise clear the per interface file as we are rewriting it
        # TODO(johnsom): We need a way to clean out old interfaces records
        if CONF.amphora_agent.agent_server_network_file:
            flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND
        else:
            flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC

        with os.fdopen(os.open(interface_file_path, flags, mode),
                       'w') as text_file:
            text = template_vip.render(
                consts=consts,
                interface=primary_interface,
                vip=vip,
                vip_ipv6=ip.version == 6,
                # For ipv6 the netmask is already the prefix
                prefix=(netmask if ip.version == 6
                        else utils.netmask_to_prefix(netmask)),
                broadcast=broadcast,
                netmask=netmask,
                gateway=gateway,
                network=utils.ip_netmask_to_cidr(vip, netmask),
                mtu=mtu,
                vrrp_ip=vrrp_ip,
                vrrp_ipv6=vrrp_version == 6,
                host_routes=render_host_routes,
                topology=CONF.controller_worker.loadbalancer_topology,
            )
            text_file.write(text) 
開發者ID:openstack,項目名稱:octavia,代碼行數:39,代碼來源:osutils.py

示例11: write_static_routes_interface_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def write_static_routes_interface_file(self, interface_file_path,
                                           interface, host_routes,
                                           template_routes, gateway,
                                           vip, netmask):
        # write static routes interface file

        mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH

        # TODO(johnsom): We need a way to clean out old interfaces records
        if CONF.amphora_agent.agent_server_network_file:
            flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND
        else:
            flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC

        with os.fdopen(os.open(interface_file_path, flags, mode),
                       'w') as text_file:
            text = template_routes.render(
                consts=consts,
                interface=interface,
                host_routes=host_routes,
                gateway=gateway,
                network=utils.ip_netmask_to_cidr(vip, netmask),
                vip=vip,
                topology=CONF.controller_worker.loadbalancer_topology,
            )
            text_file.write(text) 
開發者ID:openstack,項目名稱:octavia,代碼行數:28,代碼來源:osutils.py

示例12: file_flags_to_mode

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def file_flags_to_mode(flags):
    """Convert file's open() flags into a readable string.
    Used by Process.open_files().
    """
    modes_map = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'}
    mode = modes_map[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)]
    if flags & os.O_APPEND:
        mode = mode.replace('w', 'a', 1)
    mode = mode.replace('w+', 'r+')
    # possible values: r, w, a, r+, a+
    return mode 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:13,代碼來源:_pslinux.py

示例13: getFd

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def getFd(self, pio):
        "get file descriptor for given PInOut object"
        if self.fd is None:
            if isinstance(pio, PIn):
                self.fd = os.open(self.path, os.O_RDONLY)
            elif self.append:
                self.fd = os.open(self.path, os.O_WRONLY|os.O_CREAT|os.O_APPEND, 0o666)
            else:
                self.fd = os.open(self.path, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o666)
        return self.fd 
開發者ID:ComparativeGenomicsToolkit,項目名稱:Comparative-Annotation-Toolkit,代碼行數:12,代碼來源:pipeline.py

示例14: touch

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def touch(fname, mode=0o666, dir_fd=None, **kwargs):
    ## After http://stackoverflow.com/questions/1158076/implement-touch-using-python
    if sys.version_info < (3, 3, 0):
        with open(fname, 'a'):
            os.utime(fname, None) # set to now
    else:
        flags = os.O_CREAT | os.O_APPEND
        with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f:
            os.utime(f.fileno() if os.utime in os.supports_fd else fname,
                     dir_fd=None if os.supports_fd else dir_fd, **kwargs) 
開發者ID:GenealogyCollective,項目名稱:gprime,代碼行數:12,代碼來源:generic.py

示例15: touch

# 需要導入模塊: import os [as 別名]
# 或者: from os import O_APPEND [as 別名]
def touch(fname, mode=0o666, dir_fd=None, **kwargs):
    """Utility function for updating a file time stamp.

    Source:
        https://stackoverflow.com/questions/1158076/implement-touch-using-python
    """
    flags = os.O_CREAT | os.O_APPEND
    with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f:
        os.utime(f.fileno() if os.utime in os.supports_fd else fname,
                 dir_fd=None if os.supports_fd else dir_fd, **kwargs) 
開發者ID:glotzerlab,項目名稱:signac,代碼行數:12,代碼來源:test_sync.py


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