From 55a31cb3dd1e128b951087e8906d7ab1a8d3c584 Mon Sep 17 00:00:00 2001 From: Daniel Bohannon Date: Tue, 27 Jan 2015 12:21:56 -0800 Subject: [PATCH] updated commands; added db setup; created suites --- lib/commands.coffee | 81 +++++++++++++++++++++++---------------------- lib/dirs.coffee | 16 +++++++++ lib/media.coffee | 31 ++++++++++++++++- 3 files changed, 87 insertions(+), 41 deletions(-) diff --git a/lib/commands.coffee b/lib/commands.coffee index 2cf67de..37b0240 100644 --- a/lib/commands.coffee +++ b/lib/commands.coffee @@ -11,46 +11,26 @@ async = require 'async' program.version(pkg.version) program.command('clean') - .description('Let\'s tidy up those media files!') + .description('Let\'s tidy up those media files and directories!') .action () -> - media = new Media + config = new Config dirs = new Dirs + media = new Media # Perform action in series with async async.series [ - # Clean files - (callback) -> - media.addFiles -> - callback() - (callback) -> - media.fileExists -> - callback() - (callback) -> - media.fileMetaUpdate -> - callback() - (callback) -> - media.deleteCorrupt -> - callback() + # Ensure db is setup (callback) -> - media.deleteSamples -> - callback() - (callback) -> - media.deleteOthers -> + config.setup -> callback() + # Clean files (callback) -> - media.deleteDupes -> + media.suite -> callback() - # Clean dirs (callback) -> - dirs.addDirs -> - callback() - (callback) -> - dirs.dirExists -> - callback() - (callback) -> - dirs.deleteEmptyDirs -> + dirs.suite -> callback() ], (err, results) -> throw err if err @@ -59,21 +39,36 @@ program.command('clean') program.command('clean-dirs') .description('Let\'s tidy up those media directories!') .action () -> + config = new Config dirs = new Dirs async.series [ (callback) -> - dirs.addDirs -> + config.setup -> + callback() + (callback) -> + dirs.suite -> callback() + ], (err, results) -> + throw err if err + console.log 'Your media directories are looking mighty tidy!' + +program.command('clean-files') + .description('Let\'s tidy up those media files!') + .action () -> + config = new Config + media = new Media + + async.series [ (callback) -> - dirs.dirExists -> + config.setup -> callback() (callback) -> - dirs.deleteEmptyDirs -> + media.suite -> callback() ], (err, results) -> throw err if err - console.log 'Your media directories are looking mighty tidy!' + console.log 'Your media files are looking mighty tidy!' program .command('add-paths') @@ -82,12 +77,12 @@ program config = new Config async.series [ - (seriesCallback) -> + (callback) -> config.setup -> - seriesCallback() - (seriesCallback) -> + callback() + (callback) -> config.pathPrompt -> - seriesCallback() + callback() ], (err, results) -> throw err if err console.log 'Media path add complete.' @@ -99,9 +94,12 @@ program config = new Config async.series [ - (seriesCallback) -> + (callback) -> + config.setup -> + callback() + (callback) -> config.pathsDelete -> - seriesCallback() + callback() ], (err, results) -> throw err if err console.log 'All media paths have been removed from mediatidy.' @@ -113,9 +111,12 @@ program config = new Config async.series [ - (seriesCallback) -> + (callback) -> + config.setup -> + callback() + (callback) -> config.filesDelete -> - seriesCallback() + callback() ], (err, results) -> throw err if err console.log 'All file data has been removed from mediatidy database.' diff --git a/lib/dirs.coffee b/lib/dirs.coffee index 70312a0..01e4c27 100644 --- a/lib/dirs.coffee +++ b/lib/dirs.coffee @@ -154,4 +154,20 @@ class Dirs extends Database console.log "No directories needed to be deleted..." callback() + suite: (callback) -> + # Runs full suite of directory cleanup commands + async.series [ + (callback) => + @addDirs => + callback() + (callback) => + @dirExists => + callback() + (callback) => + @deleteEmptyDirs => + callback() + ], (err, results) => + throw err if err + callback results + module.exports = Dirs diff --git a/lib/media.coffee b/lib/media.coffee index 9c1f451..2444e32 100755 --- a/lib/media.coffee +++ b/lib/media.coffee @@ -36,7 +36,7 @@ class Media extends Database @dbBulkPathGet '\'MEDIA\'', (array) => if array.length is 0 console.log "No paths have been added to mediatidy. Add paths to your media files with", - "\"mediatidy paths-update\"".red + "\"mediatidy add-paths\"".red else # get files asynchronously for each 'MEDIA' path async.eachSeries array, ((basePath, seriesCallback) => @@ -508,4 +508,33 @@ class Media extends Database # console.log 'filtered:', filteredFileName callback filteredFileName + suite: (callback) -> + # Runs full suite of directory cleanup commands + async.series [ + (callback) => + @addFiles => + callback() + (callback) => + @fileExists => + callback() + (callback) => + @fileMetaUpdate => + callback() + (callback) => + @deleteCorrupt => + callback() + (callback) => + @deleteSamples => + callback() + (callback) => + @deleteOthers => + callback() + (callback) => + @deleteDupes => + callback() + ], (err, results) => + throw err if err + callback results + + module.exports = Media