* morituri/image/cue.py:

getRealPath should be here, it doesn't need anything outside
	  the .cue file
	* morituri/image/image.py:
	  Proxy it here.
This commit is contained in:
Thomas Vander Stichele
2009-04-25 16:06:23 +00:00
parent 10e5ec0b18
commit 03ef79ec84
3 changed files with 42 additions and 26 deletions

View File

@@ -1,3 +1,11 @@
2009-04-25 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <thomas at apestaart dot org>
* morituri/common/checksum.py:

View File

@@ -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.

View File

@@ -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):
"""