Skip to content

textual_fspicker.safe_tests

Support functions for doing safe filesystem tests.

This module provides some functions for performing tests on entries in the filesystem in a way that swallows some errors that we don't want causing the application to crash on. In most cases this is going to be a PermissionError, which for UI stuff is better ignored than raised.

is_dir

is_dir(location)

A safe version of is_dir.

Parameters:

Name Type Description Default

location

Path

The location to test.

required

Returns:

Type Description
bool

True if the location looks like a directory, False if not, or if it could not be determined.

This function swallows PermissionError and just returns that the location isn't a directory.

is_file

is_file(location)

A safe version of is_file.

Parameters:

Name Type Description Default

location

Path

The location to test.

required

Returns:

Type Description
bool

True if the location looks like a file or if it could not be determined, False it can be known it doesn't look like a file.

This function swallows PermissionError and just returns that the location is a file.

is_symlink(location)

A safe version of is_symlink.

Parameters:

Name Type Description Default

location

Path

The location to test.

required

Returns:

Type Description
bool

True if the location looks like a symlink, False if not, or if it could not be determined.

This function swallows PermissionError and just returns that the location isn't a symlink.