jupyterlab-slurm
Version:
A JupyterLab extension to interface with the Slurm workload manager.
104 lines • 4.13 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const application_1 = require("@jupyterlab/application");
const apputils_1 = require("@jupyterlab/apputils");
const launcher_1 = require("@jupyterlab/launcher");
const coreutils_1 = require("@lumino/coreutils");
const filebrowser_1 = require("@jupyterlab/filebrowser");
// Local
const slurmWidget_1 = __importDefault(require("./slurmWidget"));
const config = __importStar(require("./slurm-config/config.json"));
require("bootstrap/dist/css/bootstrap.min.css");
/**
* The class names for the Slurm extension icon, for launcher and
* tab, respectively
*/
const SLURM_ICON_CLASS_L = 'jp-NerscLaunchIcon';
const SLURM_ICON_CLASS_T = 'jp-NerscTabIcon';
/**
* Activate the Slurm widget extension.
*/
function activate(app, palette, restorer, filebrowserfactory, launcher) {
// Declare a Slurm widget variable
let widget;
// Add an application command
const command = 'slurm:open';
const filebrowser = filebrowserfactory.defaultBrowser;
app.commands.addCommand(command, {
label: args => (args['isPalette'] ? 'Open Slurm Queue Manager' : 'Slurm Queue'),
iconClass: args => (args['isPalette'] ? '' : SLURM_ICON_CLASS_L),
execute: () => {
if (!widget) {
// Instantiate a new widget if one does not exist
widget = new slurmWidget_1.default(filebrowser);
widget.title.icon = SLURM_ICON_CLASS_T;
// Reload table on regular intervals if autoReload is activated
if (config["autoReload"]) {
setInterval(() => widget.update(), config["autoReloadRate"]);
}
}
if (!tracker.has(widget)) {
// Track the state of the widget for later restoration
tracker.add(widget);
}
if (!widget.isAttached) {
// Attach the widget to the main work area if it's not there
app.shell.add(widget);
}
widget.update();
// Activate the widget
app.shell.activateById(widget.id);
}
});
// Add the command to the palette.
palette.addItem({ command, category: 'HPC Tools', args: { isPalette: true } });
// Track and restore the widget state
let tracker = new apputils_1.WidgetTracker({ namespace: 'slurm' });
restorer.restore(tracker, {
command,
args: () => coreutils_1.JSONExt.emptyObject,
name: () => 'slurm'
});
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
command: 'slurm:open',
rank: 1,
category: 'HPC Tools'
});
}
} // activate
/**
* Initialization data for the jupyterlab-slurm extension.
*/
const extension = {
id: 'jupyterlab-slurm',
autoStart: true,
requires: [apputils_1.ICommandPalette, application_1.ILayoutRestorer, filebrowser_1.IFileBrowserFactory],
optional: [launcher_1.ILauncher],
activate: activate
};
exports.default = extension;
//# sourceMappingURL=index.js.map