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


Python stat.S_IWRITE属性代码示例

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


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

示例1: copymode

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def copymode(src, dst, follow_symlinks=True, **kwargs):
    """
    Copy the permission bits from src to dst. The file contents, owner, and group are unaffected. Due to the
    limitations of Windows, this function only sets/unsets the dst's FILE_ATTRIBUTE_READ_ONLY flag based on what src's
    attribute is set to.

    If follow_symlinks is 'False', and both src and dst are symbolic links, copymode() will attempt to modify the mode
    of dst itself (rather than the file it points to).

    This function supports src and dst being either a local or UNC path. A relative path will be resolved based on the
    current working directory.

    :param src: The src file or directory to copy the read only flag from.
    :param dst: The dst file or directory to copy the read only flag to.
    :param follow_symlinks: Whether to copy the read only flag on the symlink or the target of the symlink.
    :param kwargs: Common arguments used to build the SMB Session for any UNC paths.
    """
    src_mode = stat.S_IMODE(_get_file_stat(src, follow_symlinks, **kwargs).st_mode)

    norm_dst = ntpath.normpath(dst)
    if norm_dst.startswith('\\\\'):
        read_only = not (src_mode & stat.S_IWRITE == stat.S_IWRITE and src_mode & stat.S_IREAD == stat.S_IREAD)
        _set_file_basic_info(dst, follow_symlinks, read_only=read_only, **kwargs)
    else:
        _local_chmod(dst, src_mode, follow_symlinks) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:27,代码来源:shutil.py

示例2: test_copymode_remote_to_local

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def test_copymode_remote_to_local(smb_share, tmpdir):
    test_dir = tmpdir.mkdir("test")
    src_filename = "%s\\source.txt" % smb_share
    dst_filename = "%s\\target.txt" % test_dir

    with open_file(src_filename, mode='w', file_attributes=FileAttributes.FILE_ATTRIBUTE_READONLY) as fd:
        fd.write(u"content")

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    copymode(src_filename, dst_filename)

    actual = os.stat(dst_filename).st_mode
    assert stat.S_IMODE(actual) & stat.S_IWRITE == 0

    remove(src_filename)
    with open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    copymode(src_filename, dst_filename)

    actual = os.stat(dst_filename).st_mode
    assert stat.S_IMODE(actual) & stat.S_IWRITE == stat.S_IWRITE 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:26,代码来源:test_smbclient_shutil.py

示例3: test_copystat_remote_to_local

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def test_copystat_remote_to_local(smb_share, tmpdir):
    test_dir = tmpdir.mkdir("test")
    src_filename = "%s\\source.txt" % smb_share
    dst_filename = "%s\\target.txt" % test_dir

    with open_file(src_filename, mode='w', file_attributes=FileAttributes.FILE_ATTRIBUTE_READONLY) as fd:
        fd.write(u"content")
    utime(src_filename, times=(1024, 1024))

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    copystat(src_filename, dst_filename)

    actual = os.stat(dst_filename)
    assert actual.st_atime == 1024
    assert actual.st_mtime == 1024
    assert stat.S_IMODE(actual.st_mode) & stat.S_IWRITE == 0 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:20,代码来源:test_smbclient_shutil.py

示例4: test_copystat_local_to_local

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def test_copystat_local_to_local(tmpdir):
    test_dir = tmpdir.mkdir("test")
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)
    os.utime(src_filename, (1024, 1024))

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    copystat(src_filename, dst_filename)

    actual = os.stat(dst_filename)
    assert actual.st_atime == 1024
    assert actual.st_mtime == 1024
    assert stat.S_IMODE(actual.st_mode) & stat.S_IWRITE == 0 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:21,代码来源:test_smbclient_shutil.py

