Skip to content

Commit

Permalink
fix: 🚑 software lifecycle issue
Browse files Browse the repository at this point in the history
  • Loading branch information
realashleybailey committed Nov 17, 2023
1 parent ed1cee8 commit ac55841
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
3 changes: 2 additions & 1 deletion apps/wizarr-backend/wizarr_backend/api/routes/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_restx import Namespace, Resource
from playhouse.shortcuts import model_to_dict

from app.utils.software_lifecycle import get_current_version, need_update, get_latest_version, get_latest_beta_version
from app.utils.software_lifecycle import is_beta, get_current_version, need_update, get_latest_version, get_latest_beta_version
from app.extensions import cache

from json import loads, dumps
Expand All @@ -29,6 +29,7 @@ def get(self):
"update_available": need_update(),
"debug": True if app.debug else False,
"setup_required": is_setup_required(),
"is_beta": is_beta(),
"latest_version": str(get_latest_version()),
"latest_beta_version": str(get_latest_beta_version()),
}
Expand Down
50 changes: 26 additions & 24 deletions apps/wizarr-backend/wizarr_backend/app/utils/software_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,55 @@
from os import path
from json import load
from definitions import LATEST_FILE, DATABASE_DIR
from re import search

session = CachedSession(cache_name=path.join(DATABASE_DIR, "wizarr_cache"), backend="sqlite", expire_after=3600, cache_control=True, stale_if_error=True, allowable_codes=[200])

def compare_versions(version1, version2):
return parse(str(version1)) > parse(str(version2))

def get_latest_version():
try:
url = "https://api.github.com/repos/wizarrrr/wizarr/releases/latest"
url = "https://api.github.com/repos/wizarrrr/wizarr/tags"
response = session.get(url, timeout=5)
if response.status_code != 200:
return None
release = response.json()
latest = release["tag_name"]
return str(latest)
if response.status_code != 200: return None
latest = None
for tag in response.json():
if latest is None or compare_versions(tag["name"], latest):
if "beta" not in tag["name"]:
latest = tag["name"]
return parse(str(latest))
except Exception:
return None

def get_latest_beta_version():
try:
url = "https://api.github.com/repos/wizarrrr/wizarr/releases"
url = "https://api.github.com/repos/wizarrrr/wizarr/tags"
response = session.get(url, timeout=5)
if response.status_code != 200:
return None
releases = response.json()
latest_beta = str([release["tag_name"] for release in releases if release["prerelease"] and "beta" in release["tag_name"]][0])

# TEMPORARY FIX: Remove -v3 from the version
latest_beta = latest_beta.replace("-v3", "")

return parse(latest_beta)
if response.status_code != 200: return None
latest_beta = None
for tag in response.json():
if latest_beta is None or compare_versions(tag["name"], latest_beta):
if "beta" in tag["name"]:
latest_beta = tag["name"]
return parse(str(latest_beta))
except Exception:
return None

def get_current_version():
with open(LATEST_FILE, "r", encoding="utf-8") as f:
current_version = str(f.read())

# TEMPORARY FIX: Remove -v3 from the version
current_version = current_version.replace("-v3", "")

return parse(current_version)

def compare_versions(version1, version2):
return parse(str(version1)) > parse(str(version2))

def is_beta():
return "beta" in str(get_current_version())
return search(r"\d\.\d\.\d\w\d", str(get_current_version())) is not None

def is_latest():
print(get_current_version(), is_beta(), get_latest_beta_version(), get_latest_version())
print(compare_versions(get_current_version(), is_beta() and get_latest_beta_version() or get_latest_version()))
print(str(get_current_version()) == str(is_beta() and get_latest_beta_version() or get_latest_version()))
if str(get_current_version()) == str(is_beta() and get_latest_beta_version() or get_latest_version()):
return True
return compare_versions(get_current_version(), is_beta() and get_latest_beta_version() or get_latest_version())

def is_stable():
Expand Down

0 comments on commit ac55841

Please sign in to comment.