fix Windows path manipulation in importfeeds

This commit is contained in:
Adrian Sampson 2014-04-18 15:52:23 -07:00
parent 81d04643bf
commit 5f4a9c6446
3 changed files with 12 additions and 7 deletions

View file

@ -101,9 +101,13 @@ def _record_items(lib, basename, items):
if config['importfeeds']['absolute_path']:
paths.append(item.path)
else:
paths.append(os.path.relpath(
item.path, relative_to
))
try:
relpath = os.path.relpath(item.path, relative_to)
except ValueError:
# On Windows, it is sometimes not possible to construct a
# relative path (if the files are on different disks).
relpath = item.path
paths.append(relpath)
if 'm3u' in formats:
basename = bytestring_path(

View file

@ -9,4 +9,4 @@ ignore=E241,E221
# List of files that have not been cleand up yet. We will try to reduce
# this with each commit
exclude=test/test_config_command.py,test/test_files.py,test/test_art.py,test/test_dbcore.py,test/test_web.py,test/test_zero.py,test/rsrc/beetsplug/test.py,test/test_template.py,test/test_importfeeds.py,test/test_echonest.py,test/test_datequery.py,test/test_mb.py,test/test_convert.py,test/testall.py,test/test_player.py,test/test_query.py,test/test_mediafile.py,test/test_keyfinder.py,test/test_the.py,test/test_library.py,test/test_lyrics.py,test/test_ihate.py,test/test_vfs.py,test/test_replaygain.py,test/__init__.py,test/_common.py,test/test_mediafile_edge.py,test/test_ui.py
exclude=test/test_config_command.py,test/test_files.py,test/test_art.py,test/test_dbcore.py,test/test_web.py,test/test_zero.py,test/rsrc/beetsplug/test.py,test/test_template.py,test/test_echonest.py,test/test_datequery.py,test/test_mb.py,test/test_convert.py,test/testall.py,test/test_player.py,test/test_query.py,test/test_mediafile.py,test/test_keyfinder.py,test/test_the.py,test/test_library.py,test/test_lyrics.py,test/test_ihate.py,test/test_vfs.py,test/test_replaygain.py,test/__init__.py,test/_common.py,test/test_mediafile_edge.py,test/test_ui.py

View file

@ -16,14 +16,15 @@ class ImportfeedsTestTest(unittest.TestCase):
self.lib = Library(':memory:')
self.feeds_dir = tempfile.mkdtemp()
config['importfeeds']['dir'] = self.feeds_dir
def tearDown(self):
shutil.rmtree(self.feeds_dir)
def test_multi_format_album_playlist(self):
config['importfeeds']['formats'] = 'm3u_multi'
album = Album(album='album/name', id=1)
item = Item(title='song', album_id=1, path='/path/to/item')
item_path = os.path.join('path', 'to', 'item')
item = Item(title='song', album_id=1, path=item_path)
self.lib.add(album)
self.lib.add(item)
@ -32,7 +33,7 @@ class ImportfeedsTestTest(unittest.TestCase):
os.listdir(self.feeds_dir)[0])
self.assertTrue(playlist_path.endswith('album_name.m3u'))
with open(playlist_path) as playlist:
self.assertIn('/path/to/item', playlist.read())
self.assertIn(item_path, playlist.read())
def suite():