diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h b/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h index e46e5b7f4028c8e36fa1ecc651a880e7da39eaa6..8addd56ba262084caa8b1405a18076ed67e21dbf 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h @@ -117,8 +117,12 @@ private: void setGlobalLocaleToAscii(); /// Silence NeXus output void disableNexusOutput(); + /// Starts asynchronous tasks that are done as part of Start-up + void AsynchronousStartupTasks(); /// Update instrument definitions from github void UpdateInstrumentDefinitions(); + ///check if a newer version of Mantid is available + void CheckIfNewerVersionIsAvailable(); /// Sends startup usage information void SendStartupUsageInfo(); diff --git a/Code/Mantid/Framework/API/src/FrameworkManager.cpp b/Code/Mantid/Framework/API/src/FrameworkManager.cpp index f7b731630eeb4ebae160c786e56073bba6fc0a8b..67c50618adaa6d2f2504d9fa3fd9c4c20e659499 100644 --- a/Code/Mantid/Framework/API/src/FrameworkManager.cpp +++ b/Code/Mantid/Framework/API/src/FrameworkManager.cpp @@ -82,24 +82,43 @@ FrameworkManagerImpl::FrameworkManagerImpl() g_log.debug() << "FrameworkManager created." << std::endl; + AsynchronousStartupTasks(); +} + +/// Destructor +FrameworkManagerImpl::~FrameworkManagerImpl() {} + +/// Starts asynchronous tasks that are done as part of Start-up. +void FrameworkManagerImpl::AsynchronousStartupTasks() +{ int updateInstrumentDefinitions = 0; int retVal = Kernel::ConfigService::Instance().getValue( - "UpdateInstrumentDefinitions.OnStartup", updateInstrumentDefinitions); + "UpdateInstrumentDefinitions.OnStartup", updateInstrumentDefinitions); if ((retVal == 1) && (updateInstrumentDefinitions == 1)) { UpdateInstrumentDefinitions(); } else { g_log.information() - << "Instrument updates disabled - cannot update instrument definitions." - << std::endl; + << "Instrument updates disabled - cannot update instrument definitions." + << std::endl; } + int checkIfNewerVersionIsAvailable= 0; + int retValVersionCheck = Kernel::ConfigService::Instance().getValue( + "CheckMantidVersion.OnStartup", checkIfNewerVersionIsAvailable); + if ((retValVersionCheck == 1) && (checkIfNewerVersionIsAvailable == 1)) { + CheckIfNewerVersionIsAvailable(); + } else { + g_log.information() + << "Version check disabled." + << std::endl; + } + + // the algorithm will see if it should run + SendStartupUsageInfo(); } -/// Destructor -FrameworkManagerImpl::~FrameworkManagerImpl() {} - /// Update instrument definitions from github void FrameworkManagerImpl::UpdateInstrumentDefinitions() { try { @@ -113,6 +132,20 @@ void FrameworkManagerImpl::UpdateInstrumentDefinitions() { } } + +/// Update instrument definitions from github +void FrameworkManagerImpl::CheckIfNewerVersionIsAvailable() { + try { + IAlgorithm *algCheckVersion = + this->createAlgorithm("CheckMantidVersion"); + algCheckVersion->setAlgStartupLogging(false); + Poco::ActiveResult<bool> result = algCheckVersion->executeAsync(); + } catch (Kernel::Exception::NotFoundError &) { + g_log.debug() << "CheckMantidVersion algorithm is not available - cannot " + "ucheck if a newer version is available." << std::endl; + } +} + /// Sends startup information about OS and Mantid version void FrameworkManagerImpl::SendStartupUsageInfo() { diff --git a/Code/Mantid/Framework/DataHandling/src/CheckMantidVersion.cpp b/Code/Mantid/Framework/DataHandling/src/CheckMantidVersion.cpp index 89c9946799b88f191a27959a4600d1ac23437107..0cb5b1da4ddc9ab0250e77c79e934fe46fdbd0ea 100644 --- a/Code/Mantid/Framework/DataHandling/src/CheckMantidVersion.cpp +++ b/Code/Mantid/Framework/DataHandling/src/CheckMantidVersion.cpp @@ -57,9 +57,9 @@ const std::string CheckMantidVersion::summary() const { /** Initialize the algorithm's properties. */ void CheckMantidVersion::init() { - declareProperty("CurrentVersion", "", Direction::Output); - declareProperty("MostRecentVersion", "", Direction::Output); - declareProperty("IsNewVersionAvailable", false, Direction::Output); + declareProperty("CurrentVersion", "", "The version string of the currently running version", Direction::Output); + declareProperty("MostRecentVersion", "", "The version string of most recent full or patch release available for download", Direction::Output); + declareProperty("IsNewVersionAvailable", false,"True if a newer version is available, otherwise false", Direction::Output); } //---------------------------------------------------------------------------------------------- @@ -82,17 +82,21 @@ void CheckMantidVersion::exec() { } std::string json = ""; + bool skipVersionCheck = false; try { json = getVersionsFromGitHub(gitHubReleaseUrl); } catch (Exception::InternetError &ex) { if (ex.errorCode() == InternetHelper::HTTP_NOT_MODIFIED) { // No changes since last release - mostRecentVersion = getCurrentVersion(); + //mostRecentVersion = getCurrentVersion(); + mostRecentVersion = "No new versions since " + + std::string(MantidVersion::releaseDate()); } else { throw; } } + bool isNewVersionAvailable = false; if (!json.empty()) { Json::Reader r; Json::Value root; @@ -100,17 +104,18 @@ void CheckMantidVersion::exec() { std::string gitHubVersionTag = root["tag_name"].asString(); mostRecentVersion = cleanVersionTag(gitHubVersionTag); - + + isNewVersionAvailable = isVersionMoreRecent(currentVersion, mostRecentVersion); + if (isNewVersionAvailable) { + // output a notice level log + g_log.notice("A new version of Mantid(" + mostRecentVersion + + ") is available for download from " + downloadUrl); + } } g_log.information("Current Mantid Version: " + currentVersion); g_log.information("Most Recent Mantid Version: " + mostRecentVersion); - bool isNewVersionAvailable = isVersionMoreRecent(currentVersion, mostRecentVersion); - if (isVersionMoreRecent(currentVersion, mostRecentVersion)) { - // output a notice level log - g_log.notice("A new version of Mantid(" + mostRecentVersion + - ") is available for download from " + downloadUrl); - } + setProperty("CurrentVersion", currentVersion); setProperty("MostRecentVersion", mostRecentVersion); setProperty("IsNewVersionAvailable", isNewVersionAvailable); diff --git a/Code/Mantid/Framework/Kernel/CMakeLists.txt b/Code/Mantid/Framework/Kernel/CMakeLists.txt index 277ca71f2b05cd685c8754dd910c04f07349f8a5..cf14f7859a9a3293ff60e2bcb60bd852b4828374 100644 --- a/Code/Mantid/Framework/Kernel/CMakeLists.txt +++ b/Code/Mantid/Framework/Kernel/CMakeLists.txt @@ -465,6 +465,7 @@ endif () set ( IGNORE_PARAVIEW "0" ) set ( QTPLUGINS "." ) set ( UPDATE_INSTRUMENT_DEFINTITIONS "0" ) +set ( CHECK_FOR_NEW_MANTID_VERSION "0" ) set ( ENABLE_USAGE_REPORTS "0" ) set ( PYTHONPLUGIN_DIRS "${MANTID_ROOT}/Framework/PythonInterface/plugins" ) set ( DATADIRS ${ExternalData_BINARY_ROOT}/Testing/Data/UnitTest;${ExternalData_BINARY_ROOT}/Testing/Data/DocTest;${MANTID_ROOT}/instrument ) @@ -543,6 +544,7 @@ endif () set ( PLUGINS ${MANTID_ROOT}/plugins ) set ( PYTHONPLUGIN_DIRS "${PLUGINS}/python" ) set ( UPDATE_INSTRUMENT_DEFINTITIONS "1" ) +set ( CHECK_FOR_NEW_MANTID_VERSION "1" ) set ( ENABLE_USAGE_REPORTS "1" ) set ( DATADIRS "" ) set ( MANTIDPUBLISHER "http://upload.mantidproject.org/scriptrepository/payload/publish" ) diff --git a/Code/Mantid/Framework/Properties/Mantid.properties.template b/Code/Mantid/Framework/Properties/Mantid.properties.template index b695b7886ece390966223e096d4ac0609432b3aa..e400eaa8e67d6cbea9e41f8b8abf44e097f517d7 100644 --- a/Code/Mantid/Framework/Properties/Mantid.properties.template +++ b/Code/Mantid/Framework/Properties/Mantid.properties.template @@ -42,6 +42,11 @@ instrumentDefinition.directory = @MANTID_ROOT@/instrument UpdateInstrumentDefinitions.OnStartup = @UPDATE_INSTRUMENT_DEFINTITIONS@ UpdateInstrumentDefinitions.URL = https://api.github.com/repos/mantidproject/mantid/contents/Code/Mantid/instrument +# Whether to check for newer mantid versions on startup +CheckMantidVersion.OnStartup = @CHECK_FOR_NEW_MANTID_VERSION@ +CheckMantidVersion.GitHubReleaseURL = https://api.github.com/repos/mantidproject/mantid/releases/latest +CheckMantidVersion.DownloadURL = http://download.mantidproject.org + # Whether to report usage statistics back to central server usagereports.enabled = @ENABLE_USAGE_REPORTS@ diff --git a/Code/Mantid/docs/source/algorithms/CheckMantidVersion-v1.rst b/Code/Mantid/docs/source/algorithms/CheckMantidVersion-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..a7d4fd663ccdd05ab28365174927e1e7ac13f77b --- /dev/null +++ b/Code/Mantid/docs/source/algorithms/CheckMantidVersion-v1.rst @@ -0,0 +1,49 @@ + +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +Checks if a new release of Mantid is available using the Github API for inspecting the most recent release. +In order to reduce API usage and optimise performance the request is sent with a "if-modified-since" header +with the date of the current release. + +This algorithm is run on asynchronously on start-up in release builds and official releases of Mantid. +It only outputs messages to the logs and outpus properties, it does not change anything else. + +If you want to disable the check on start-up add this to your mantid.user.properties file. + +``` + CheckMantidVersion.OnStartup = 0 +``` + +Usage +----- + +**Example - CheckMantidVersion** + +.. testcode:: CheckMantidVersionExample + + (current_version, most_recent_version, is_new_version_available)=CheckMantidVersion() + print "Current Version: " + current_version + print "Most Recent Version: " + most_recent_version + print "Is a newer version available? " + str(is_new_version_available) + +Output: + +.. testoutput:: CheckMantidVersionExample + :options: +ELLIPSIS, +NORMALIZE_WHITESPACE + + Current Version: ... + Most Recent Version: ... + Is a newer version available? ... + + +.. categories:: +