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


Python stat.S_IREAD屬性代碼示例

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


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

示例1: copymode

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [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_copystat_local_to_remote

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def test_copystat_local_to_remote(smb_share, tmpdir):
    test_dir = tmpdir.mkdir("test")
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % smb_share

    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_file(dst_filename, mode='w') as fd:
        fd.write(u"content")

    copystat(src_filename, dst_filename)

    actual = smbclient_stat(dst_filename)
    assert actual.st_atime == 1024
    assert actual.st_mtime == 1024
    assert actual.st_file_attributes & FileAttributes.FILE_ATTRIBUTE_READONLY == FileAttributes.FILE_ATTRIBUTE_READONLY 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:21,代碼來源:test_smbclient_shutil.py

示例3: test_copystat_local_to_local

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [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

示例4: test_copystat_local_to_local_symlink_dont_follow_fail

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def test_copystat_local_to_local_symlink_dont_follow_fail(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)

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

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    expected = "follow_symlinks unavailable on this platform"
    with pytest.raises(NotImplementedError, match=re.escape(expected)):
        copystat(src_link, dst_link, follow_symlinks=False) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:23,代碼來源:test_smbclient_shutil.py

示例5: ___test_folder_not_writeable

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [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: rmtree_errorhandler

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [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

示例7: test_on_error

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def test_on_error(self):
        self.errorState = 0
        os.mkdir(TESTFN)
        self.childpath = os.path.join(TESTFN, 'a')
        f = open(self.childpath, 'w')
        f.close()
        old_dir_mode = os.stat(TESTFN).st_mode
        old_child_mode = os.stat(self.childpath).st_mode
        # Make unwritable.
        os.chmod(self.childpath, stat.S_IREAD)
        os.chmod(TESTFN, stat.S_IREAD)

        shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
        # Test whether onerror has actually been called.
        self.assertEqual(self.errorState, 2,
                            "Expected call to onerror function did not happen.")

        # Make writable again.
        os.chmod(TESTFN, old_dir_mode)
        os.chmod(self.childpath, old_child_mode)

        # Clean up.
        shutil.rmtree(TESTFN) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_shutil.py

示例8: test_remove_negative

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [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

示例9: test_access

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [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

示例10: test_on_error

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def test_on_error(self):
            self.errorState = 0
            os.mkdir(TESTFN)
            self.childpath = os.path.join(TESTFN, 'a')
            f = open(self.childpath, 'w')
            f.close()
            old_dir_mode = os.stat(TESTFN).st_mode
            old_child_mode = os.stat(self.childpath).st_mode
            # Make unwritable.
            os.chmod(self.childpath, stat.S_IREAD)
            os.chmod(TESTFN, stat.S_IREAD)

            shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
            # Test whether onerror has actually been called.
            self.assertEqual(self.errorState, 2,
                             "Expected call to onerror function did not happen.")

            # Make writable again.
            os.chmod(TESTFN, old_dir_mode)
            os.chmod(self.childpath, old_child_mode)

            # Clean up.
            shutil.rmtree(TESTFN) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:25,代碼來源:test_shutil.py

示例11: rmtree_errorhandler

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def rmtree_errorhandler(func, path, exc_info):
    """On Windows, the files in .svn are read-only, 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]
    if not ((exctype is WindowsError and value.args[0] == 5) or #others
            (exctype is OSError and value.args[0] == 13) or #python2.4
            (exctype is PermissionError and value.args[3] == 5) #python3.3
            ):
        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:aliyun,項目名稱:oss-ftp,代碼行數:19,代碼來源:util.py

示例12: write

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def write(self, json_dict):

        json_data = json.dumps(json_dict, indent=4, sort_keys=True)
        if self.path is None:
            return json_data

        temp_path = "%s.tmp.%s" % (self.path, os.getpid())
        with open(temp_path, "w") as f:
            f.write(json_data)
            f.flush()
            os.fsync(f.fileno())

        if os.path.exists(self.path):
            mode = os.stat(self.path).st_mode
        else:
            mode = stat.S_IREAD | stat.S_IWRITE
        try:
            os.rename(temp_path, self.path)
        except Exception:  # pylint: disable=broad-except
            os.remove(self.path)
            os.rename(temp_path, self.path)
        os.chmod(self.path, mode) 
開發者ID:lbryio,項目名稱:torba,代碼行數:24,代碼來源:wallet.py

示例13: test_force_write_mode_with_permission_error

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def test_force_write_mode_with_permission_error(self):
        job = self.project.open_job(dict(a=0))
        job.init()
        job.doc.a = True
        x = job.doc.a
        path = os.path.dirname(job.doc._filename)
        mode = os.stat(path).st_mode
        logging.disable(logging.CRITICAL)
        try:
            assert job.doc.a == x
            with pytest.raises(BufferedFileError):
                with signac.buffered():
                    assert job.doc.a == x
                    job.doc.a = not x
                    assert job.doc.a == (not x)
                    os.chmod(path, S_IREAD)  # Trigger permissions error
        finally:
            logging.disable(logging.NOTSET)
            os.chmod(path, mode)
        assert job.doc.a == x 
開發者ID:glotzerlab,項目名稱:signac,代碼行數:22,代碼來源:test_buffered_mode.py

示例14: ensure_private_ssh_key

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def ensure_private_ssh_key():
    global PRIVATE_SSH_KEY
    if PRIVATE_SSH_KEY:
        key_path = os.path.expanduser('~/.ssh')
        key_file = os.path.join(key_path, 'id_rsa')
        try:
            if not os.path.isdir(key_path):
                os.mkdir(key_path)
            if not os.path.isfile(key_file):
                shutil.copyfile(PRIVATE_SSH_KEY, key_file)
                os.chmod(key_file, stat.S_IWRITE | stat.S_IREAD)
        except (IOError, OSError) as error:
            PRIVATE_SSH_KEY = ''
            print(error)
        else:
            return True
    return False


# TODO: unify with frontend config 
開發者ID:marcopaz,項目名稱:is-service-up,代碼行數:22,代碼來源:config.py

示例15: ensure_code_file

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IREAD [as 別名]
def ensure_code_file(self, code, file_path):
        """"""
        if file_path:
            file_path = os.path.abspath(file_path)
            if not os.path.isfile(file_path):
                raise RequirementsInvalid(
                    'Arg file_path is not a valid file.'
                )
            self.code_file = file_path
        else:
            if code:
                (fd, temp_file_path) = tempfile.mkstemp()
                with os.fdopen(fd, 'w') as f:
                    f.write(code)
                self.code_file = self.temp_file = temp_file_path
            else:
                raise RequirementsInvalid(
                    'Neither code nor code file_path specified.'
                )
        st = os.stat(self.code_file)
        os.chmod(self.code_file,
                 st.st_mode | stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH) 
開發者ID:NtesEyes,項目名稱:pylane,代碼行數:24,代碼來源:injector.py


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