Interacting With Connected FlySight Devices

Device Identification

pyflysight.flysight_utils.iter_flysight_drives

iter_flysight_drives() -> abc.Generator[Path, None, None]

Iterate through the system's mounted disk partitions and yield likely FlySight devices.

FlySight devices should have a FLYSIGHT.TXT file in their root directory.

Warning

If called immediately after a device is plugged in (e.g. if being called in a polling loop), the OS may still be completing other tasks prior to assigning the device its actual drive letter. While in this state, attempts to read from the device will raise an OSError.

pyflysight.flysight_utils.get_flysight_drives

get_flysight_drives() -> tuple[Path]

Return a tuple of mounted disk partitions that are likely FlySight devices.

FlySight devices should have a FLYSIGHT.TXT file in their root directory.

Warning

If called immediately after a device is plugged in (e.g. if being called in a polling loop), the OS may still be completing other tasks prior to assigning the device its actual drive letter. While in this state, attempts to read from the device will raise an OSError.

pyflysight.flysight_utils.wait_for_flysight

wait_for_flysight(
    timeout: int = 10,
    polling_interval: float = 0.01,
    verbose: bool = True,
    raise_on_timeout: bool = False,
) -> tuple[Path]

Poll the system for likely FlySight devices.

FlySight devices should have a FLYSIGHT.TXT file in their root directory.

While running, the system will be polled every polling_interval seconds for likely devices, timing out after timeout seconds. A TimeoutError may be optionally raised by setting the raise_on_timeout flag to True.

Status messages may be suppressed by setting verbose to False.

Device Metadata

pyflysight.FlysightType

Bases: IntEnum

Enumerate expected FlySight hardware revisions.

VERSION_1 class-attribute instance-attribute

VERSION_1 = 1

VERSION_2 class-attribute instance-attribute

VERSION_2 = 2

pyflysight.flysight_utils.classify_hardware_type

classify_hardware_type(device_root: Path) -> FlysightType

Classify the most likely FlySight type for the provided drive.

Classification is made based on the contents of the FlySight's FLYSIGHT.TXT state information file, located at the root of the device. Based on the firmware source code for each hardware iteration, it appears that the contents & structure of this file differs significantly enough between the two hardware revisions to reliably make an accurate distinction.

pyflysight.flysight_utils.FlysightMetadata

Bases: NamedTuple

firmware instance-attribute

firmware: str

flysight_type instance-attribute

flysight_type: FlysightType

n_logs instance-attribute

n_logs: int

serial instance-attribute

serial: str

from_drive classmethod

from_drive(device_root: Path) -> FlysightMetadata

Parse the provided FlySight device for some descriptive metadata.

pyflysight.flysight_utils.get_device_metadata

get_device_metadata(device_root: Path) -> FlysightMetadata

Parse the provided FlySight device for some descriptive metadata.

Flight Log Interaction

pyflysight.flysight_utils.LogCopyStatus

Bases: NamedTuple

n_dirs_copied instance-attribute

n_dirs_copied: int

n_dirs_erased instance-attribute

n_dirs_erased: int

pyflysight.flysight_utils.copy_logs

copy_logs(
    device_root: Path,
    dest: Path,
    filter_func: abc.Callable[[Path], bool] | None = None,
    exist_ok: bool = True,
    remove_after: bool = False,
) -> LogCopyStatus

Copy the log file tree from the provided device root to the specified destination directory.

Note

This function operates on directories of log files only. FlySight V1 hardware groups flight logs by UTC date & time, so each directory may have multiple flight logs present. FlySight V2 hardware groups flight logs per logging session, so each flight log will have its own directory.

The number of directories copied and deleted is optionally returned for downstream notification purposes.

A filtering function may be optionally specified as a callable that accepts a path to a single directory of log files and returns False if the directory should not be copied.

If exist_ok is False, an exception will be raised if the target directory already exists in the destination.

If remove_after is True, the log directory will be deleted from the FlySight device after log data is copied to the destination.

Warning

exist_ok=True and remove_after=True are both destructive operations. Overwritten and/or deleted data will be lost permanently.

pyflysight.flysight_utils.erase_logs

erase_logs(device_root: Path, filter_func: abc.Callable[[Path], bool] | None = None) -> None

Erase all log files from the provided device root.

A filtering function may be optionally specified as a callable that accepts a path to a single directory of log files and returns False if the directory should not be erased.

Warning

This is a destructive operation. Data is removed permanently and cannot be recovered.