[education/rkward] rkward/plugins: added DownloadAppImage plugin

m.eik michalke null at kde.org
Thu Aug 29 09:36:52 BST 2024


Git commit 8503e721e27552b3d988e1ad7fc3a834b3a15d42 by m.eik michalke.
Committed on 29/08/2024 at 08:36.
Pushed by meikm into branch 'master'.

added DownloadAppImage plugin

A  +50   -0    rkward/plugins/00saveload/DownloadAppImage.js
A  +60   -0    rkward/plugins/00saveload/DownloadAppImage.rkh
A  +78   -0    rkward/plugins/00saveload/DownloadAppImage.xml
M  +2    -0    rkward/plugins/import_export.pluginmap
A  +308  -0    rkward/plugins/rkwarddev_scripts/rkwarddev_rk.download_appimage_plugin_script.R

https://invent.kde.org/education/rkward/-/commit/8503e721e27552b3d988e1ad7fc3a834b3a15d42

diff --git a/rkward/plugins/00saveload/DownloadAppImage.js b/rkward/plugins/00saveload/DownloadAppImage.js
new file mode 100644
index 000000000..b47a4e440
--- /dev/null
+++ b/rkward/plugins/00saveload/DownloadAppImage.js
@@ -0,0 +1,50 @@
+// this code was generated using the rkwarddev package.
+// perhaps don't make changes here, but in the rkwarddev script instead!
+// 
+// look for a file called: $SRC/inst/rkward/rkwarddev_rk.download_appimage_plugin_script.R
+
+
+
+function preprocess(is_preview){
+  // add requirements etc. here
+  var noLoadMsg = getValue("noLoadMsg");
+  if(noLoadMsg) {
+    echo("suppressMessages(require(XiMpLe))\n");
+  } else {
+    echo("require(XiMpLe)\n");
+  }
+}
+
+function calculate(is_preview){
+  // read in variables from dialog
+  var aiuFile = getString("aiu_file");
+  var aiuUrl = getString("aiu_url");
+  var aiuPattern = getString("aiu_pattern");
+  var aiuMethod = getString("aiu_method");
+  var aiuTimeout = getString("aiu_timeout");
+  var aiuCacheok = getBoolean("aiu_cacheok.state");
+
+  // the R code to be evaluated
+  var aiuFileOverwrite = getValue("aiu_file.overwrite");
+  var fileBasename = aiuFile.replace(/.*\//, '');
+  var fileDirname = aiuFile.match(/.*\//);
+  echo("appimage <- rk.with.progress(\n  {rk.download_appimage(\n" + "    dir = \"" + fileDirname + "\"" + ",\n    filename = \"" + fileBasename + "\"");
+  if(aiuFileOverwrite) {
+    echo(",\n    overwrite = TRUE");  
+  } else {
+    echo(",\n    overwrite = FALSE");  
+  }
+  echo(",\n    url = \"" + aiuUrl + "\"" + ",\n    pattern = \"" + aiuPattern + "\"" + ",\n    method = \"" + aiuMethod + "\"");
+  if(aiuCacheok) {
+    echo(",\n      cacheOK=TRUE");
+  } else {}
+  echo(",\n    timeout = " + aiuTimeout + "\n  )},\n  text = \"Downloading RKWard AppImage...\"\n)\n\n");
+}
+
+function printout(is_preview){
+  // printout the results
+  new Header(i18n("Download AppImage results")).print();
+  echo("rk.print.literal(\"AppImage was saved as:\")\n" + "rk.results(appimage)\n" + "rk.print.literal(\"You must restart RKWard to use it.\")\n");
+
+}
+
diff --git a/rkward/plugins/00saveload/DownloadAppImage.rkh b/rkward/plugins/00saveload/DownloadAppImage.rkh
new file mode 100644
index 000000000..a8e201f7a
--- /dev/null
+++ b/rkward/plugins/00saveload/DownloadAppImage.rkh
@@ -0,0 +1,60 @@
+<!DOCTYPE rkhelp >
+<document>
+  <!--
+    this code was generated using the rkwarddev package.
+  perhaps don't make changes here, but in the rkwarddev script instead!
+  
+  look for a file called: $SRC/inst/rkward/rkwarddev_rk.download_appimage_plugin_script.R
+  -->
+  <title>
+    Download AppImage
+  </title>
+  <summary>
+    Adds a dialog to install or update an AppImage of RKWard
+  </summary>
+  <usage>
+  </usage>
+  <!--
+    <section id="sct_EDITORDE" title="EDIT OR DELETE ME">
+      EDIT OR DELETE ME
+    </section>
+  -->
+  <settings>
+    <caption id="tab_File" />
+    <caption id="frm_txtPAIYRFR" />
+    <caption id="frm_brwsrlbSAI" />
+    <setting id="aiu_file">
+      Select a target file to save the AppImage to.
+    </setting>
+    <setting id="noLoadMsg">
+    </setting>
+    <caption id="tab_Source" />
+    <setting id="aiu_url">
+      URL to look for the AppImage files.
+    </setting>
+    <setting id="aiu_pattern">
+      Regular expression to find links to the AppImage in the HTML code of the URL.
+    </setting>
+    <caption id="tab_Download" />
+    <setting id="aiu_method">
+      The method to use by download.file().
+    </setting>
+    <setting id="aiu_cacheok">
+      Is a server-side cached value acceptable? Disabling this is useful for ‘⁠http://⁠’ and ‘⁠https://⁠’ URLs. It will attempt to get a copy directly from the site rather than from an intermediate cache.
+    </setting>
+    <setting id="aiu_timeout">
+      The number of seconds allowed to try downloading the AppImage.
+    </setting>
+  </settings>
+  <!--
+    <related>
+      <ul>
+        <li>
+          <link href="rkward://rhelp/..." />
+        </li>
+      </ul>
+    </related>
+  -->
+  <technical>
+  </technical>
+</document>
diff --git a/rkward/plugins/00saveload/DownloadAppImage.xml b/rkward/plugins/00saveload/DownloadAppImage.xml
new file mode 100644
index 000000000..38be968a0
--- /dev/null
+++ b/rkward/plugins/00saveload/DownloadAppImage.xml
@@ -0,0 +1,78 @@
+<!DOCTYPE rkplugin >
+<document>
+  <!--
+    this code was generated using the rkwarddev package.
+  perhaps don't make changes here, but in the rkwarddev script instead!
+  
+  look for a file called: $SRC/inst/rkward/rkwarddev_rk.download_appimage_plugin_script.R
+  -->
+  <code file="DownloadAppImage.js" />
+  <help file="DownloadAppImage.rkh" />
+  <!--
+    <dependencies>
+    </dependencies>
+  -->
+  <logic>
+    <script>
+      <![CDATA[
+        doRCommand('Sys.getenv("APPIMAGE")', "commandFinished");
+        commandFinished = function (result, id) {
+          if (result != "") {
+            gui.setValue("aiu_file.selection", result);
+            return;
+          }
+        }
+      ]]>
+    </script>
+  </logic>
+  <dialog label="Download AppImage">
+    <tabbook id="tbbk_AppImage" label="AppImage">
+      <tab label="File" id="tab_File">
+        <row id="row_cPAIYRFRPA">
+          <column id="clm_fPAIYRFRPA">
+            <frame id="frm_txtPAIYRFR">
+              <text id="aiu_file_warning" type="warning">
+                Please note that downloading the AppImage file might take a while. Your R session can be occpied for some minutes once you submit. For a live feedback of the download progress, please run the
+                <code>
+                  rk.download_appimage()
+                </code>
+                call in the R console manually.
+              </text>
+            </frame>
+            <frame id="frm_brwsrlbSAI">
+              <browser label="Save to" type="savefile" id="aiu_file" filter="*.AppImage" />
+            </frame>
+            <stretch />
+            <checkbox id="noLoadMsg" label="Suppress package loading messages" value="true" checked="true" />
+          </column>
+        </row>
+      </tab>
+      <tab label="Source" id="tab_Source">
+        <row id="row_cURLP8664A">
+          <column id="clm_iURLP8664A">
+            <input label="URL" id="aiu_url" initial="https://cdn.kde.org/ci-builds/education/rkward/master/linux" required="true" />
+            <input label="Pattern" id="aiu_pattern" initial="rkward-master.*linux-gcc-x86_64\\.AppImage" required="true" />
+            <stretch />
+          </column>
+        </row>
+      </tab>
+      <tab label="Download" id="tab_Download">
+        <row id="row_cDWAT40040">
+          <column id="clm_dDWAT40040">
+            <dropdown id="aiu_method" label="Download method">
+              <option label="auto" value="auto" checked="true" />
+              <option label="internal" value="internal" />
+              <option label="libcurl" value="libcurl" />
+              <option label="wget" value="wget" />
+              <option label="curl" value="curl" />
+              <option label="wininet (Windows only)" value="wininet" />
+            </dropdown>
+            <checkbox id="aiu_cacheok" label="Allow cached files" value="true" />
+            <spinbox label="Timeout" id="aiu_timeout" initial="400" min="400" type="integer" />
+            <stretch />
+          </column>
+        </row>
+      </tab>
+    </tabbook>
+  </dialog>
+</document>
diff --git a/rkward/plugins/import_export.pluginmap b/rkward/plugins/import_export.pluginmap
index f71f92ae4..22823d384 100644
--- a/rkward/plugins/import_export.pluginmap
+++ b/rkward/plugins/import_export.pluginmap
@@ -51,6 +51,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 		<component type="standard" id="import_generic_rio" file="import/import_generic_rio.xml" label="Generic import (rio-based)" />
 
 		<component type="standard" id="setworkdir" file="setworkdir.xml" label="Set Working Directory" />
+		<component id="cmp_DownloadAppImgDwnldAppImg" label="Download AppImage" type="standard" file="DownloadAppImage.xml"></component>
 	</components>
 
 	<hierarchy>
@@ -74,6 +75,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 				<entry component="save_rmarkdown" />
 				<entry component="save_skeleton" />
 			</menu>
+			<entry component="cmp_DownloadAppImgDwnldAppImg" />
 		</menu>
 		<menu id="workspace" label="Workspace">
 			<entry component="setworkdir" />
diff --git a/rkward/plugins/rkwarddev_scripts/rkwarddev_rk.download_appimage_plugin_script.R b/rkward/plugins/rkwarddev_scripts/rkwarddev_rk.download_appimage_plugin_script.R
new file mode 100644
index 000000000..60d88f94e
--- /dev/null
+++ b/rkward/plugins/rkwarddev_scripts/rkwarddev_rk.download_appimage_plugin_script.R
@@ -0,0 +1,308 @@
+require(rkwarddev)
+rkwarddev.required("0.08-1")
+
+rk.local({
+# define where the plugin should write its files
+output.dir <- tempdir()
+# overwrite an existing plugin in output.dir?
+overwrite <- TRUE
+# if you set guess.getters to TRUE, the resulting code will need RKWard >= 0.6.0
+guess.getter <- TRUE
+# define the indentation character for the generated code
+rk.set.indent(by="  ")
+# should empty "else" clauses be kept in the JavaScript code?
+rk.set.empty.e(TRUE)
+# make your plugin translatable by setting this to TRUE
+update.translations <- FALSE
+
+aboutPlugin <- rk.XML.about(
+  name="rk.downloadAppImage",
+  author=c(
+    person(
+      given="Meik",
+      family="Michalke",
+      email="meik.michalke at hhu.de",
+      role=c("aut", "cre")
+    )
+  ),
+  about=list(
+    desc="Adds a dialog to install or update an AppImage of RKWard",
+    version="0.01-0",
+    url="https://rkward.kde.org",
+    license="GPL (>= 3)"
+  )
+)
+
+plugin.dependencies <- rk.XML.dependencies(
+  dependencies=list(
+    rkward.min="0.8.0"
+  ),
+  package=list(
+    c(name="XiMpLe", min="0.11-3")
+  )
+)
+
+# name of the main component, relevant for help page content
+rk.set.comp("Download AppImage")
+
+############
+## your plugin dialog and JavaScript should be put here
+############
+
+aiu_file <- rk.XML.browser(
+  label="Save to",
+  type = "savefile",
+  initial = NULL, # dirname(Sys.getenv("APPIMAGE")) basename(Sys.getenv("APPIMAGE"))
+  filter = "*.AppImage",
+  id.name = "aiu_file",
+  help = "Select a target file to save the AppImage to."
+)
+
+noLoadMsg <- rk.XML.cbox(
+  label="Suppress package loading messages",
+  value="true",
+  chk=TRUE,
+  id.name="noLoadMsg"
+)
+
+tab_file <- rk.XML.row(
+  rk.XML.col(
+    rk.XML.frame(
+      rk.XML.text(
+        "Please note that downloading the AppImage file might take a while. Your R session can be occpied for some minutes once you submit. For a live feedback of the download progress, please run the <code>rk.download_appimage()</code> call in the R console manually.",
+        type="warning",
+        id.name="aiu_file_warning"
+      )
+    ),
+    rk.XML.frame(
+      aiu_file
+    ),
+    rk.XML.stretch(),
+    noLoadMsg
+  )
+)
+
+aiu_url <- rk.XML.input(
+  label = "URL",
+  initial = "https://cdn.kde.org/ci-builds/education/rkward/master/linux",
+  size = "medium",
+  required = TRUE,
+  id.name = "aiu_url",
+  help = "URL to look for the AppImage files."
+)
+
+aiu_pattern <- rk.XML.input(
+  label = "Pattern",
+  initial = "rkward-master.*linux-gcc-x86_64\\\\.AppImage",
+  size = "medium",
+  required = TRUE,
+  id.name = "aiu_pattern",
+  help = "Regular expression to find links to the AppImage in the HTML code of the URL."
+)
+
+tab_source <- rk.XML.row(
+  rk.XML.col(
+    aiu_url,
+    aiu_pattern,
+    rk.XML.stretch()
+  )
+)
+
+aiu_method <- rk.XML.dropdown(
+  label = "Download method",
+  options = list(
+    "auto"=c(
+      val = "auto",
+      chk = TRUE
+    ),
+    "internal"=c(
+      val = "internal"
+    ),
+    "libcurl"=c(
+      val = "libcurl"
+    ),
+    "wget"=c(
+      val = "wget"
+    ),
+    "curl"=c(
+      val = "curl"
+    ),
+    "wininet (Windows only)"=c(
+      val = "wininet"
+    )
+  ),
+  id.name = "aiu_method",
+  help = "The method to use by download.file()."
+)
+
+# download.file {utils}
+aiu_cacheok <- rk.XML.checkbox(
+  "Allow cached files",
+  chk = FALSE,
+  id.name = "aiu_cacheok",
+  help = "Is a server-side cached value acceptable? Disabling this is useful for ‘⁠http://⁠’ and ‘⁠https://⁠’ URLs. It will attempt to get a copy directly from the site rather than from an intermediate cache."
+)
+
+aiu_timeout <- rk.XML.spinbox(
+  label = "Timeout",
+  min = 400,
+  initial = 400, # max(400, getOption("timeout"))
+  real = FALSE,
+  id.name = "aiu_timeout",
+  help = "The number of seconds allowed to try downloading the AppImage."
+)
+
+tab_download <- rk.XML.row(
+  rk.XML.col(
+    aiu_method,
+    aiu_cacheok,
+    aiu_timeout,
+    rk.XML.stretch()
+  )
+)
+
+pluginDialog <- rk.XML.dialog(
+  rk.XML.tabbook(
+    label = "AppImage",
+    tabs = list(
+      "File" = tab_file,
+      "Source" = tab_source,
+      "Download" = tab_download
+    )
+  ),
+  label = "Download AppImage"
+)
+
+################
+## logic section
+
+aiu_logic <- rk.XML.logic(rk.comment(id("
+  doRCommand('Sys.getenv(\"APPIMAGE\")', \"commandFinished\");
+        commandFinished = function (result, id) {
+          if (result != \"\") {
+            gui.setValue(\"", aiu_file, ".selection\", result);
+            return;
+          }
+        }
+", js=FALSE)))
+
+
+#############
+## JavaScript
+
+overwriteChecked <- rk.JS.vars(aiu_file, modifiers="overwrite")
+# dummy vars used for scripting
+file_basename <- rk.JS.vars("fileBasename")
+file_dirname <- rk.JS.vars("fileDirname")
+aiu_js_calc <- rk.paste.JS(
+  overwriteChecked,
+  js(
+    "var ", file_basename, " = ", aiu_file, ".replace(/.*\\//, '');",
+    linebreaks = FALSE
+  ),
+  js(
+    "var ", file_dirname, " = ", aiu_file, ".match(/.*\\//);",
+    linebreaks = FALSE
+  ),
+  echo(
+    "appimage <- rk.with.progress(\n  {rk.download_appimage(\n",
+    "    dir = \"", file_dirname, "\"",          # dir = dirname(Sys.getenv("APPIMAGE"))
+    ",\n    filename = \"", file_basename, "\""  # filename = "rkward-master-linux-gcc-x86_64.AppImage"
+  ),
+  js(
+    if(overwriteChecked){
+      echo(",\n    overwrite = TRUE")
+    } else {
+      echo(",\n    overwrite = FALSE")
+    }
+  ),
+  echo(
+    ",\n    url = \"", aiu_url, "\"",                # url = "https://cdn.kde.org/ci-builds/education/rkward/master/linux"
+    ",\n    pattern = \"", aiu_pattern, "\"",        # pattern = "rkward-master.*linux-gcc-x86_64\\.AppImage"
+    ",\n    method = \"", aiu_method, "\""           # method = "auto"
+  ),
+  tf(
+    aiu_cacheok,                                   #   , cacheOK = FALSE
+    opt = "cacheOK",
+    level = 4
+  ),
+  echo(",\n    timeout = ", aiu_timeout,             # timeout =  max(400, getOption("timeout"))
+    "\n  )},\n  text = \"Downloading RKWard AppImage...\"\n)\n\n"
+  )
+)
+
+aiu_js_print <- rk.paste.JS(
+  echo(
+    "rk.print.literal(\"AppImage was saved as:\")\n",
+    "rk.results(appimage)\n",
+    "rk.print.literal(\"You must restart RKWard to use it.\")\n"
+  )
+)
+
+############
+## help page
+plugin.summary <- rk.rkh.summary(
+  "Adds a dialog to install or update an AppImage of RKWard"
+)
+plugin.usage <- rk.rkh.usage(
+  ""
+)
+
+#############
+## the main call
+## if you run the following function call, files will be written to output.dir!
+#############
+# this is where things get serious, that is, here all of the above is put together into one plugin
+plugin.dir <- rk.plugin.skeleton(
+  about=aboutPlugin,
+  #dependencies=plugin.dependencies,
+  path=output.dir,
+  guess.getter=guess.getter,
+  scan=c("var", "saveobj", "settings"),
+  xml=list(
+      dialog=pluginDialog
+#     , wizard=
+    , logic=aiu_logic
+#     , snippets=
+  ),
+  js=list(
+#       results.header=FALSE
+      load.silencer=noLoadMsg
+    , require="XiMpLe"
+#     , variables=
+#     , globals=
+#     , preprocess=
+    , calculate=aiu_js_calc
+    , printout=aiu_js_print
+#     , doPrintout=
+  ),
+  rkh=list(
+      summary=plugin.summary
+    , usage=plugin.usage
+#     , sections=
+#     , settings=
+#     , related=
+#     , technical=
+  ),
+  create=c("pmap", "xml", "js", "desc", "rkh"),
+  overwrite=overwrite,
+  #components=list(),, 
+  #provides=c("logic", "dialog"), 
+  pluginmap=list(name="Download AppImage", hierarchy="file"), 
+  tests=FALSE, 
+  # edit=TRUE, 
+  load=TRUE, 
+  show=FALSE,
+  gen.info="$SRC/inst/rkward/rkwarddev_rk.download_appimage_plugin_script.R"
+)
+
+# you can make your plugin translatable, see top of script
+if(isTRUE(update.translations)){
+  rk.updatePluginMessages(
+    file.path(output.dir,"rk.downloadAppImage","inst","rkward","rk.downloadAppImage.pluginmap"),
+    # where should translation bug reports go?
+    bug_reports="https://mail.kde.org/mailman/listinfo/kde-i18n-doc"
+  )
+} else {}
+
+})


More information about the rkward-tracker mailing list