From: Simeon Veldstra Date: Mon, 5 Feb 2007 00:58:17 +0000 (-0800) Subject: Added --update patch from Mark J. Hewitt X-Git-Tag: v0.5.9 X-Git-Url: http://puddle.ca/cgi-bin/gitweb.cgi?p=mp3togo;a=commitdiff;h=5ef762a453aaac9acacc3e5b126ecd1534fea409 Added --update patch from Mark J. Hewitt Signed-off-by: Simeon Veldstra --- --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mp3togo (0.5.9) unstable; urgency=low + + * Added -u update switch for conditional --force. Thanks Mark J. Hewitt. + + -- Simeon Veldstra Sun, 4 Feb 2007 16:38:54 -0800 + mp3togo (0.5.8) unstable; urgency=low * Fixed failure when converting flac with no GENRE tag --- a/debian/mp3togo.1 +++ b/debian/mp3togo.1 @@ -134,4 +134,4 @@ License can be found in /usr/share/commo .PP mp3togo can be found online at http://puddle.ca/mp3togo -.\" created by instant / docbook-to-man, Sun 05 Nov 2006, 16:36 +.\" created by instant / docbook-to-man, Sun 04 Feb 2007, 16:42 --- a/mp3togo/__init__.py +++ b/mp3togo/__init__.py @@ -21,5 +21,5 @@ # __all__ = ('converter', 'main', 'options', 'setup') -version = '0.5.8' +version = '0.5.9' --- a/mp3togo/conf.py +++ b/mp3togo/conf.py @@ -98,6 +98,8 @@ class Options(options.Options): ('maxtempsize', '', '', 0L, None, ''), ('force', 'F', 'force', False, None, '''Overwrite files if they already exist.'''), + ('update', 'u', 'update', False, None, + '''Overwrite files if they already exist only if they are older than the source file.'''), ('encoder', 'C', 'encoder', 'lame', None, '''The encoder to use to create the output files. Options are wav, lame or oggenc.'''), ('encopts', 'E', 'encoder-options', '', None, --- a/mp3togo/track.py +++ b/mp3togo/track.py @@ -252,16 +252,42 @@ class Track: tasks.append(job) del job - # Consider the track done if the output file exists: - if os.path.exists(self._outname) and not opts['force']: - opts.log(1, "Skipping existing file: %s\n" % self._outname) - self._queue = tuple(tasks) - if self._hash and self._cache: - self._cache.release(self._hash) - for tsk in self._queue: - tsk._status = task.DONE - self._state = DONE - return + ## Consider the track done if the output file exists: + #if os.path.exists(self._outname) and not opts['force']: + # opts.log(1, "Skipping existing file: %s\n" % self._outname) + # self._queue = tuple(tasks) + # if self._hash and self._cache: + # self._cache.release(self._hash) + # for tsk in self._queue: + # tsk._status = task.DONE + # self._state = DONE + # return + if not opts['force']: + if os.path.exists(self._outname): + # In update mode, consider the track done if an existing file is older than the source + if opts['update']: + sourceinfo = os.stat(self._filename) + targetinfo = os.stat(self._outname) + if targetinfo.st_mtime >= sourceinfo.st_mtime: + opts.log(1, "Skipping up to date file: %s\n" % self._outname) + self._queue = tuple(tasks) + if self._hash and self._cache: + self._cache.release(self._hash) + for tsk in self._queue: + tsk._status = task.DONE + self._state = DONE + return + else: + opts.log(1, "Replacing out of date file: %s\n" % self._outname) + else: # Consider the track done if the output file exists: + opts.log(1, "Skipping existing file: %s\n" % self._outname) + self._queue = tuple(tasks) + if self._hash and self._cache: + self._cache.release(self._hash) + for tsk in self._queue: + tsk._status = task.DONE + self._state = DONE + return # Ready to go self._queue = tuple(tasks) @@ -285,4 +311,3 @@ class Track: child._parent = None self._queue = () -