aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-23 16:53:57 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-23 16:54:27 +0800
commita993ae58f3c848bbf46c90f217d1dbc1f44828c1 (patch)
tree9b9a7f6006c5ba1705766142abefc0454f2f1ff3 /fg21sim/webui
parent58bc8b4bca4a0272ea78294d8aa413598eaf75c6 (diff)
downloadfg21sim-a993ae58f3c848bbf46c90f217d1dbc1f44828c1.tar.bz2
webui: products: Implement GET action "which"
The "which" GET action try to locate the given executable name/path, in order to check whether the executable callable. This function will be used to check the validity of the specified FITS viewer, which opens the HPX FITS images.
Diffstat (limited to 'fg21sim/webui')
-rw-r--r--fg21sim/webui/handlers/products.py17
-rw-r--r--fg21sim/webui/static/js/products.js21
2 files changed, 37 insertions, 1 deletions
diff --git a/fg21sim/webui/handlers/products.py b/fg21sim/webui/handlers/products.py
index f68fa5d..ffb27bb 100644
--- a/fg21sim/webui/handlers/products.py
+++ b/fg21sim/webui/handlers/products.py
@@ -8,6 +8,7 @@ Handle the AJAX requests from the client to manage the simulation products.
import os
import logging
+import shutil
import tornado.ioloop
from tornado.escape import json_decode, json_encode
@@ -41,16 +42,32 @@ class ProductsAJAXHandler(BaseRequestHandler):
Supported actions:
- get: Get the current products manifest
+ - which: Locate the command/program (check whether the command/program
+ can be found in PATH and is executable)
- download: TODO
- open: TODO
"""
action = self.get_argument("action", "get")
if action == "get":
+ # Get current products manifest
response = {
"manifest": self.products.manifest,
"localhost": self.from_localhost,
}
success = True
+ elif action == "which":
+ # Locate (and check) the command/program
+ cmd = json_decode(self.get_argument("cmd"))
+ cmdpath = shutil.which(cmd)
+ if cmdpath:
+ success = True
+ response = {
+ "isExecutable": True,
+ "cmdPath": cmdpath,
+ }
+ else:
+ success = False
+ reason = "Cannot locate the executable for: {0}".format(cmd)
else:
# ERROR: bad action
success = False
diff --git a/fg21sim/webui/static/js/products.js b/fg21sim/webui/static/js/products.js
index 0b25eaa..72a7028 100644
--- a/fg21sim/webui/static/js/products.js
+++ b/fg21sim/webui/static/js/products.js
@@ -192,6 +192,25 @@ var getServerManifest = function (url) {
/**
+ * Locate the command in the `$PATH` on the server, which checks
+ * whether the command can be called.
+ *
+ * @param {String} cmd - The command name or path.
+ */
+var whichExecutable = function (url, cmd) {
+ return $.getJSON(url, {action: "which", cmd: JSON.stringify(cmd)})
+ .fail(function (jqxhr) {
+ var modalData = {};
+ modalData.icon = "times-circle";
+ modalData.contents = "Cannot locate the command in PATH!";
+ modalData.code = jqxhr.status;
+ modalData.reason = jqxhr.statusText;
+ showModalProducts(modalData);
+ });
+};
+
+
+/**
* Reset the products manifest on both the server side and client side
*/
var resetManifest = function (url) {
@@ -270,7 +289,7 @@ $(document).ready(function () {
// Save current products manifest
$("#save-products").on("click", function () {
- saveServerManifest(ajax_url);
+ saveServerManifest(ajax_url, true);
});
// Show product information (metadata)