summaryrefslogtreecommitdiff
path: root/app/relay/runner.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/relay/runner.js')
-rw-r--r--app/relay/runner.js104
1 files changed, 77 insertions, 27 deletions
diff --git a/app/relay/runner.js b/app/relay/runner.js
index 54f5a94..431ed75 100644
--- a/app/relay/runner.js
+++ b/app/relay/runner.js
@@ -7,6 +7,7 @@ import { set_connected } from './rpc'
import uuidv1 from 'uuid/v1'
import * as fs from 'fs'
import * as path from 'path'
+import readdir from 'fs-readdir-promise'
import * as q from './queue'
@@ -120,31 +121,31 @@ export function build_params(module, activity, task) {
}
}
-export function run_system_command(cmd, cb) {
- console.log('running system command:', cmd.cmd)
- switch(cmd.cmd) {
+export function run_system_command(opt, cb) {
+ console.log('running system command:', opt.cmd)
+ switch(opt.cmd) {
case 'nvidia-smi':
case 'uptime':
case 'w':
- execFile(cmd.cmd, [], cb)
+ execFile(opt.cmd, [], cb)
break
case 'ps':
- execFile(cmd.cmd, ['au'], cb)
+ execFile('ps', ['au'], cb)
break
case 'df':
execFile('df', ['-h'], cb)
break
case 'ls':
- list_directory(cmd, cb)
+ list_directory(opt, cb)
break
case 'du':
- disk_usage(cmd, cb)
+ disk_usage(opt, cb)
break
- case 'list_results':
- list_results(cmd, cb)
+ case 'list_sequences':
+ list_sequences(opt, cb)
break
case 'dir_to_video':
- dir_to_video(cmd, cb)
+ dir_to_video(opt, cb)
break
default:
cb({ error: 'no such command' })
@@ -152,15 +153,20 @@ export function run_system_command(cmd, cb) {
}
}
-export function list_directory(opt, cb) {
+export function module_dir(opt, dir){
if (!opt.module || ! modules[opt.module]) {
- cb([])
+ return null
}
const module = modules[opt.module]
if (!module) {
- return cb([])
+ return null
}
- const dir = path.join(module.cwd, opt.dir.replace(/\.\.?\//g, ''))
+ return path.join(module.cwd, dir.replace(/\.\.?\//g, ''))
+}
+
+export function list_directory(opt, cb) {
+ const dir = module_dir(opt, opt.dir)
+ if (!dir) return cb([])
fs.readdir(dir, (err, files) => {
const statPromises = (files || []).filter(f => f[0] !== '.').map(f => {
return new Promise((resolve, reject) => {
@@ -177,35 +183,79 @@ export function list_directory(opt, cb) {
})
})
Promise.all(statPromises).then(stats => {
- cb(stats)
+ cb(stats, dir)
}).catch(error => {
cb(error)
})
})
}
-export function list_results(opt, cb) {
- // list the contents of the results directory for the module
- // filter out non-directories
- // for each directory
- // list it and count the files and sum their sizes and print the first filename and `identify` it...
- cb([])
+// list the contents of a directory of sequences
+export function list_sequences(opt, cb) {
+ list_directory(opt, (files, root_dir) => {
+ // console.log(files, root_dir)
+ const sequencePromises = files.filter(d => !!d.dir).map(f => {
+ return list_sequence(opt, f, root_dir)
+ })
+ Promise.all(sequencePromises).then(cb).catch(error => {
+ console.error(error)
+ cb([])
+ })
+ })
+}
+export function list_sequence(opt, f, root_dir) {
+ return new Promise( (resolve, reject) => {
+ let sequence = {
+ name: f.name,
+ date: f.date,
+ size: f.size,
+ frame: null,
+ count: 0,
+ }
+ readdir(path.join(root_dir, f.name)).then(files => {
+ if (! files.length) {
+ return resolve(sequence)
+ }
+ const middle_file = files[Math.floor(files.length/2)]
+ if (! middle_file) return resolve(sequence)
+ sequence.frame = {
+ prefix: middle_file.split('_')[0],
+ }
+ sequence.count = files.length
+ // console.log(sequence.count)
+ return stat_promise(path.join(root_dir, f.name, middle_file))
+ }).then(stat => {
+ sequence.frame.date = stat.date
+ sequence.frame.size = stat.size
+ resolve(sequence)
+ }).catch(err => reject(err))
+ })
+}
+
+export function stat_promise(fn) {
+ return new Promise((resolve, reject) => {
+ fs.stat(fn, (err, stat={}) => {
+ if (err) reject(err)
+ resolve(stat)
+ })
+ })
}
export function dir_to_video(opt, db) {
+ const dir = module_dir(opt, opt.dir)
+ if (!dir) return cb([])
// input: the path (in results/) you want as a video
// output: the path (in renders/) that contains the video
// run the dir to video script with CWD as the directory and first input as ../renders plus the directory name
// list the file in renders...
- cb([])
+ execFile('./bin/dir_to_video.pl', params, {
+ cwd: module.cwd,
+ }, cb)
}
export function disk_usage(opt, cb) {
- if (!opt.module || ! modules[opt.module]) {
- cb([])
- }
- const module = modules[opt.module]
- const dir = path.join(module.cwd, opt.dir.replace(/\.\.?\//g, ''))
+ const dir = module_dir(opt, opt.dir)
+ if (!dir) return cb([])
execFile('du', ['-d', 1, dir], cb)
}