Skip to content

Commit

Permalink
integrated into mantid startup for release builds
Browse files Browse the repository at this point in the history
Also added docs, and neatened things up a bit.
Improved handling of if-modified-since returns.
re #12064
  • Loading branch information
NickDraper committed Jul 6, 2015
1 parent 9c99ecf commit f2f8fef
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
Expand Up @@ -117,8 +117,12 @@ class MANTID_API_DLL FrameworkManagerImpl {
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();

Expand Down
45 changes: 39 additions & 6 deletions Code/Mantid/Framework/API/src/FrameworkManager.cpp
Expand Up @@ -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 {
Expand All @@ -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()
{
Expand Down
27 changes: 16 additions & 11 deletions Code/Mantid/Framework/DataHandling/src/CheckMantidVersion.cpp
Expand Up @@ -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);
}

//----------------------------------------------------------------------------------------------
Expand All @@ -82,35 +82,40 @@ 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;
r.parse(json, root);

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);
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Kernel/CMakeLists.txt
Expand Up @@ -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 )
Expand Down Expand Up @@ -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" )
Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/Properties/Mantid.properties.template
Expand Up @@ -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@

Expand Down
49 changes: 49 additions & 0 deletions 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::

0 comments on commit f2f8fef

Please sign in to comment.