Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installdriver: prompt on fresh install #624

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions generated/nidaqmx/_install_daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,29 +328,42 @@ def _ask_user_confirmation(user_message: str) -> bool:


def _upgrade_daqmx_user_confirmation(
latest_version: str,
installed_version: str,
download_url: str,
latest_version: str,
release: str,
) -> bool:
"""
Confirm with the user and return the user response.
"""
_logger.debug("Entering _upgrade_daqmx_user_confirmation")
latest_parts: Tuple[int, ...] = _parse_version(latest_version)
installed_parts: Tuple[int, ...] = _parse_version(installed_version)
latest_parts: Tuple[int, ...] = _parse_version(latest_version)
if installed_parts >= latest_parts:
print(
f"Installed NI-DAQmx version ({installed_version}) is up to date. (Expected {latest_version} or newer.)"
f"Installed NI-DAQmx version ({installed_version}) is up to date. (Expected {latest_version} ({release}) or newer.)"
)
return False
is_upgrade = _ask_user_confirmation(
f"Installed NI-DAQmx version is {installed_version}. Latest version available is {latest_version}. Do you want to upgrade?"
f"Installed NI-DAQmx version is {installed_version}. Latest version available is {latest_version} ({release}). Do you want to upgrade?"
)
return is_upgrade


def _fresh_install_daqmx_user_confirmation(
latest_version: str,
release: str,
) -> bool:
"""
Confirm with the user and return the user response.
"""
_logger.debug("Entering _fresh_install_daqmx_user_confirmation")
return _ask_user_confirmation(
f"Latest NI-DAQmx version available is {latest_version} ({release}). Do you want to install?"
)


def _is_distribution_supported() -> None:
"""
Raises an exception if the linux distribution and its version are not supported.
Expand Down Expand Up @@ -401,18 +414,23 @@ def _install_daqmx_driver():
)

installed_version = _get_daqmx_installed_version()
download_url, latest_version, release, supported_os = _get_driver_details(platform)
download_url, latest_version, release, _ = _get_driver_details(platform)

if not download_url:
raise click.ClickException(f"Failed to fetch the download url.")
if not release:
if not release or not latest_version:
raise click.ClickException(f"Failed to fetch the release version string.")
else:
if installed_version and latest_version:
if installed_version:
user_response = _upgrade_daqmx_user_confirmation(
latest_version, installed_version, download_url, release
installed_version, latest_version, release
)
else:
user_response = _fresh_install_daqmx_user_confirmation(
latest_version, release
)
if installed_version is None or (installed_version and user_response):

if user_response:
if platform == "Linux":
_install_daqmx_driver_linux_core(download_url, release)
else:
Expand Down
38 changes: 28 additions & 10 deletions src/handwritten/_install_daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,29 +328,42 @@ def _ask_user_confirmation(user_message: str) -> bool:


def _upgrade_daqmx_user_confirmation(
latest_version: str,
installed_version: str,
download_url: str,
latest_version: str,
release: str,
) -> bool:
"""
Confirm with the user and return the user response.
"""
_logger.debug("Entering _upgrade_daqmx_user_confirmation")
latest_parts: Tuple[int, ...] = _parse_version(latest_version)
installed_parts: Tuple[int, ...] = _parse_version(installed_version)
latest_parts: Tuple[int, ...] = _parse_version(latest_version)
if installed_parts >= latest_parts:
print(
f"Installed NI-DAQmx version ({installed_version}) is up to date. (Expected {latest_version} or newer.)"
f"Installed NI-DAQmx version ({installed_version}) is up to date. (Expected {latest_version} ({release}) or newer.)"
)
return False
is_upgrade = _ask_user_confirmation(
f"Installed NI-DAQmx version is {installed_version}. Latest version available is {latest_version}. Do you want to upgrade?"
f"Installed NI-DAQmx version is {installed_version}. Latest version available is {latest_version} ({release}). Do you want to upgrade?"
)
return is_upgrade


def _fresh_install_daqmx_user_confirmation(
latest_version: str,
release: str,
) -> bool:
"""
Confirm with the user and return the user response.
"""
_logger.debug("Entering _fresh_install_daqmx_user_confirmation")
return _ask_user_confirmation(
f"Latest NI-DAQmx version available is {latest_version} ({release}). Do you want to install?"
)


def _is_distribution_supported() -> None:
"""
Raises an exception if the linux distribution and its version are not supported.
Expand Down Expand Up @@ -401,18 +414,23 @@ def _install_daqmx_driver():
)

installed_version = _get_daqmx_installed_version()
download_url, latest_version, release, supported_os = _get_driver_details(platform)
download_url, latest_version, release, _ = _get_driver_details(platform)

if not download_url:
raise click.ClickException(f"Failed to fetch the download url.")
if not release:
if not release or not latest_version:
raise click.ClickException(f"Failed to fetch the release version string.")
else:
if installed_version and latest_version:
if installed_version:
user_response = _upgrade_daqmx_user_confirmation(
latest_version, installed_version, download_url, release
installed_version, latest_version, release
)
else:
user_response = _fresh_install_daqmx_user_confirmation(
latest_version, release
)
if installed_version is None or (installed_version and user_response):

if user_response:
if platform == "Linux":
_install_daqmx_driver_linux_core(download_url, release)
else:
Expand Down
Loading