diff --git a/setup.py b/setup.py index acbdb79..d405399 100755 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ reqs = [ "Pillow", "requests>=1.0.0", "mutagen>=1.33", - "scandir<2.0.0", + "scandir<2.0.0; python_version <= '2.7'", "watchdog>=0.8.0", "zipstream", ] diff --git a/supysonic/py23.py b/supysonic/py23.py index 982b154..653f7aa 100644 --- a/supysonic/py23.py +++ b/supysonic/py23.py @@ -10,9 +10,9 @@ # Try built-in scandir, fall back to the package for Python 2.7 try: - from os import scandir, DirEntry + from os import scandir except ImportError: - from scandir import scandir, DirEntry + from scandir import scandir # os.replace was added in Python 3.3, provide a fallback for Python 2.7 try: diff --git a/supysonic/scanner.py b/supysonic/scanner.py index a15ff5d..a6ab3a7 100644 --- a/supysonic/scanner.py +++ b/supysonic/scanner.py @@ -20,7 +20,7 @@ from .covers import find_cover_in_folder, has_embedded_cover, CoverFile from .db import Folder, Artist, Album, Track, User from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack from .db import RatingFolder, RatingTrack -from .py23 import scandir, strtype, DirEntry, Queue, QueueEmpty +from .py23 import scandir, strtype, Queue, QueueEmpty logger = logging.getLogger(__name__) @@ -194,16 +194,7 @@ class Scanner(Thread): @db_session def scan_file(self, path_or_direntry): - if not isinstance(path_or_direntry, (strtype, DirEntry)): - raise TypeError( - "Expecting string or DirEntry, got " + str(type(path_or_direntry)) - ) - - if isinstance(path_or_direntry, DirEntry): - path = path_or_direntry.path - basename = path_or_direntry.name - stat = path_or_direntry.stat() - else: + if isinstance(path_or_direntry, strtype): path = path_or_direntry if not os.path.exists(path): @@ -211,6 +202,10 @@ class Scanner(Thread): basename = os.path.basename(path) stat = os.stat(path) + else: + path = path_or_direntry.path + basename = path_or_direntry.name + stat = path_or_direntry.stat() mtime = int(stat.st_mtime) size = stat.st_size diff --git a/tests/base/test_scanner.py b/tests/base/test_scanner.py index 4659949..090d038 100644 --- a/tests/base/test_scanner.py +++ b/tests/base/test_scanner.py @@ -72,10 +72,6 @@ class ScannerTestCase(unittest.TestCase): @db_session def test_scan_file(self): - track = db.Track.select().first() - self.assertRaises(TypeError, self.scanner.scan_file, None) - self.assertRaises(TypeError, self.scanner.scan_file, track) - self.scanner.scan_file("/some/inexistent/path") commit() self.assertEqual(db.Track.select().count(), 1)