diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-20 12:26:50 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-20 12:26:50 +0200 |
| commit | d13f1cf7ea9853a0afc9baba2a7019369dbd934d (patch) | |
| tree | 626c6e8ba0962f6de4c053ddffea3a6e8b8e036a /app/relay | |
| parent | 439fa5d16810a8872bbaf764f5777124001616a4 (diff) | |
new sequence thing
Diffstat (limited to 'app/relay')
| -rw-r--r-- | app/relay/runner.js | 84 |
1 files changed, 66 insertions, 18 deletions
diff --git a/app/relay/runner.js b/app/relay/runner.js index 54f5a94..361fecc 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' @@ -140,8 +141,8 @@ export function run_system_command(cmd, cb) { case 'du': disk_usage(cmd, cb) break - case 'list_results': - list_results(cmd, cb) + case 'list_sequences': + list_sequences(cmd, cb) break case 'dir_to_video': dir_to_video(cmd, cb) @@ -152,15 +153,21 @@ 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, '')) + const dir = path.join(module.cwd, dir.replace(/\.\.?\//g, '')) + return dir +} + +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 +184,76 @@ 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) => { + 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, + dir: f, + frame: null, + count: 0, + } + readdir(path.join(root_dir, f.name)).then(files => { + const middle_file = files[Math.floor(files.length/2)] + const filePromises = [] + filePromises.push(stat_promise(path.join(root_dir, f.name, middle_file))) + sequence.count = files.length + return Promise.all(filePromises) + }).then(stats => { + if (stats.length) { + sequence.frame = { + prefix: middle_file.split('_')[0] + 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) } |
