Modernize runtime compatibility and initialize Bearhub fork

This commit is contained in:
Sebastian Palencsar
2026-05-26 08:35:29 +02:00
parent b1ea479a3a
commit d541a4cbcf
23 changed files with 132 additions and 96 deletions

View File

@@ -3,7 +3,7 @@ import os
import re
import traceback
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from json import JSONDecodeError
from logging import Logger
from pathlib import Path
@@ -52,14 +52,14 @@ class ApplicationIndexer:
return True
try:
timestamp = datetime.fromtimestamp(float(timestamp_str))
timestamp = datetime.fromtimestamp(float(timestamp_str), tz=timezone.utc)
except Exception:
self._log.error(f'Could not parse the Debian applications index timestamp: {timestamp_str} '
f'({self._file_timestamp_path})')
traceback.print_exc()
return True
expired = timestamp + timedelta(minutes=exp_minutes) <= datetime.utcnow()
expired = timestamp + timedelta(minutes=exp_minutes) <= datetime.now(timezone.utc)
if expired:
self._log.info("Debian applications index has expired. A new one must be generated.")
@@ -122,7 +122,7 @@ class ApplicationIndexer:
raise ApplicationIndexError()
if update_timestamp:
index_timestamp = datetime.utcnow().timestamp()
index_timestamp = datetime.now(timezone.utc).timestamp()
try:
with open(self._file_timestamp_path, 'w+') as f:
f.write(str(index_timestamp))
@@ -140,7 +140,7 @@ class ApplicationsMapper:
def __init__(self, logger: Logger, workers: int = 10):
self._log = logger
self._re_desktop_file = re.compile(r'(.+):\s+(/usr/share/applications/.+\.desktop)')
self._re_desktop_file_fields = re.compile('(Exec|TryExec|Icon|Categories|NoDisplay|Terminal)\s*=\s*(.+)')
self._re_desktop_file_fields = re.compile(r'(Exec|TryExec|Icon|Categories|NoDisplay|Terminal)\s*=\s*(.+)')
self._workers = workers
def _read_file(self, file_path: str) -> Optional[str]:

View File

@@ -1,6 +1,6 @@
import os
import traceback
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from logging import Logger
from pathlib import Path
from threading import Thread
@@ -95,13 +95,13 @@ class DebianSuggestionsDownloader(Thread):
timestamp_str = f.read()
try:
suggestions_timestamp = datetime.fromtimestamp(float(timestamp_str))
suggestions_timestamp = datetime.fromtimestamp(float(timestamp_str), tz=timezone.utc)
except Exception:
self._log.error(f'Could not parse the Debian cached suggestions timestamp: {timestamp_str}')
traceback.print_exc()
return True
update = suggestions_timestamp + timedelta(hours=exp_hours) <= datetime.utcnow()
update = suggestions_timestamp + timedelta(hours=exp_hours) <= datetime.now(timezone.utc)
return update
def _save(self, text: str, timestamp: float):
@@ -184,7 +184,7 @@ class DebianSuggestionsDownloader(Thread):
suggestions = parse(res.text, self._log, 'Debian')
if suggestions:
self._save(text=res.text, timestamp=datetime.utcnow().timestamp())
self._save(text=res.text, timestamp=datetime.now(timezone.utc).timestamp())
else:
self._log.warning("No Debian suggestions to cache")
else:

View File

@@ -1,6 +1,6 @@
import time
import traceback
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from logging import Logger
from threading import Thread
from typing import Optional, Set
@@ -149,14 +149,14 @@ class SynchronizePackages(Thread):
return True
try:
last_timestamp = datetime.fromtimestamp(float(timestamp_str))
last_timestamp = datetime.fromtimestamp(float(timestamp_str), tz=timezone.utc)
except Exception:
logger.error(f'Could not parse the packages synchronization timestamp: {timestamp_str} '
f'({PACKAGE_SYNC_TIMESTAMP_FILE})')
traceback.print_exc()
return True
expired = last_timestamp + timedelta(minutes=period) <= datetime.utcnow()
expired = last_timestamp + timedelta(minutes=period) <= datetime.now(timezone.utc)
if expired:
logger.info("Packages synchronization is outdated")
@@ -176,7 +176,7 @@ class SynchronizePackages(Thread):
self._taskman.update_progress(self._id, 99, None)
if updated:
index_timestamp = datetime.utcnow().timestamp()
index_timestamp = datetime.now(timezone.utc).timestamp()
finish_msg = None
try:
with open(PACKAGE_SYNC_TIMESTAMP_FILE, 'w+') as f: