Clarify local provider update status

This commit is contained in:
Dymas
2026-09-01 13:00:18 +02:00
parent 07f73ea340
commit 97646d1382
6 changed files with 70 additions and 12 deletions
+41 -10
View File
@@ -4,6 +4,7 @@
import hashlib
import json
import re
import urllib.error
import urllib.request
from datetime import datetime, timezone
@@ -36,6 +37,7 @@ def default_status(status="idle", message="Provider update check has not run yet
"upstream_tree_sha": "",
"checked_files": 0,
"updated_files": [],
"locally_modified_files": [],
"missing_upstream_files": [],
}
@@ -55,6 +57,25 @@ def sha256_bytes(content):
return hashlib.sha256(content).hexdigest()
def provider_module_version(content):
match = re.search(rb'version:\s*["\']([^"\']+)["\']', content)
if not match:
return ""
return match.group(1).decode("utf-8", errors="replace")
def compare_versions(left, right):
left_parts = [int(part) for part in re.findall(r"\d+", left or "")]
right_parts = [int(part) for part in re.findall(r"\d+", right or "")]
length = max(len(left_parts), len(right_parts))
for index in range(length):
left_value = left_parts[index] if index < len(left_parts) else 0
right_value = right_parts[index] if index < len(right_parts) else 0
if left_value != right_value:
return 1 if left_value > right_value else -1
return 0
def fetch_json(url, timeout=10):
request = urllib.request.Request(
url,
@@ -100,6 +121,7 @@ def check_provider_updates(local_root=LOCAL_PROVIDER_ROOT, timeout=10):
upstream_paths, upstream_tree_sha = upstream_provider_js_paths(timeout=timeout)
updated_files = []
locally_modified_files = []
missing_upstream_files = []
checked_files = 0
@@ -114,19 +136,27 @@ def check_provider_updates(local_root=LOCAL_PROVIDER_ROOT, timeout=10):
local_hash = sha256_bytes(local_content)
remote_hash = sha256_bytes(remote_content)
if local_hash != remote_hash:
updated_files.append(
{
"path": relative_path,
"local_sha256": local_hash,
"upstream_sha256": remote_hash,
"upstream_url": remote_url,
}
)
local_version = provider_module_version(local_content)
upstream_version = provider_module_version(remote_content)
item = {
"path": relative_path,
"local_sha256": local_hash,
"upstream_sha256": remote_hash,
"upstream_url": remote_url,
"local_version": local_version,
"upstream_version": upstream_version,
}
if local_version and upstream_version and compare_versions(local_version, upstream_version) > 0:
locally_modified_files.append(item)
else:
updated_files.append(item)
has_updates = bool(updated_files or missing_upstream_files)
if has_updates:
if updated_files or missing_upstream_files:
message = "Provider updates are available from TheYogMehta/extensions."
status_name = "updates_available"
elif locally_modified_files:
message = "Bundled provider JavaScript includes local changes ahead of upstream."
status_name = "local_changes"
else:
message = "Bundled provider JavaScript is up to date."
status_name = "up_to_date"
@@ -140,6 +170,7 @@ def check_provider_updates(local_root=LOCAL_PROVIDER_ROOT, timeout=10):
"upstream_tree_sha": upstream_tree_sha,
"checked_files": checked_files,
"updated_files": updated_files,
"locally_modified_files": locally_modified_files,
"missing_upstream_files": missing_upstream_files,
}