[rkward-cvs] SF.net SVN: rkward-code:[4516] trunk/rkward

tfry at users.sf.net tfry at users.sf.net
Mon Jan 28 11:10:52 UTC 2013


Revision: 4516
          http://sourceforge.net/p/rkward/code/4516
Author:   tfry
Date:     2013-01-28 11:10:50 +0000 (Mon, 28 Jan 2013)
Log Message:
-----------
Add special property for checking R / RKWard version requirements, dynamically.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugin/rkcomponentmeta.cpp
    trunk/rkward/rkward/plugin/rkcomponentmeta.h
    trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
    trunk/rkward/rkward/plugins/00saveload/save/save.rkh
    trunk/rkward/rkward/plugins/00saveload/save/save.xml
    trunk/rkward/rkward/plugins/import_export.pluginmap
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rksessionvars.cpp
    trunk/rkward/rkward/rbackend/rksessionvars.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/ChangeLog	2013-01-28 11:10:50 UTC (rev 4516)
@@ -1,3 +1,5 @@
+- Added new element <dependency_check> for dynamic version checks within a plugin (R and RKWard versions, only, so far)
+	- TODO: document, test
 - Add guard against accidental usage of the standard distributed pluginmaps in a later version of RKWard (installed in parallel)
 - Easier (de-)activation of RKWard plugin maps using checkboxes (Settings->Configure RKWard->Plugins)
 - Broken or quirky .pluginmap files are reported to the user, and disables completely broken maps, automatically
@@ -4,9 +6,8 @@
 - Implement basic dependency handling for plugins / pluginmaps
 	- NOTES: Contrary to existing documentation, <dependencies> is a top level element, not a child element of <about>
 	- TODO:
-		- Provide more info (particularly about data) in selection UI
+		- Also provide "about" info and dependencies on plugin help pages
 		- Explicitly document the fact that <include>s can be used for <about> and <dependencies>
-		- Add possibilities for soft dependencies (i.e. dynamic version check within a plugin)
 		- Think about means for cross-package pluginmap includes
 - Added support for the upcoming R 3.0.0			TODO: Check for any more regressions, before release
 - Added <switch> logic element to switch between several target properties (or fixed values) based on the value of a condition property

Modified: trunk/rkward/rkward/plugin/rkcomponentmeta.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmeta.cpp	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/plugin/rkcomponentmeta.cpp	2013-01-28 11:10:50 UTC (rev 4516)
@@ -107,6 +107,19 @@
 	return true;
 }
 
