From 03ef79ec847ea70fe86ad3107e09fb204b28cbaa Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sat, 25 Apr 2009 16:06:23 +0000 Subject: [PATCH] * morituri/image/cue.py: getRealPath should be here, it doesn't need anything outside the .cue file * morituri/image/image.py: Proxy it here. --- ChangeLog | 8 ++++++++ morituri/image/cue.py | 33 +++++++++++++++++++++++++++++++++ morituri/image/image.py | 27 +-------------------------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5dc800a..1cd3d32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-04-25 Thomas Vander Stichele + + * morituri/image/cue.py: + getRealPath should be here, it doesn't need anything outside + the .cue file + * morituri/image/image.py: + Proxy it here. + 2009-04-25 Thomas Vander Stichele * morituri/common/checksum.py: diff --git a/morituri/image/cue.py b/morituri/image/cue.py index 3a99499..b562975 100644 --- a/morituri/image/cue.py +++ b/morituri/image/cue.py @@ -26,6 +26,7 @@ Reading .cue files See http://digitalx.org/cuesheetsyntax.php """ +import os import re _REM_RE = re.compile("^REM\s(\w+)\s(.*)$") @@ -147,6 +148,38 @@ class Cue: # FIXME: more logic return -1 + def getRealPath(self, path): + """ + Translate the .cue's FILE to an existing path. + """ + if os.path.exists(path): + return path + + # .cue FILE statements have Windows-style path separators, so convert + tpath = os.path.join(*path.split('\\')) + candidatePaths = [] + + # if the path is relative: + # - check relatively to the cue file + # - check only the filename part relative to the cue file + if tpath == os.path.abspath(tpath): + candidatePaths.append(tPath) + else: + candidatePaths.append(os.path.join( + os.path.dirname(self._path), tpath)) + candidatePaths.append(os.path.join( + os.path.dirname(self._path), os.path.basename(tpath))) + + for candidate in candidatePaths: + noext, _ = os.path.splitext(candidate) + for ext in ['wav', 'flac']: + cpath = '%s.%s' % (noext, ext) + if os.path.exists(cpath): + return cpath + + raise KeyError, "Cannot find file for %s" % path + + class File: """ I represent a FILE line in a cue file. diff --git a/morituri/image/image.py b/morituri/image/image.py index 812bae8..73062a5 100644 --- a/morituri/image/image.py +++ b/morituri/image/image.py @@ -47,32 +47,7 @@ class Image: """ Translate the .cue's FILE to an existing path. """ - if os.path.exists(path): - return path - - # .cue FILE statements have Windows-style path separators, so convert - tpath = os.path.join(*path.split('\\')) - candidatePaths = [] - - # if the path is relative: - # - check relatively to the cue file - # - check only the filename part relative to the cue file - if tpath == os.path.abspath(tpath): - candidatePaths.append(tPath) - else: - candidatePaths.append(os.path.join( - os.path.dirname(self._path), tpath)) - candidatePaths.append(os.path.join( - os.path.dirname(self._path), os.path.basename(tpath))) - - for candidate in candidatePaths: - noext, _ = os.path.splitext(candidate) - for ext in ['wav', 'flac']: - cpath = '%s.%s' % (noext, ext) - if os.path.exists(cpath): - return cpath - - raise KeyError, "Cannot find file for %s" % path + return self.cue.getRealPath(path) def setup(self, runner): """