示例5: ___test_folder_not_writeable

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def ___test_folder_not_writeable(self):
        # make sure we get permissions error and not 'database is locked'
        s = ts.SetupDbAndCredentials()
        s.test_setup("test_folder_not_writeable", trash_files=True, trash_db=True)
        try:
            if os.name == "nt":
                os.chmod(str(s.root), stat.S_IREAD)
            else:
                s.root.chmod(0o444)
            with self.assertRaises(PermissionError):
                s.gp.main([str(s.root), "--skip-shared-albums"])
        finally:
            if os.name == "nt":
                os.chmod(str(s.root), stat.S_IWRITE | stat.S_IREAD)
            else:
                os.chmod(str(s.root), 0o777)
            shutil.rmtree(str(s.root)) 
开发者ID:gilesknap,项目名称:gphotos-sync,代码行数:19,代码来源:test_regression.py

示例6: open

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def open(self):
        """Reads file.

        :return: byte string.

        """
        if self.path.endswith('.mp3'):
            try:
                stream = open(self.path, 'r+b')
            except PermissionError:
                os.chmod(self.path, S_IWRITE)
                stream = open(self.path, 'r+b')
        else:
            raise MP3OpenFileError('File must be MP3 format')
        data = stream.read()
        stream.close()
        return data 
开发者ID:artcom-net,项目名称:mp3-tagger,代码行数:19,代码来源:mp3.py

示例7: rmtree_errorhandler

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def rmtree_errorhandler(func, path, exc_info):
    """
    On Windows, some files are read-only (e.g. in in .svn dirs), so when
    rmtree() tries to remove them, an exception is thrown.
    We catch that here, remove the read-only attribute, and hopefully
    continue without problems.
    """
    exctype, value = exc_info[:2]
    # looking for a windows error
    if exctype is not WindowsError or 'Access is denied' not in str(value):
        raise
    # file type should currently be read only
    if ((os.stat(path).st_mode & stat.S_IREAD) != stat.S_IREAD):
        raise
    # convert to read/write
    os.chmod(path, stat.S_IWRITE)
    # use the original function to repeat the operation
    func(path) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:_os.py

示例8: copyFunc

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def copyFunc(dest, source, env):
    """Install a source file or directory into a destination by copying,
    (including copying permission/mode bits)."""

    if os.path.isdir(source):
        if os.path.exists(dest):
            if not os.path.isdir(dest):
                raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source)))
        else:
            parent = os.path.split(dest)[0]
            if not os.path.exists(parent):
                os.makedirs(parent)
        scons_copytree(source, dest)
    else:
        shutil.copy2(source, dest)
        st = os.stat(source)
        os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)

    return 0

#
# Functions doing the actual work of the InstallVersionedLib Builder.
# 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:25,代码来源:install.py

示例9: copyFuncVersionedLib

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def copyFuncVersionedLib(dest, source, env):
    """Install a versioned library into a destination by copying,
    (including copying permission/mode bits) and then creating
    required symlinks."""

    if os.path.isdir(source):
        raise SCons.Errors.UserError("cannot install directory `%s' as a version library" % str(source) )
    else:
        # remove the link if it is already there
        try:
            os.remove(dest)
        except:
            pass
        shutil.copy2(source, dest)
        st = os.stat(source)
        os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
        installShlibLinks(dest, source, env)

    return 0 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:21,代码来源:install.py

示例10: CacheRetrieveFunc

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def CacheRetrieveFunc(target, source, env):
    t = target[0]
    fs = t.fs
    cd = env.get_CacheDir()
    cachedir, cachefile = cd.cachepath(t)
    if not fs.exists(cachefile):
        cd.CacheDebug('CacheRetrieve(%s):  %s not in cache\n', t, cachefile)
        return 1
    cd.CacheDebug('CacheRetrieve(%s):  retrieving from %s\n', t, cachefile)
    if SCons.Action.execute_actions:
        if fs.islink(cachefile):
            fs.symlink(fs.readlink(cachefile), t.get_internal_path())
        else:
            env.copy_from_cache(cachefile, t.get_internal_path())
            try:
                os.utime(cachefile, None)
            except OSError:
                pass
        st = fs.stat(cachefile)
        fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
    return 0 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:23,代码来源:CacheDir.py

