Commit d33cb9f9 authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] #813 fix About Sakia available release search code

Search on git.duniter.org, can be set in constants.py
parent 9213934b
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -21,7 +21,8 @@ from PyQt5.QtCore import (
QFile,
)
from . import __version__
from .options import SakiaOptions
from sakia.constants import GITLAB_RELEASES_API_URL, GITLAB_RELEASES_PAGE_URL
from sakia.options import SakiaOptions
from sakia.data.connectors import BmaConnector
from sakia.services import (
NetworkService,
......@@ -309,40 +310,30 @@ class Application(QObject):
async with aiohttp.ClientSession() as session:
async with async_timeout.timeout(10):
response = await session.get(
"https://api.github.com/repos/duniter/sakia/releases",
GITLAB_RELEASES_API_URL,
proxy=self.parameters.proxy(),
)
if response.status == 200:
releases = await response.json()
latest = None
for r in releases:
if not latest:
latest = r
else:
latest_date = datetime.datetime.strptime(
latest["published_at"], "%Y-%m-%dT%H:%M:%SZ"
)
date = datetime.datetime.strptime(
r["published_at"], "%Y-%m-%dT%H:%M:%SZ"
)
if latest_date < date:
latest = r
latest_version = latest["tag_name"]
version = (
__version__ == latest_version,
latest_version,
latest["html_url"],
)
logging.debug("Found version: {0}".format(latest_version))
logging.debug("Current version: {0}".format(__version__))
self.available_version = version
if len(releases) > 0:
release = releases[0]
latest_version = release["tag_name"]
version = (
__version__ == latest_version,
latest_version,
GITLAB_RELEASES_PAGE_URL,
)
logging.debug("Found version: {0}".format(latest_version))
logging.debug("Current version: {0}".format(__version__))
self.available_version = version
except (
aiohttp.ClientError,
aiohttp.ServerDisconnectedError,
asyncio.TimeoutError,
socket.gaierror,
) as e:
self._logger.debug("Could not connect to github: {0}".format(str(e)))
self._logger.debug("Could not connect to gitlab: {0}".format(str(e)))
def save_parameters(self, parameters):
self.parameters = UserParametersFile.in_config_path(
......
......@@ -6,3 +6,8 @@ with open(
os.path.join(os.path.dirname(__file__), "g1_license.html"), "r", encoding="utf-8"
) as stream:
G1_LICENSE = stream.read()
GITLAB_RELEASES_PAGE_URL = "https://git.duniter.org/clients/python/sakia/-/releases"
GITLAB_RELEASES_API_URL = (
"https://git.duniter.org/api/v4/projects/clients%2Fpython%2Fsakia/releases"
)
from PyQt5.QtCore import QObject, QLocale, QDateTime
from PyQt5.QtCore import QObject, QLocale, QDateTime, QCoreApplication
from sakia.data.processors import ConnectionsProcessor
import attr
import math
......@@ -37,15 +37,18 @@ class ToolbarModel(QObject):
latest = self.app.available_version
version_info = ""
version_url = ""
url_text = ""
if not latest[0]:
version_info = "Latest release: {version}".format(version=latest[1])
version_url = latest[2]
url_text = QCoreApplication.translate("ToolbarView", "Download page")
new_version_text = """
<p><b>{version_info}</b></p>
<p><a href={version_url}>Download link</a></p>
<p><a href={version_url}>{url_text}</a></p>
""".format(
version_info=version_info, version_url=version_url
version_info=version_info, version_url=version_url, url_text=url_text
)
return """
<h1>Sakia</h1>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment