Skip to content

Commit

Permalink
updated commands; added db setup; created suites
Browse files Browse the repository at this point in the history
  • Loading branch information
danb235 committed Jan 27, 2015
1 parent 9d99395 commit 55a31cb
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 41 deletions.
81 changes: 41 additions & 40 deletions lib/commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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.'
Expand All @@ -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.'
Expand All @@ -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.'
Expand Down
16 changes: 16 additions & 0 deletions lib/dirs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 30 additions & 1 deletion lib/media.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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

0 comments on commit 55a31cb

Please sign in to comment.