Skip to content

Commit

Permalink
better update command suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Feb 14, 2024
1 parent a13bdf3 commit 9eb5054
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cat_win/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _show_help(shell: bool = False) -> None:
help_message += f"\t{'catw f trunc=a:b:c': <25}"
help_message += "Output f's content starting at line a, ending at line b, stepping c\n"
print(help_message)
print_update_information(__project__, __version__, color_dic, os.path.basename(sys.executable))
print_update_information(__project__, __version__, color_dic, on_windows_os)


def _show_version() -> None:
Expand All @@ -185,7 +185,7 @@ def _show_version() -> None:
version_message += 'Install time: \t-\n'
version_message += f"Author: \t{__author__}\n"
print(version_message)
print_update_information(__project__, __version__, color_dic, os.path.basename(sys.executable))
print_update_information(__project__, __version__, color_dic, on_windows_os)


def _show_debug(args: list, unknown_args: list, known_files: list, unknown_files: list,
Expand Down
21 changes: 15 additions & 6 deletions cat_win/web/updatechecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import json
import os
import sys
import urllib.request

Expand Down Expand Up @@ -127,7 +128,7 @@ def new_version_available(current_version: str, latest_version: str) -> int:


def print_update_information(package: str, current_version: str, color_dic: dict,
py_executable: str) -> None:
on_windows_os: bool) -> None:
"""
prints update information if there are any.
Expand All @@ -138,16 +139,23 @@ def print_update_information(package: str, current_version: str, color_dic: dict
a version representation as string of the current version
color_dic (dict):
a dictionary translating the color-keywords to ANSI-Colorcodes
py_executable (str):
the python executable (from sys.executable)
on_windows_os (bool):
indicates whether the platfowm is Windows or not
"""
py_executable = sys.executable
if os.path.dirname(py_executable) in os.environ['PATH'].split(os.pathsep):
py_executable = os.path.basename(py_executable)
elif ' ' in py_executable:
py_executable = f'"{py_executable}"' if on_windows_os else py_executable.replace(' ', '\\ ')

latest_version = get_latest_package_version(package)
status = new_version_available(current_version, latest_version)

if status == STATUS_UP_TO_DATE:
return
message = ''
warning = ''
info = ''

message, warning, info = '', '', ''

if abs(status) == STATUS_STABLE_RELEASE_AVAILABLE:
message += f"{color_dic[CKW.MESSAGE_IMPORTANT]}"
message += f"A new stable release of {package} is available: v{latest_version}"
Expand All @@ -169,6 +177,7 @@ def print_update_information(package: str, current_version: str, color_dic: dict
info += f"{color_dic[CKW.MESSAGE_INFORMATION]}Take a look at the changelog here:"
info += f"{color_dic[CKW.RESET_ALL]}\n{color_dic[CKW.MESSAGE_INFORMATION]}"
info += f"{__url__}/blob/main/CHANGELOG.md{color_dic[CKW.RESET_ALL]}"

print(message)
print(warning, file=sys.stderr)
print(info)

0 comments on commit 9eb5054

Please sign in to comment.