forked from openlp/openlp
handle the version from the web site
This commit is contained in:
parent
da51b046b2
commit
be145b7675
@ -153,10 +153,8 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication):
|
|||||||
self.processEvents()
|
self.processEvents()
|
||||||
if not has_run_wizard:
|
if not has_run_wizard:
|
||||||
self.main_window.first_time()
|
self.main_window.first_time()
|
||||||
# update_check = Settings().value('core/update check')
|
version = VersionThread(self.main_window)
|
||||||
# if update_check:
|
version.start()
|
||||||
# version = VersionThread(self.main_window)
|
|
||||||
# version.start()
|
|
||||||
self.main_window.is_display_blank()
|
self.main_window.is_display_blank()
|
||||||
self.main_window.app_startup()
|
self.main_window.app_startup()
|
||||||
return self.exec()
|
return self.exec()
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
from PyQt5 import QtCore, QtGui, QtNetwork, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtNetwork, QtWidgets
|
||||||
|
|
||||||
from openlp.core.common import UiStrings, Settings, translate
|
from openlp.core.common import UiStrings, Registry, Settings, translate
|
||||||
from openlp.core.lib import SettingsTab
|
from openlp.core.lib import SettingsTab
|
||||||
|
|
||||||
ZERO_URL = '0.0.0.0'
|
ZERO_URL = '0.0.0.0'
|
||||||
@ -38,6 +38,7 @@ class ApiTab(SettingsTab):
|
|||||||
super(ApiTab, self).__init__(parent, 'api', advanced_translated)
|
super(ApiTab, self).__init__(parent, 'api', advanced_translated)
|
||||||
self.define_main_window_icon()
|
self.define_main_window_icon()
|
||||||
self.generate_icon()
|
self.generate_icon()
|
||||||
|
Registry().register_function('set_website_version', self.set_website_version)
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
self.setObjectName('ApiTab')
|
self.setObjectName('ApiTab')
|
||||||
@ -93,7 +94,6 @@ class ApiTab(SettingsTab):
|
|||||||
self.user_login_group_box.setCheckable(True)
|
self.user_login_group_box.setCheckable(True)
|
||||||
self.user_login_group_box.setChecked(False)
|
self.user_login_group_box.setChecked(False)
|
||||||
self.user_login_group_box.setObjectName('user_login_group_box')
|
self.user_login_group_box.setObjectName('user_login_group_box')
|
||||||
|
|
||||||
self.user_login_layout = QtWidgets.QFormLayout(self.user_login_group_box)
|
self.user_login_layout = QtWidgets.QFormLayout(self.user_login_group_box)
|
||||||
self.user_login_layout.setObjectName('user_login_layout')
|
self.user_login_layout.setObjectName('user_login_layout')
|
||||||
self.user_id_label = QtWidgets.QLabel(self.user_login_group_box)
|
self.user_id_label = QtWidgets.QLabel(self.user_login_group_box)
|
||||||
@ -180,7 +180,6 @@ class ApiTab(SettingsTab):
|
|||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.tab_title_visible = translate('RemotePlugin.RemoteTab', 'Remote Interface')
|
self.tab_title_visible = translate('RemotePlugin.RemoteTab', 'Remote Interface')
|
||||||
|
|
||||||
self.server_settings_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'Server Settings'))
|
self.server_settings_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'Server Settings'))
|
||||||
self.address_label.setText(translate('RemotePlugin.RemoteTab', 'Serve on IP address:'))
|
self.address_label.setText(translate('RemotePlugin.RemoteTab', 'Serve on IP address:'))
|
||||||
self.port_label.setText(translate('RemotePlugin.RemoteTab', 'Port number:'))
|
self.port_label.setText(translate('RemotePlugin.RemoteTab', 'Port number:'))
|
||||||
@ -306,3 +305,12 @@ class ApiTab(SettingsTab):
|
|||||||
painter.end()
|
painter.end()
|
||||||
self.remote_server_icon.setPixmap(QtGui.QPixmap.fromImage(icon))
|
self.remote_server_icon.setPixmap(QtGui.QPixmap.fromImage(icon))
|
||||||
self.remote_server_icon.show()
|
self.remote_server_icon.show()
|
||||||
|
|
||||||
|
def set_website_version(self):
|
||||||
|
"""
|
||||||
|
Update the website version when it has been downloaded
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
self.master_version_value.setText(Registry().get_flag('website_version'))
|
||||||
|
if self.master_version_value.text() == self.current_version_value.text():
|
||||||
|
self.update_site_group_box.setEnabled(False)
|
||||||
|
@ -25,8 +25,10 @@ The :mod:`openlp.core.utils` module provides the utility libraries for OpenLP.
|
|||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@ -254,4 +256,17 @@ def url_get_file(callback, url, f_path, sha256=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def ping(host):
|
||||||
|
"""
|
||||||
|
Returns True if host responds to a ping request
|
||||||
|
"""
|
||||||
|
# Ping parameters as function of OS
|
||||||
|
ping_str = "-n 1" if platform.system().lower()=="windows" else "-c 1"
|
||||||
|
args = "ping " + " " + ping_str + " " + host
|
||||||
|
need_sh = False if platform.system().lower()=="windows" else True
|
||||||
|
|
||||||
|
# Ping
|
||||||
|
return subprocess.call(args, shell=need_sh) == 0
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['get_web_page']
|
__all__ = ['get_web_page']
|
||||||
|
@ -12,7 +12,8 @@ from subprocess import Popen, PIPE
|
|||||||
|
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
|
|
||||||
from openlp.core.common import AppLocation, Settings
|
from openlp.core.common import AppLocation, Registry, Settings
|
||||||
|
from openlp.core.common.httputils import ping
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -42,6 +43,12 @@ class VersionThread(QtCore.QThread):
|
|||||||
"""
|
"""
|
||||||
self.sleep(1)
|
self.sleep(1)
|
||||||
log.debug('Version thread - run')
|
log.debug('Version thread - run')
|
||||||
|
found = ping("openlp.io")
|
||||||
|
Registry().set_flag('internet_present', found)
|
||||||
|
update_check = Settings().value('core/update check')
|
||||||
|
if found:
|
||||||
|
Registry().execute('get_website_version')
|
||||||
|
if update_check:
|
||||||
app_version = get_application_version()
|
app_version = get_application_version()
|
||||||
version = check_latest_version(app_version)
|
version = check_latest_version(app_version)
|
||||||
log.debug("Versions {version1} and {version2} ".format(version1=LooseVersion(str(version)),
|
log.debug("Versions {version1} and {version2} ".format(version1=LooseVersion(str(version)),
|
||||||
|
@ -27,7 +27,7 @@ from openlp.core.api.http import register_endpoint
|
|||||||
from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists
|
from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists
|
||||||
from openlp.core.lib import Plugin, StringContent, translate, build_icon
|
from openlp.core.lib import Plugin, StringContent, translate, build_icon
|
||||||
from openlp.plugins.remotes.endpoint import remote_endpoint
|
from openlp.plugins.remotes.endpoint import remote_endpoint
|
||||||
from openlp.plugins.remotes.deploy import download_and_check
|
from openlp.plugins.remotes.deploy import download_and_check, download_sha256
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
__default_settings__ = {
|
__default_settings__ = {
|
||||||
@ -48,6 +48,8 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
|||||||
self.weight = -1
|
self.weight = -1
|
||||||
register_endpoint(remote_endpoint)
|
register_endpoint(remote_endpoint)
|
||||||
Registry().register_function('download_website', self.first_time)
|
Registry().register_function('download_website', self.first_time)
|
||||||
|
Registry().register_function('get_website_version', self.website_version)
|
||||||
|
Registry().set_flag('website_version', '0001_01_01')
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
"""
|
"""
|
||||||
@ -91,3 +93,13 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
|||||||
self.application.process_events()
|
self.application.process_events()
|
||||||
download_and_check()
|
download_and_check()
|
||||||
self.application.process_events()
|
self.application.process_events()
|
||||||
|
|
||||||
|
def website_version(self):
|
||||||
|
"""
|
||||||
|
Download and save the website version and sha256
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
sha256, version = download_sha256()
|
||||||
|
Registry().set_flag('website_sha256', sha256)
|
||||||
|
Registry().set_flag('website_version', version)
|
||||||
|
Registry().execute('set_website_version')
|
||||||
|
@ -28,7 +28,7 @@ import socket
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from openlp.core.common.httputils import get_user_agent, get_web_page, get_url_file_size, url_get_file
|
from openlp.core.common.httputils import get_user_agent, get_web_page, get_url_file_size, url_get_file, ping
|
||||||
|
|
||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
@ -272,3 +272,29 @@ class TestHttpUtils(TestCase, TestMixin):
|
|||||||
# THEN: socket.timeout should have been caught
|
# THEN: socket.timeout should have been caught
|
||||||
# NOTE: Test is if $tmpdir/tempfile is still there, then test fails since ftw deletes bad downloaded files
|
# NOTE: Test is if $tmpdir/tempfile is still there, then test fails since ftw deletes bad downloaded files
|
||||||
self.assertFalse(os.path.exists(self.tempfile), 'FTW url_get_file should have caught socket.timeout')
|
self.assertFalse(os.path.exists(self.tempfile), 'FTW url_get_file should have caught socket.timeout')
|
||||||
|
|
||||||
|
def test_ping_valid(self):
|
||||||
|
"""
|
||||||
|
Test ping for OpenLP
|
||||||
|
"""
|
||||||
|
# GIVEN: a valid url to test
|
||||||
|
url = "openlp.io"
|
||||||
|
|
||||||
|
# WHEN: Attempt to check the url exists
|
||||||
|
url_found = ping(url)
|
||||||
|
|
||||||
|
# THEN: It should be found
|
||||||
|
self.assertTrue(url_found, 'OpenLP.io is not found')
|
||||||
|
|
||||||
|
def test_ping_invalid(self):
|
||||||
|
"""
|
||||||
|
Test ping for OpenLP
|
||||||
|
"""
|
||||||
|
# GIVEN: a valid url to test
|
||||||
|
url = "trb143.io"
|
||||||
|
|
||||||
|
# WHEN: Attempt to check the url exists
|
||||||
|
url_found = ping(url)
|
||||||
|
|
||||||
|
# THEN: It should be found
|
||||||
|
self.assertFalse(url_found, 'TRB143.io is found')
|
||||||
|
Loading…
Reference in New Issue
Block a user