dcase_util.files.FileLock

class dcase_util.files.FileLock(filename, timeout=60, lock_file_extension='lock', **kwargs)[source]

Simple file-based locking class.

Usual solution for file locking is to use fcntl module. This class provides a bit more flexible solution as it does not require file to be open to get a lock. This locking system should also work with NFS mounts (also prior v3).

Constructor

Parameters
filenamestr

File path

timeoutint

Timeout in seconds

lock_file_extensionstr

File extension to be used for locking files

__init__(filename, timeout=60, lock_file_extension='lock', **kwargs)[source]

Constructor

Parameters
filenamestr

File path

timeoutint

Timeout in seconds

lock_file_extensionstr

File extension to be used for locking files

Methods

__init__(filename[, timeout, ...])

Constructor

delimiter([exclude_delimiters])

Use csv.sniffer to guess delimiter for CSV file

detect_file_format([filename])

Detect file format from extension

empty()

Check if file is empty

exists()

Checks that file exists

get_file_information()

Get file information, filename

is_package([filename])

Determine if the file is compressed package.

load([filename])

Load file

lock()

Lock file.

log([level])

Log container content

release()

Release file lock.

save([filename])

Save file

show([mode, indent, visualize])

Print container content

to_html([indent])

Get container information in a HTML formatted string

to_string([ui, indent])

Get container information in a string

touch()

Create locking file with current time stamp.

validate_format()

Validate file format

Attributes

bytes

File size in bytes

expired

Check is the locking file older than specified timeout.

is_locked

Check does the locking file exists.

logger

Logger instance

md5

Checksum for file.

valid_formats

Valid file formats