コード例 #1
0
ファイル: file_utils.py プロジェクト: goc9000/baon
def check_default_filesystem_supports_permissions():
    """
    Checks whether the default file systems supports at least basic file permissions AND that BAON is equipped to
    set permissions in that environment.
    """
    if check_default_filesystem_is_posix():
        return True
    if on_windows():
        return permissions_supported()

    return False
コード例 #2
0
ファイル: FileSystemTestCase.py プロジェクト: goc9000/baon
    def set_rights(self, path, read=None, write=None, execute=None, traverse=None, win_delete=None):
        if read is None and write is None and execute is None and traverse is None and win_delete is None:
            return # Bail if nothing to do

        assert check_default_filesystem_supports_permissions(), 'Cannot set permissions on this file system'
        assert traverse is not False or check_default_filesystem_is_posix(),\
            'Traverse permission only makes sense in POSIX filesystems'

        full_path = self.resolve_test_path(path)

        if check_default_filesystem_is_posix():
            set_file_rights(full_path, read=read, write=write, execute=execute, traverse=traverse)
        elif windows_utils.on_windows():
            windows_utils.set_file_rights(full_path, read=read, write=write, execute=execute, delete=win_delete)
        else:
            raise AssertionError("Don't know how to set permissions on this file system")
コード例 #3
0
ファイル: FileSystemTestCase.py プロジェクト: goc9000/baon
    def reset_rights(self, path, recursive=False):
        if not check_default_filesystem_supports_permissions():
            return

        full_path = self.resolve_test_path(path)

        if check_default_filesystem_is_posix():
            is_dir = os.path.isdir(full_path)

            set_file_rights(
                full_path,
                read=True,
                write=True,
                execute=True if not is_dir else None,
                traverse=True if is_dir and check_default_filesystem_is_posix() else None,
            )

            if recursive and is_dir:
                for item in os.listdir(full_path):
                    self.reset_rights(os.path.join(path, item), True)
        elif windows_utils.on_windows():
            windows_utils.reset_file_rights(full_path, recursive=recursive)
        else:
            raise AssertionError("Don't know how to reset permissions on this file system")