pilot_drive package

Subpackages

Submodules

pilot_drive.constants module

Top-level constants for PILOT Drive

pilot_drive.installer module

The installer/setup wizard for PILOT Drive

class pilot_drive.installer.Cmd(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

String enum of most used bash commands

APT_INSTALL = 'apt-get -y install'
GIT_CWD = 'git -C'
INSTALL_W_READ = 'install -m 644'
RASPI_CONFIG_NOINT = 'raspi-config nonint'
SYSTEMCTL = '/bin/systemctl'
YUM_INSTALL = 'yum --assumeyes install'
class pilot_drive.installer.Colors(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

String enum of colors to make the terminal pretty on install

BLUE = '\x1b[94m'
BOLD = '\x1b[1m'
CYAN = '\x1b[96m'
ENDC = '\x1b[0m'
FAIL = '\x1b[91m'
GREEN = '\x1b[92m'
UNDERLINE = '\x1b[4m'
WARNING = '\x1b[93m'
class pilot_drive.installer.CommonArchs(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

String enum of common system architectures

AARCH64 = 'aarch64'
ARM64 = 'arm64'
ARMV7L = 'armv7l'
INTEL_AMD = 'x86'
INTEL_AMD_64 = 'x86_64'
class pilot_drive.installer.DistroManagers(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

String enum of distribution managers

APT = 'apt'
YUM = 'yum'
exception pilot_drive.installer.FailedToDetectDistroManagerException

Bases: Exception

Raised when the distribution manager could not be detected

exception pilot_drive.installer.FailedToDetectSysArchException

Bases: Exception

Raised when the system architecture could not be detected

exception pilot_drive.installer.FailedToExecuteCommandException

Bases: Exception

Raised when a subprocess command fails to execute

class pilot_drive.installer.Installer(use_default: bool = True)

Bases: object

The installer used to install and configure PILOT Drive

configure_obd(settings: Dict, port: str) Dict

Configure an OBD port in settings

Parameters:
  • port – A validated port in string

  • settings – A dict of the settings to be written to

Returns:

a modified settings dict

detect_current_arch() CommonArchs

Detect the distribution manager used by the host

Returns:

DistroManager Enum item with the detected distribution manager

Raise:

FailedToDetectSysArchException if system arch could not be detected

detect_distro_manager() DistroManagers

Detect the distribution manager used by the host

Returns:

DistroManager Enum item with the detected distribution manager

Raise:

FailedToDetectDistroManagerException if distribution manager could not be detected

exec_cmd(command: str) str

Used to execute bash commands via subprocess

Parameters:

command – the command to be executed

Raises:

FailedToExecuteCommandException when the executed command returns and error

for_production()

Run PILOT Drive for production, configure the systemctl service, auto-start mozilla, etc.

get_settings() Dict

Get current settings or create a new

Returns:

A settings dict of either an existing or created settings

install_adb(settings: Dict) Dict

Install ADB and it’s needed dependencies

Parameters:

settings – A dict of the settings to be written to

Returns:

a modified settings dict

install_ancs(settings: Dict) Dict

Install ANCS4Linux to get iOS/iPadOS notifications

Based off of the shell script here: https://github.com/pzmarzly/ancs4linux/blob/master/autorun/install.sh

Parameters:

settings – A dict of the settings to be written to

Returns:

a modified settings dict

install_bt_speaker() None

Install bt-speaker by lukasjapan. For the time being, this is debian specific.

bt-speaker install is based off the sh installer, here: https://github.com/lukasjapan/bt-speaker/blob/master/install.sh

install_firefox() None

Install Firefox

install_from_distro_manager(packages: List[str]) None

Installs a specified package from the distribution manager depending on the OS/manager used

install_rpi_camera() int

Setup the Raspberry Pi camera along with it’s button trigger pin

Returns:

camera pin integer

interactive_install() None

Run the PILOT Drive installer/config

main(args: Namespace) None

The main installer method

Parameters:

args – The given command line arguments

non_interactive_install(args: Namespace) None

Run a non-interactive installer based on command line arguments

Parameters:

args – argparser args

prompt_input(prompt: str, regex_validator: str, example: str | None = None) str

Handle general string prompts in terminal

Parameters:
  • prompt – the prompt for the user

  • regex_validator – the regex string to validate the user input

  • example – an optional example string to be provided to the user

Returns:

the user’s input string

prompt_list(prompt: str, options: List[str], default_in: int) int

Handle list prompts in terminal

Parameters:
  • prompt – the prompt for the user

  • options – the list of options to present to the user

Returns:

the index of the user’s selected option

prompt_yes_no(prompt: str, default_in: str) bool

Handle y/n prompts in terminal as the user configures PILOT Drive

Parameters:
  • prompt – the message/question to prompt the user with

  • default_in – the default option (“y” or “n”)

Returns:

True if user input matches the default

rpi_setup()

Configuration specific to a Raspberry Pi running in production

write_settings(settings: Dict) None

Write to the settings file

Parameters:

settings – the settings dict that has been modified to be written

pilot_drive.installer.installer_arguments(parser: ArgumentParser) None

Initialize the command line arguments of the installer

Parameters:

parser – An initalized argparse.ArgumentParser to populate with arguments

pilot_drive.pd_manager module

The main PILOT Drive module that contains the class that starts the services and runs the websockets logic.

exception pilot_drive.pd_manager.FailedToCreateServiceException

Bases: Exception

Exception that occurs when a service could not be created

class pilot_drive.pd_manager.PilotDrive

Bases: object

The main class of PILOT Drive. Creates services (distributes logging & events queues), handles asyncio websockets, and attempts to properly exit services.

T = ~T
async consumer(websocket) None

The consumer to be used when new WebSocket messages come in from the UI

Parameters:

websocket – the WebSocket the UI is connected to

handle_message(message: str) None

The handler for when a new WebSocket event recieved from the UI client

Params message:

the event in from the UI, recieved as a JSON string to be converted to a dict

async handler(websocket) None

The handler used for the WebSocket connection, creates consumer and producer tasks

Parameters:

websocket – the WebSocket the UI is connected to

async main() None

The main method to be run, handles the WebSocket connection to the UI

async producer(websocket) None

The producer used when new events need to be pushed to the UI via WebSocket

Parameters:

websocket – the WebSocket the UI is connected to

refresh() None
Called when the webpage refreshes or reconnects to the WebSocket - used to recall data

like settings

service_factory(service: Generic[T], **kwargs) AbstractService
Creates a new service, and automatically passes master queue, event type, and logger. Takes

arguments of the service class, followed by all of the specified service’s keyword arguments.

Parameters:
  • service – a service class that has a base of AbstractService

  • **kwargs – extra keyword arguments to be passed to the given service

Returns:

an instance of the service class

Raises:

FailedToCreateServiceException: if service isn’t in the EventType enum

Raises:

FailedToCreateServiceException: if the service creation returns a TypeError, possibly if the keyword arguments are wrong

terminate(signum, frame)

Cleanly terminates each process and calls it’s cleanup method

Module contents

The main package for PILOT Drive