* morituri/common/common.py:

* morituri/common/program.py:
	* morituri/image/table.py:
	* morituri/rip/cd.py:
	* morituri/test/test_common_common.py:
	* morituri/test/test_image_toc.py:
	  Handle cases where disc_template and track_template are not in
	  the same directory.
This commit is contained in:
Thomas Vander Stichele
2012-11-22 23:20:44 +00:00
parent d0435dc2ab
commit 9b4e653ae4
7 changed files with 96 additions and 23 deletions

View File

@@ -21,10 +21,14 @@
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
import os
import os.path
import math
import tempfile
import shutil
from morituri.extern.log import log
SAMPLES_PER_FRAME = 588
WORDS_PER_FRAME = SAMPLES_PER_FRAME * 2
BYTES_PER_FRAME = SAMPLES_PER_FRAME * 4
@@ -334,3 +338,28 @@ def getRealPath(refPath, filePath):
return cpath
raise KeyError("Cannot find file for %r" % filePath)
def getRelativePath(targetPath, collectionPath):
"""
Get a relative path from the directory of collectionPath to
targetPath.
Used to determine the path to use in .cue/.m3u files
"""
log.debug('common', 'getRelativePath: target %r, collection %r' % (
targetPath, collectionPath))
targetDir = os.path.dirname(targetPath)
collectionDir = os.path.dirname(collectionPath)
if targetDir == collectionDir:
log.debug('common',
'getRelativePath: target and collection in same dir')
return os.path.basename(targetPath)
else:
rel = os.path.relpath(
targetDir + os.path.sep,
collectionDir + os.path.sep)
log.debug('common',
'getRelativePath: target and collection in different dir, %r' %
rel)
return os.path.join(rel, os.path.basename(targetPath))