+bool RKComponentDependency::isRVersionCompatible (const QDomElement& e) {
+	RK_TRACE (PLUGIN);
+
+	if (e.hasAttribute (R_min_version_tag)) {
+		if (RKSessionVars::compareRVersion (e.attribute (R_min_version_tag)) > 0) return false;
+	}
+	if (e.hasAttribute (R_max_version_tag)) {
+		if (RKSessionVars::compareRVersion (e.attribute (R_max_version_tag)) < 0) return false;
+	}
+
+	return true;
+}
+
 QList <RKComponentDependency> RKComponentDependency::parseDependencies (const QDomElement& e) {
 	RK_TRACE (PLUGIN);
 

Modified: trunk/rkward/rkward/plugin/rkcomponentmeta.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmeta.h	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/plugin/rkcomponentmeta.h	2013-01-28 11:10:50 UTC (rev 4516)
@@ -39,6 +39,7 @@
 
 	static QList<RKComponentDependency> parseDependencies (const QDomElement &e);
 	static bool isRKWardVersionCompatible (const QDomElement &e);
+	static bool isRVersionCompatible (const QDomElement &e);
 };
 
 struct RKComponentAuthor {

Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2013-01-28 11:10:50 UTC (rev 4516)
@@ -703,6 +703,13 @@
 	for (it = children.constBegin (); it != children.constEnd (); ++it) {
 		initial_values.insert (xml->getStringAttribute (*it, "id", "#noid#", DL_WARNING), xml->getStringAttribute (*it, "to", "false", DL_WARNING));
 	}
+	children = xml->getChildElements (element, "dependency_check", DL_INFO);
+	for (it = children.constBegin (); it != children.constEnd (); ++it) {
+		RKComponentPropertyBool *dep = new RKComponentPropertyBool (component (), false);
+		dep->setInternal (true);
+		dep->setBoolValue (RKComponentDependency::isRKWardVersionCompatible (*it) && RKComponentDependency::isRVersionCompatible (*it));
+		component ()->addChild (xml->getStringAttribute (*it, "id", "#noid#", DL_WARNING), dep);
+	}
 
 	// find outside elements
 	children = xml->getChildElements (element, "external", DL_INFO);

Modified: trunk/rkward/rkward/plugins/00saveload/save/save.rkh
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/save/save.rkh	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/plugins/00saveload/save/save.rkh	2013-01-28 11:10:50 UTC (rev 4516)
@@ -11,7 +11,7 @@
 		<setting id="data">One or more objects to save.</setting>
 		<setting id="file">Location to save to.</setting>
 		<setting id="ascii">Write an ascii, rather than binary representation of the object(s).</setting>
-		<setting id="compress">The file can be compressed to achieve a smaller file size. This control allows to select the method of compression.</setting>
+		<setting id="compress">The file can be compressed to achieve a smaller file size. This control allows to select the method of compression. Some methods are not available for versions of R before 2.10.0.</setting>
 		<setting id="complevel">Compression level. Higher values indicate better compression.</setting>
 		<setting id="xzextreme">For <i>xz</i> compression, only: Enable xz "extreme" compresison.</setting>
 	</settings>

Modified: trunk/rkward/rkward/plugins/00saveload/save/save.xml
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/save/save.xml	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/plugins/00saveload/save/save.xml	2013-01-28 11:10:50 UTC (rev 4516)
@@ -4,6 +4,9 @@
 	<help file="save.rkh"/>
 
 	<logic>
+		<dependency_check R_min_version="2.10.0" id="R210"/>
+		<connect governor="R210" client="compress.xz.enabled" />
+		<connect governor="R210" client="compress.bzip2.enabled" />
 		<convert id="lgc_compress" sources="compress.string" mode="notequals" standard="" />
 		<convert id="lgc_cmprssxz" sources="compress.string" mode="equals" standard="xz" />
 		<connect governor="lgc_compress" client="complevel.enabled" />
@@ -41,8 +44,8 @@
 						<dropdown id="compress" label="Compression">
 							<option label="None" value="" checked="true" />
 							<option label="gzip" value="gzip" />
-							<option label="bzip2" value="bzip2" />
-							<option label="xz" value="xz" />
+							<option id="bzip2" label="bzip2" value="bzip2" />
+							<option id="xz" label="xz" value="xz" />
 						</dropdown>
 						<spinbox label="Compression level" id="complevel" initial="6" min="1" max="9" type="integer" />
 						<checkbox id="xzextreme" label="Enable xz extreme compression" value="true" />

Modified: trunk/rkward/rkward/plugins/import_export.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/import_export.pluginmap	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/plugins/import_export.pluginmap	2013-01-28 11:10:50 UTC (rev 4516)
@@ -8,7 +8,7 @@
 		<component type="standard" id="load_source" file="import/source.xml" label="Source an R file" />
 
 		<component type="standard" id="save_r" file="save/save.xml" label="Save objects as R data">
-			<dependencies R_min_version="2.10.0"/> <!-- "save_r" needs at least R 2.10 for bzip2/xz compression -->
+			<!-- <dependencies R_min_version="2.10.0"/>  "save_r" needs at least R 2.10 for bzip2/xz compression, but this is now handled inside the plugin itself. -->
 		</component>
 		<component type="standard" id="save_skeleton" file="save/skeleton/description.xml" label="Create package skeleton" />
 		<component type="standard" id="save_variables" file="save/write.xml" label="Export vector or matrix data" />

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2013-01-28 11:10:50 UTC (rev 4516)
@@ -2,7 +2,7 @@
                           rinterface.cpp  -  description
                              -------------------
     begin                : Fri Nov 1 2002
-    copyright            : (C) 2002, 2004, 2005, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2002-2013 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -74,6 +74,7 @@
 #define GET_HELP_BASE 2
 #define SET_RUNTIME_OPTS 3
 #define STARTUP_PHASE2_COMPLETE 4
+#define GET_R_VERSION 5
 
 // statics
 double RInterface::na_real;
@@ -279,6 +280,10 @@
 		issueCommand ("rk.set.output.html.file (\"" + RKSettingsModuleGeneral::filesPath () + "/rk_out.html\")\n", RCommand::App | RCommand::Sync, QString (), this, SET_RUNTIME_OPTS, chain);
 
 		closeChain (chain);
+	} else if (command->getFlags () == GET_R_VERSION) {
+		RK_ASSERT (command->getDataType () == RData::StringVector);
+		RK_ASSERT (command->getDataLength () == 1);
+		RKSessionVars::setRVersion (command->stringVector ().value (0));
 	} else if (command->getFlags () == GET_HELP_BASE) {
 		RK_ASSERT (command->getDataType () == RData::StringVector);
 		RK_ASSERT (command->getDataLength () == 1);
@@ -345,6 +350,7 @@
 		RCommandStack *stack = new RCommandStack (runningCommand ());
 		RCommandChain *chain = stack->startChain (stack);
 
+		issueCommand ("paste (R.version[c (\"major\", \"minor\")], collapse=\".\")\n", RCommand::GetStringVector | RCommand::App | RCommand::Sync, QString (), this, GET_R_VERSION, chain);
 		// find out about standard library locations
 		issueCommand (".libPaths ()\n", RCommand::GetStringVector | RCommand::App | RCommand::Sync, QString (), this, GET_LIB_PATHS, chain);
 		// start help server / determined help base url

Modified: trunk/rkward/rkward/rbackend/rksessionvars.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rksessionvars.cpp	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/rbackend/rksessionvars.cpp	2013-01-28 11:10:50 UTC (rev 4516)
@@ -25,6 +25,8 @@
 RKSessionVars* RKSessionVars::_instance = 0;
 quint32 RKSessionVars::rkward_version = 0;
 QString RKSessionVars::rkward_version_suffix;
+quint32 RKSessionVars::r_version = 0;
+QString RKSessionVars::r_version_string;
 
 RKSessionVars::RKSessionVars (RInterface *parent) : QObject (parent) {
 	RK_TRACE (RBACKEND);
@@ -44,6 +46,16 @@
 	emit (installedPackagesChanged ());
 }
 
+void RKSessionVars::setRVersion (const QString& version_string) {
+	RK_TRACE (RBACKEND);
+
+	if (!r_version_string.isEmpty ()) {
+		RK_DEBUG (RBACKEND, DL_WARNING, "R version has changed during runtime, from %s to %s", qPrintable (r_version_string), qPrintable (r_version));
+	}
+	r_version_string = version_string;
+	r_version = parseVersionString (version_string, 0);
+}
+
 quint32 RKSessionVars::parseVersionString (const QString &version, QString *suffix) {
 	quint32 ret = 0;
 	int pos = -1;
@@ -89,4 +101,13 @@
 	return (suffix.compare (rkward_version_suffix));
 }
 
+int RKSessionVars::compareRVersion (const QString& version) {
+	if (r_version_string.isEmpty()) return 0;
+
+	quint32 ver = parseVersionString (version, 0);
+	if (ver < r_version) return -1;
+	if (ver > r_version) return 1;
+	return 0;
+}
+
 #include "rksessionvars.moc"

Modified: trunk/rkward/rkward/rbackend/rksessionvars.h
===================================================================
--- trunk/rkward/rkward/rbackend/rksessionvars.h	2013-01-27 18:39:49 UTC (rev 4515)
+++ trunk/rkward/rkward/rbackend/rksessionvars.h	2013-01-28 11:10:50 UTC (rev 4516)
@@ -22,7 +22,6 @@
 #include <QStringList>
 
 class RInterface;
-class RCommand;
 
 /** Singleton for storing information about the running R session, and - for some of the info - notifying about changes. */
 class RKSessionVars : public QObject {
@@ -31,8 +30,11 @@
 	static RKSessionVars* instance () { return _instance; };
 	QStringList installedPackages () const { return installed_packages; };
 	void setInstalledPackages (const QStringList &new_list);
+	static void setRVersion (const QString &version_string);
 /** compare given version string against the running version of RKWard. Returns -1 for earlier than current, 0 for equal, 1 for later than current version */
 	static int compareRKWardVersion (const QString &version);
+/** compare given version string against the running version of R. Returns -1 for earlier than current, 0 for equal, 1 for later than current version. NOTE: The version of R is not known until the R backend has been started. In this case, 0 is always returned */
+	static int compareRVersion (const QString &version);
 /** Split "a.b.c.d.e-fghi" into up to four numeric portions (returned as four bytes in a single 32bit unsigned int).
 Anything else (everything after the fourth dot, or after the first character that is neither dot, nor digit)
 is returned as suffix (via the suffix pointer; if that is 0, an error is reported, instead). */
@@ -49,6 +51,8 @@
 	QStringList installed_packages;
 	static quint32 rkward_version;
 	static QString rkward_version_suffix;
+	static quint32 r_version;
+	static QString r_version_string;
 };
 
 #endif





More information about the rkward-tracker mailing list