mirror of
https://github.com/dw-0/kiauh.git
synced 2026-02-06 01:16:13 +05:00
fix(core): standardize handling of None values for repo and version fields
- Improve local and remote version comparison by replacing default placeholders with None. - Update repo and branch logic to handle None values consistently. - Refactor type hints for better readability and accuracy.
This commit is contained in:
@@ -152,10 +152,9 @@ def symlink_webui_nginx_log(
|
|||||||
def get_local_client_version(client: BaseWebClient) -> str | None:
|
def get_local_client_version(client: BaseWebClient) -> str | None:
|
||||||
relinfo_file = client.client_dir.joinpath("release_info.json")
|
relinfo_file = client.client_dir.joinpath("release_info.json")
|
||||||
version_file = client.client_dir.joinpath(".version")
|
version_file = client.client_dir.joinpath(".version")
|
||||||
default = "-"
|
|
||||||
|
|
||||||
if not client.client_dir.exists():
|
if not client.client_dir.exists():
|
||||||
return default
|
return None
|
||||||
|
|
||||||
# try to get version from release_info.json first
|
# try to get version from release_info.json first
|
||||||
if relinfo_file.is_file():
|
if relinfo_file.is_file():
|
||||||
@@ -177,11 +176,11 @@ def get_local_client_version(client: BaseWebClient) -> str | None:
|
|||||||
try:
|
try:
|
||||||
with open(version_file, "r") as f:
|
with open(version_file, "r") as f:
|
||||||
line = f.readline().strip()
|
line = f.readline().strip()
|
||||||
return line or default
|
return line or None
|
||||||
except OSError:
|
except OSError:
|
||||||
Logger.print_error("Unable to read '.version'")
|
Logger.print_error("Unable to read '.version'")
|
||||||
|
|
||||||
return default
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_remote_client_version(client: BaseWebClient) -> str | None:
|
def get_remote_client_version(client: BaseWebClient) -> str | None:
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ class MainMenu(BaseMenu):
|
|||||||
status_data: ComponentStatus = status_fn(*args)
|
status_data: ComponentStatus = status_fn(*args)
|
||||||
code: int = status_data.status
|
code: int = status_data.status
|
||||||
status: StatusText = StatusMap[code]
|
status: StatusText = StatusMap[code]
|
||||||
owner: str = trunc_string(status_data.owner, 23)
|
owner: str = trunc_string(status_data.owner, 23) if status_data.owner else '-'
|
||||||
repo: str = trunc_string(status_data.repo, 23)
|
repo: str = trunc_string(status_data.repo, 23) if status_data.repo else '-'
|
||||||
instance_count: int = status_data.instances
|
instance_count: int = status_data.instances
|
||||||
|
|
||||||
count_txt: str = ""
|
count_txt: str = ""
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ class UpdateMenu(BaseMenu):
|
|||||||
|
|
||||||
def _format_local_status(self, local_version, remote_version) -> str:
|
def _format_local_status(self, local_version, remote_version) -> str:
|
||||||
color = Color.RED
|
color = Color.RED
|
||||||
if not local_version or local_version == '-':
|
if local_version is None:
|
||||||
color = Color.RED
|
color = Color.RED
|
||||||
elif local_version == remote_version:
|
elif local_version == remote_version:
|
||||||
color = Color.GREEN
|
color = Color.GREEN
|
||||||
@@ -290,7 +290,13 @@ class UpdateMenu(BaseMenu):
|
|||||||
return self.status_data[name]["installed"]
|
return self.status_data[name]["installed"]
|
||||||
|
|
||||||
def _is_update_available(self, name: str) -> bool:
|
def _is_update_available(self, name: str) -> bool:
|
||||||
return self.status_data[name]["local"] != self.status_data[name]["remote"]
|
local = self.status_data[name]["local"]
|
||||||
|
remote = self.status_data[name]["remote"]
|
||||||
|
|
||||||
|
if local is None or remote is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return local != remote
|
||||||
|
|
||||||
def _run_update_routine(self, name: str, update_fn: Callable, *args) -> None:
|
def _run_update_routine(self, name: str, update_fn: Callable, *args) -> None:
|
||||||
display_name = self.status_data[name]["display_name"]
|
display_name = self.status_data[name]["display_name"]
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class ComponentStatus:
|
|||||||
owner: str | None = None
|
owner: str | None = None
|
||||||
repo: str | None = None
|
repo: str | None = None
|
||||||
repo_url: str | None = None
|
repo_url: str | None = None
|
||||||
branch: str = ""
|
branch: str | None = None
|
||||||
local: str | None = None
|
local: str | None = None
|
||||||
remote: str | None = None
|
remote: str | None = None
|
||||||
instances: int | None = None
|
instances: int | None = None
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ def get_install_status(
|
|||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
|
|
||||||
checks = []
|
checks = []
|
||||||
branch: str = ""
|
branch: str | None = None
|
||||||
|
|
||||||
if repo_dir.exists():
|
if repo_dir.exists():
|
||||||
checks.append(True)
|
checks.append(True)
|
||||||
|
|||||||
@@ -73,44 +73,44 @@ def git_pull_wrapper(target_dir: Path) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_repo_name(repo: Path) -> Tuple[str, str]:
|
def get_repo_name(repo: Path) -> Tuple[str | None, str | None]:
|
||||||
"""
|
"""
|
||||||
Helper method to extract the organisation and name of a repository |
|
Helper method to extract the organisation and name of a repository |
|
||||||
:param repo: repository to extract the values from
|
:param repo: repository to extract the values from
|
||||||
:return: String in form of "<orga>/<name>" or None
|
:return: String in form of "<orga>/<name>" or None
|
||||||
"""
|
"""
|
||||||
if not repo.exists() or not repo.joinpath(".git").exists():
|
if not repo.exists() or not repo.joinpath(".git").exists():
|
||||||
return "-", "-"
|
return None, None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = ["git", "-C", repo.as_posix(), "config", "--get", "remote.origin.url"]
|
cmd = ["git", "-C", repo.as_posix(), "config", "--get", "remote.origin.url"]
|
||||||
result: str = check_output(cmd, stderr=DEVNULL).decode(encoding="utf-8")
|
result: str = check_output(cmd, stderr=DEVNULL).decode(encoding="utf-8")
|
||||||
substrings: List[str] = result.strip().split("/")[-2:]
|
substrings: List[str] = result.strip().split("/")[-2:]
|
||||||
|
|
||||||
orga: str = substrings[0] if substrings[0] else "-"
|
orga: str | None = substrings[0] if substrings[0] else None
|
||||||
name: str = substrings[1] if substrings[1] else "-"
|
name: str | None = substrings[1] if substrings[1] else None
|
||||||
|
|
||||||
return orga, name.replace(".git", "")
|
return orga, name.replace(".git", "") if name else None
|
||||||
|
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
return "-", "-"
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def get_current_branch(repo: Path) -> str:
|
def get_current_branch(repo: Path) -> str | None:
|
||||||
"""
|
"""
|
||||||
Get the current branch of a local Git repository
|
Get the current branch of a local Git repository
|
||||||
:param repo: Path to the local Git repository
|
:param repo: Path to the local Git repository
|
||||||
:return: Current branch
|
:return: Current branch or None if not determinable
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = ["git", "branch", "--show-current"]
|
cmd = ["git", "branch", "--show-current"]
|
||||||
result: str = check_output(cmd, stderr=DEVNULL, cwd=repo).decode(
|
result: str = check_output(cmd, stderr=DEVNULL, cwd=repo).decode(
|
||||||
encoding="utf-8"
|
encoding="utf-8"
|
||||||
)
|
)
|
||||||
return result.strip() if result else "-"
|
return result.strip() if result else None
|
||||||
|
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
return "-"
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||||
|
|||||||
Reference in New Issue
Block a user