示例11: removePath

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def removePath(path):
    if sys.platform == "win32":
        def onerror(func, path, exc):
            os.chmod(path, stat.S_IWRITE)
            os.unlink(path)
    else:
        onerror = None

    try:
        if os.path.lexists(path):
            if os.path.isdir(path) and not os.path.islink(path):
                shutil.rmtree(path, onerror=onerror)
            else:
                os.unlink(path)
    except OSError as e:
        raise BuildError("Error removing '"+path+"': " + str(e)) 
开发者ID:BobBuildTool,项目名称:bob,代码行数:18,代码来源:utils.py

示例12: test_remove_negative

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def test_remove_negative(self):
        import stat
        self.assertRaisesNumber(WindowsError, errno.ENOENT, lambda : nt.remove('some_file_that_does_not_exist'))
        try:
            file('some_test_file.txt', 'w').close()
            nt.chmod('some_test_file.txt', stat.S_IREAD)
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            
            f = file('some_test_file.txt', 'w+')
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            f.close()
        finally:
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            nt.unlink('some_test_file.txt')
            
            

    # rename tests 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_nt.py

示例13: test_access

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def test_access(self):
        f = file('new_file_name', 'w')
        f.close()
        
        self.assertEqual(nt.access('new_file_name', nt.F_OK), True)
        self.assertEqual(nt.access('new_file_name', nt.R_OK), True)
        self.assertEqual(nt.access('does_not_exist.py', nt.F_OK), False)
        self.assertEqual(nt.access('does_not_exist.py', nt.R_OK), False)

        nt.chmod('new_file_name', 0x100) # S_IREAD
        self.assertEqual(nt.access('new_file_name', nt.W_OK), False)
        nt.chmod('new_file_name', 0x80)  # S_IWRITE
            
        nt.unlink('new_file_name')
        
        nt.mkdir('new_dir_name')
        self.assertEqual(nt.access('new_dir_name', nt.R_OK), True)
        nt.rmdir('new_dir_name')
        
        self.assertRaises(TypeError, nt.access, None, 1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_nt.py

示例14: CacheRetrieveFunc

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def CacheRetrieveFunc(target, source, env):
    t = target[0]
    fs = t.fs
    cd = env.get_CacheDir()
    cachedir, cachefile = cd.cachepath(t)
    if not fs.exists(cachefile):
        cd.CacheDebug('CacheRetrieve(%s):  %s not in cache\n', t, cachefile)
        return 1
    cd.CacheDebug('CacheRetrieve(%s):  retrieving from %s\n', t, cachefile)
    if SCons.Action.execute_actions:
        if fs.islink(cachefile):
            fs.symlink(fs.readlink(cachefile), t.get_internal_path())
        else:
            env.copy_from_cache(cachefile, t.get_internal_path())
        st = fs.stat(cachefile)
        fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
    return 0 
开发者ID:bq,项目名称:web2board,代码行数:19,代码来源:CacheDir.py

示例15: handle_rm_readonly_files

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IWRITE [as 别名]
def handle_rm_readonly_files(_func, path, exc):
    """Handle read-only files on Windows. Adapted from https://stackoverflow.com/a/21263493.

    Args:
        _func (function): Function which raised the exception
        path (str): Path name passed to function
        exc (exception): Exception information returned by sys.exc_info()

    Raises:
        OSError: Raised if the read-only files are unable to be handled
    """
    assert platform.system() == "Windows"
    path = Path(path)
    if exc[1].errno == errno.EACCES:
        Path.chmod(path, stat.S_IWRITE)
        assert path.is_file()
        path.unlink()
    else:
        raise OSError("Unable to handle read-only files.") 
开发者ID:MozillaSecurity,项目名称:funfuzz,代码行数:21,代码来源:file_system_helpers.py


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