utils: Switch to exceptions.FindError for errors.
This commit is contained in:
parent
5015a7ff28
commit
2c3217685b
@ -24,6 +24,12 @@ class ExtensionError(MopidyException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FindError(MopidyException):
|
||||||
|
def __init__(self, message, errno=None):
|
||||||
|
super(FindError, self).__init__(message, errno)
|
||||||
|
self.errno = errno
|
||||||
|
|
||||||
|
|
||||||
class FrontendError(MopidyException):
|
class FrontendError(MopidyException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import urlparse
|
|||||||
|
|
||||||
import glib
|
import glib
|
||||||
|
|
||||||
from mopidy import compat
|
from mopidy import compat, exceptions
|
||||||
from mopidy.compat import queue
|
from mopidy.compat import queue
|
||||||
|
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ def _find_worker(relative, follow, done, work, results, errors):
|
|||||||
st = os.lstat(entry)
|
st = os.lstat(entry)
|
||||||
|
|
||||||
if (st.st_dev, st.st_ino) in parents:
|
if (st.st_dev, st.st_ino) in parents:
|
||||||
errors[path] = Exception('Sym/hardlink loop found.')
|
errors[path] = exceptions.FindError('Sym/hardlink loop found.')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
parents = parents + [(st.st_dev, st.st_ino)]
|
parents = parents + [(st.st_dev, st.st_ino)]
|
||||||
@ -150,12 +150,12 @@ def _find_worker(relative, follow, done, work, results, errors):
|
|||||||
elif stat.S_ISREG(st.st_mode):
|
elif stat.S_ISREG(st.st_mode):
|
||||||
results[path] = st
|
results[path] = st
|
||||||
elif stat.S_ISLNK(st.st_mode):
|
elif stat.S_ISLNK(st.st_mode):
|
||||||
errors[path] = Exception('Not following symlinks.')
|
errors[path] = exceptions.FindError('Not following symlinks.')
|
||||||
else:
|
else:
|
||||||
errors[path] = Exception('Not a file or directory.')
|
errors[path] = exceptions.FindError('Not a file or directory.')
|
||||||
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
errors[path] = e
|
errors[path] = exceptions.FindError(e.strerror, e.errno)
|
||||||
finally:
|
finally:
|
||||||
work.task_done()
|
work.task_done()
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,16 @@ class ExceptionsTest(unittest.TestCase):
|
|||||||
self.assert_(issubclass(
|
self.assert_(issubclass(
|
||||||
exceptions.ExtensionError, exceptions.MopidyException))
|
exceptions.ExtensionError, exceptions.MopidyException))
|
||||||
|
|
||||||
|
def test_find_error_is_a_mopidy_exception(self):
|
||||||
|
self.assert_(issubclass(
|
||||||
|
exceptions.FindError, exceptions.MopidyException))
|
||||||
|
|
||||||
|
def test_find_error_can_store_an_errno(self):
|
||||||
|
exc = exceptions.FindError('msg', errno=1234)
|
||||||
|
|
||||||
|
self.assertEqual(exc.message, 'msg')
|
||||||
|
self.assertEqual(exc.errno, 1234)
|
||||||
|
|
||||||
def test_frontend_error_is_a_mopidy_exception(self):
|
def test_frontend_error_is_a_mopidy_exception(self):
|
||||||
self.assert_(issubclass(
|
self.assert_(issubclass(
|
||||||
exceptions.FrontendError, exceptions.MopidyException))
|
exceptions.FrontendError, exceptions.MopidyException))
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import unittest
|
|||||||
|
|
||||||
import glib
|
import glib
|
||||||
|
|
||||||
from mopidy import compat
|
from mopidy import compat, exceptions
|
||||||
from mopidy.utils import path
|
from mopidy.utils import path
|
||||||
|
|
||||||
import tests
|
import tests
|
||||||
@ -242,7 +242,7 @@ class FindMTimesTest(unittest.TestCase):
|
|||||||
missing = os.path.join(self.tmpdir, 'does-not-exist')
|
missing = os.path.join(self.tmpdir, 'does-not-exist')
|
||||||
result, errors = path.find_mtimes(missing)
|
result, errors = path.find_mtimes(missing)
|
||||||
self.assertEqual(result, {})
|
self.assertEqual(result, {})
|
||||||
self.assertEqual(errors, {missing: tests.IsA(OSError)})
|
self.assertEqual(errors, {missing: tests.IsA(exceptions.FindError)})
|
||||||
|
|
||||||
def test_empty_dir(self):
|
def test_empty_dir(self):
|
||||||
"""Empty directories should not show up in results"""
|
"""Empty directories should not show up in results"""
|
||||||
@ -295,7 +295,7 @@ class FindMTimesTest(unittest.TestCase):
|
|||||||
|
|
||||||
result, errors = path.find_mtimes(self.tmpdir)
|
result, errors = path.find_mtimes(self.tmpdir)
|
||||||
self.assertEqual({}, result)
|
self.assertEqual({}, result)
|
||||||
self.assertEqual({directory: tests.IsA(OSError)}, errors)
|
self.assertEqual({directory: tests.IsA(exceptions.FindError)}, errors)
|
||||||
|
|
||||||
def test_symlinks_are_ignored(self):
|
def test_symlinks_are_ignored(self):
|
||||||
"""By default symlinks should be treated as an error"""
|
"""By default symlinks should be treated as an error"""
|
||||||
@ -305,7 +305,7 @@ class FindMTimesTest(unittest.TestCase):
|
|||||||
|
|
||||||
result, errors = path.find_mtimes(self.tmpdir)
|
result, errors = path.find_mtimes(self.tmpdir)
|
||||||
self.assertEqual(result, {target: tests.any_int})
|
self.assertEqual(result, {target: tests.any_int})
|
||||||
self.assertEqual(errors, {link: tests.IsA(Exception)})
|
self.assertEqual(errors, {link: tests.IsA(exceptions.FindError)})
|
||||||
|
|
||||||
def test_symlink_to_file_as_root_is_followed(self):
|
def test_symlink_to_file_as_root_is_followed(self):
|
||||||
"""Passing a symlink as the root should be followed when follow=True"""
|
"""Passing a symlink as the root should be followed when follow=True"""
|
||||||
@ -327,7 +327,7 @@ class FindMTimesTest(unittest.TestCase):
|
|||||||
|
|
||||||
result, errors = path.find_mtimes(link, follow=True)
|
result, errors = path.find_mtimes(link, follow=True)
|
||||||
self.assertEqual({}, result)
|
self.assertEqual({}, result)
|
||||||
self.assertEqual({link: tests.IsA(OSError)}, errors)
|
self.assertEqual({link: tests.IsA(exceptions.FindError)}, errors)
|
||||||
|
|
||||||
def test_symlink_pointing_at_parent_fails(self):
|
def test_symlink_pointing_at_parent_fails(self):
|
||||||
"""We should detect a loop via the parent and give up on the branch"""
|
"""We should detect a loop via the parent and give up on the branch"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user