From d2fb905455abc34be0cf3c1d9363ae9251149538 Mon Sep 17 00:00:00 2001 From: Maik Riechert Date: Mon, 24 Sep 2018 08:13:52 +0100 Subject: [PATCH] notify user if old pre-built WRF/WPS distributions are used (#50) --- gis4wrf/core/constants.py | 1 + gis4wrf/plugin/plugin.py | 44 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/gis4wrf/core/constants.py b/gis4wrf/core/constants.py index ef0eb9c..e16fad9 100644 --- a/gis4wrf/core/constants.py +++ b/gis4wrf/core/constants.py @@ -17,6 +17,7 @@ class ProjectionTypes(object): MERCATOR = 3 LAT_LON = 6 +WRF_WPS_DIST_OLD_VERSIONS = ['3.9'] WRF_WPS_DIST_VERSION = '4.0' WRF_DIST = { diff --git a/gis4wrf/plugin/plugin.py b/gis4wrf/plugin/plugin.py index 76f3d3e..86cea2b 100644 --- a/gis4wrf/plugin/plugin.py +++ b/gis4wrf/plugin/plugin.py @@ -2,6 +2,7 @@ # Copyright (c) 2018 D. Meyer and M. Riechert. Licensed under MIT. from typing import List, Callable +import os import webbrowser import time import logging @@ -15,7 +16,7 @@ from gis4wrf.core import ( get_latest_gis4wrf_version, get_installed_gis4wrf_version, is_newer_version, - logger) + WRF_WPS_DIST_VERSION, WRF_WPS_DIST_OLD_VERSIONS, logger) # Initialize Qt resources from auto-generated file resources.py import gis4wrf.plugin.resources @@ -27,6 +28,7 @@ from gis4wrf.plugin.ui.dock import MainDock from gis4wrf.plugin.ui.dialog_about import AboutDialog +from gis4wrf.plugin.options import get_options from gis4wrf.plugin.geo import add_default_basemap, load_wps_binary_layer from gis4wrf.plugin.constants import ( PLUGIN_NAME, GIS4WRF_LOGO_PATH, ADD_WRF_NETCDF_LAYER_ICON_PATH, @@ -60,8 +62,9 @@ def initGui(self) -> None: self.options_factory = OptionsFactory() self.iface.registerOptionsWidgetFactory(self.options_factory) + self.options = get_options() - self.check_version() + self.check_versions() def unload(self) -> None: """Removes the plugin menu item and icon from QGIS GUI. @@ -126,7 +129,11 @@ def emit(self, record: logging.LogRecord) -> None: def destroy_logging(self) -> None: logger.removeHandler(self.log_handler) - def check_version(self) -> None: + def check_versions(self) -> None: + self.check_plugin_version() + self.check_prebuilt_distribution_version() + + def check_plugin_version(self) -> None: def get_latest_delayed() -> str: # When QGIS is started, display messages after QGIS # is fully loaded by waiting for 2 mins as plugins @@ -145,6 +152,37 @@ def on_succeeded(latest: str) -> None: thread.succeeded.connect(on_succeeded) thread.start() + def check_prebuilt_distribution_version(self) -> None: + def delayed() -> None: + # See check_plugin_version(). + time.sleep(120) + + variants = ['nompi', 'mpi'] + + def on_succeeded() -> None: + dist_root_dir = os.path.normpath(self.options.distributions_dir) + old_found = None + for dist_name, current_dir in [('WPS', self.options.wps_dir), ('WRF', self.options.wrf_dir)]: + if current_dir is None: + continue + for old_version in WRF_WPS_DIST_OLD_VERSIONS: + for variant in variants: + # We assume that a match of this folder path would only happen + # if the user downloaded a pre-built distribution via the settings interface. + old_dir = os.path.join(dist_root_dir, f'{dist_name}-{old_version}-{variant}') + if os.path.normpath(old_dir) == os.path.normpath(current_dir): + old_found = old_version + if old_found: + QMessageBox.information(self.iface.mainWindow(), PLUGIN_NAME, + f'Pre-built WRF/WPS {WRF_WPS_DIST_VERSION} distributions are available. ' + + f'You are currently using version {old_found}. Please update. ' + 'See the online documentation for details.', + QMessageBox.Ok) + + thread = TaskThread(delayed) + thread.succeeded.connect(on_succeeded) + thread.start() + def add_action(self, icon_path: str, text: str, callback: Callable, enabled_flag: bool=True, add_to_menu: bool=True, add_to_toolbar: bool=False, add_to_add_layer: bool=False,