Skip to content

Replace usage of connection proxy with the requests library. #3552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_tools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ twisted
uncertainties
xhtml2pdf
zope
requests

# Alphabetized list of OS-specific packages
pywin32; platform_system == "Windows"
44 changes: 15 additions & 29 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
import os
import logging
import json
import webbrowser
import traceback

from typing import Optional, Dict
from pathlib import Path
from packaging.version import Version

from PySide6.QtWidgets import *
from PySide6.QtGui import *
Expand All @@ -19,8 +19,8 @@

from twisted.internet import reactor
# General SAS imports
from sas.qtgui.Utilities.ConnectionProxy import ConnectionProxy
from sas.qtgui.Utilities.SasviewLogger import setup_qt_logging
from sas.qtgui.Utilities.NewVersion.NewVersionAvailable import get_current_release_version

import sas.qtgui.Utilities.GuiUtils as GuiUtils

Expand Down Expand Up @@ -390,14 +390,14 @@ def showHelp(cls, url):
try:
# In order to have multiple help windows open simultaneously, we need to create a new class variable
# If we just reassign the old one, the old window will be destroyed

# Have we found a name not assigned to a window?
potential_help_window = getattr(cls, window_name, None)
potential_help_window = getattr(cls, window_name, None)
while potential_help_window and potential_help_window.isVisible():
window_name = f"help_window_{counter}"
potential_help_window = getattr(cls, window_name, None)
counter += 1

# Assign new variable to the GuiManager
setattr(cls, window_name, GuiUtils.showHelp(url_abs))

Expand Down Expand Up @@ -614,19 +614,10 @@ def checkUpdate(self):
A thread is started for the connecting with the server. The thread calls
a call-back method when the current version number has been obtained.
"""
version_info = {"version": "0.0.0"}
c = ConnectionProxy(web.update_url, config.UPDATE_TIMEOUT)
response = c.connect()
if response is None:
return
try:
content = response.read().strip()
logging.info("Connected to www.sasview.org. Latest version: %s"
% (content))
version_info = json.loads(content)
self.processVersion(version_info)
except ValueError as ex:
logging.info("Failed to connect to www.sasview.org:", ex)
latest_version = get_current_release_version()
if latest_version is None:
logging.info("Failed to connect to www.sasview.org:")
self.processVersion(latest_version)

def log_installed_packages(self):
"""
Expand All @@ -640,25 +631,20 @@ def log_imported_packages(self):
"""
PackageGatherer().log_imported_packages()

def processVersion(self, version_info):
def processVersion(self, version_info: tuple[str, str, Version]):
"""
Call-back method for the process of checking for updates.
This methods is called by a VersionThread object once the current
version number has been obtained. If the check is being done in the
background, the user will not be notified unless there's an update.

:param version: version string
:param version_str: version string
"""
version_str, download_url, _ = version_info
try:
version = version_info["version"]
if version == "0.0.0":
msg = "Could not connect to the application server."
msg += " Please try again later."
self.communicate.statusBarUpdateSignal.emit(msg)

elif version.__gt__(sas.system.version.__version__):
msg = "Version %s is available! " % str(version)
if "download_url" in version_info:
if version_str.__gt__(sas.system.version.__version__):
msg = "Version %s is available! " % str(version_info)
if download_url is not None:
webbrowser.open(version_info["download_url"])
else:
webbrowser.open(web.download_url)
Expand Down
158 changes: 0 additions & 158 deletions src/sas/qtgui/Utilities/ConnectionProxy.py

This file was deleted.

24 changes: 9 additions & 15 deletions src/sas/qtgui/Utilities/NewVersion/NewVersionAvailable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from copy import copy
from typing import Optional

import json
import requests
from packaging.version import Version, parse

from PySide6.QtCore import QSize
Expand All @@ -13,7 +13,6 @@
import logging

from sas import config
from sas.qtgui.Utilities.ConnectionProxy import ConnectionProxy
from sas.system import web

from sas.system.version import __version__ as current_version_string
Expand Down Expand Up @@ -81,28 +80,23 @@ def cancel(self):

def get_current_release_version() -> Optional[tuple[str, str, Version]]:
""" Get the current version from the server """

c = ConnectionProxy(web.update_url, config.UPDATE_TIMEOUT)
response = c.connect()

# Don't do anything if we can't reach the server
if response is None:
return None

try:
content = response.read().strip()
logger.info("Connected to www.sasview.org. Received: %s", content)

version_info = json.loads(content)
response = requests.get(web.update_url, timeout=config.UPDATE_TIMEOUT)
# Will throw Exception if the HTTP status code returned isn't success
# (2xx)
response.raise_for_status()
version_info = response.json()
logger.info("Connected to www.sasview.org. Received: %s", version_info)

version_string = version_info["version"]
url = version_info["download_url"]

return version_string, url, parse(version_string)


except Exception as ex:
logging.info("Failed to get version number %s", ex)
return None



def maybe_prompt_new_version_download() -> Optional[QDialog]:
Expand Down
Loading