Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions Utilities/DataGenerator/convert-cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
#! /usr/bin/env node

var fs = require('fs');
var { execSync } = require('child_process');
var { program } = require('commander');
var shell = require('shelljs');
var path = require('path');

function lsDir(dirPath) {
try { return fs.readdirSync(dirPath); } catch (e) { return []; }
}

function findAll(dirs) {
var results = [];
dirs.forEach(function (dir) {
try {
fs.readdirSync(dir).forEach(function (entry) {
var full = path.join(dir, entry);
results.push(full);
try {
if (fs.statSync(full).isDirectory()) {
findAll([full]).forEach(function (p) { results.push(p); });
}
} catch (e) {}
});
} catch (e) {}
});
return results;
}
var paraview = process.env.PARAVIEW_HOME;

program.version('1.0.0')
Expand All @@ -24,7 +46,7 @@ const options = program.opts();
// Try to find a paraview directory inside /Applications or /opt
const pvPossibleBasePath = [];
['/Applications', '/opt', '/usr/local/opt/'].forEach(function (directoryPath) {
shell.ls(directoryPath).forEach(function (fileName) {
lsDir(directoryPath).forEach(function (fileName) {
if (fileName.toLowerCase().indexOf('paraview') !== -1) {
pvPossibleBasePath.push(path.join(directoryPath, fileName));
}
Expand All @@ -49,7 +71,7 @@ if (!process.argv.slice(2).length || !options.help || paraview.length === 0) {
process.exit(0);
}

var pvPythonExecs = shell.find(paraview).filter(function(file) { return file.match(/pvpython$/) || file.match(/pvpython.exe$/); });
var pvPythonExecs = findAll(paraview).filter(function(file) { return file.match(/pvpython$/) || file.match(/pvpython.exe$/); });
if(pvPythonExecs.length < 1) {
console.log('Could not find pvpython in your ParaView HOME directory ($PARAVIEW_HOME)');
program.outputHelp();
Expand All @@ -65,7 +87,7 @@ if(pvPythonExecs.length < 1) {
console.log('| Execute:');
console.log('| $', cmdLineSample.join('\n|\t'));
console.log('===============================================================================\n');
shell.exec(cmdLineSample.join(' '));
execSync(cmdLineSample.join(' '), { stdio: 'inherit' });
} else {
const cmdLine = [
pvPythonExecs[0], '-dr',
Expand All @@ -86,5 +108,5 @@ if(pvPythonExecs.length < 1) {
console.log('| Execute:');
console.log('| $', cmdLine.join('\n|\t'));
console.log('===============================================================================\n');
shell.exec(cmdLine.join(' '));
execSync(cmdLine.join(' '), { stdio: 'inherit' });
}
Loading