Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions labctl/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,27 @@ def put(self, path: str, data: dict = {}, json: dict = {}, additional_headers: d
if json:
return requests.put(self.api_url + path, headers=headers, json=json)
return requests.put(self.api_url + path, headers=headers)

@staticmethod
def get_latest_version() -> str | None:
"""
Get the latest version of labctl from pypi or github
Returns None if both github and pypi requests fail
"""
print("Checking for updates")
try:
return get_latest_version_from_github()
except Exception:
print("Failed to get version from github")
pass
try:
return get_latest_version_from_pypi()
except Exception:
print("Failed to get version from pypi")
return None

def get_latest_version_from_pypi() -> str:
return requests.get("https://pypi.org/pypi/labctl/json", timeout=5).json()["info"]["version"]

def get_latest_version_from_github() -> str:
return requests.get("https://api.github.com/repos/laboinfra/labctl/releases/latest", timeout=5).json()["tag_name"]
16 changes: 16 additions & 0 deletions labctl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,26 @@ def version():
"""
Print the version
"""
latest_version = APIDriver.get_latest_version()
version = __version__
dev_version = False
if version == "0.0.0":
version = "dev or installed from source"
dev_version = True
console.print(f"labctl version: {version} :rocket:")
if not latest_version:
latest_version = "Could not fetch latest version"
console.print(f"Latest version: {latest_version}")
return
# remove v prefix
if version != latest_version.replace("v", "") and not dev_version:
console.print(f"[red]:warning: Your version is outdated :warning:[/red]")
console.print(f"Latest version: [green]{latest_version.replace('v', '')}[/green]")
console.print(f"Your version: [red]{version}[/red]")
console.print(f"Please update your client to avoid issues")
if dev_version:
console.print(f"Dev version has no check intgration for updates please check manually")
console.print(f"https://github.com/laboinfra/labctl/releases")

@app.command()
@cli_ready
Expand Down
Loading