Skip to content

Commit

Permalink
notify user if old pre-built WRF/WPS distributions are used (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
letmaik authored Sep 24, 2018
1 parent 8381f85 commit d2fb905
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions gis4wrf/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
44 changes: 41 additions & 3 deletions gis4wrf/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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'<html>Pre-built WRF/WPS {WRF_WPS_DIST_VERSION} distributions are available. ' +
f'You are currently using version {old_found}. Please update. '
'See the <a href="https://gis4wrf.github.io/configuration/">online documentation</a> for details.</html>',
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,
Expand Down

0 comments on commit d2fb905

Please sign in to comment.