1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Don't use DirEntry

This commit is contained in:
Alban Féron 2019-07-13 15:12:37 +02:00
parent acf7e32ea5
commit cf3e03a1e7
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
3 changed files with 8 additions and 17 deletions

View File

@ -10,9 +10,9 @@
# Try built-in scandir, fall back to the package for Python 2.7 # Try built-in scandir, fall back to the package for Python 2.7
try: try:
from os import scandir, DirEntry from os import scandir
except ImportError: 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 # os.replace was added in Python 3.3, provide a fallback for Python 2.7
try: try:

View File

@ -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 Folder, Artist, Album, Track, User
from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack
from .db import RatingFolder, RatingTrack from .db import RatingFolder, RatingTrack
from .py23 import scandir, strtype, DirEntry, Queue, QueueEmpty from .py23 import scandir, strtype, Queue, QueueEmpty
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -194,16 +194,7 @@ class Scanner(Thread):
@db_session @db_session
def scan_file(self, path_or_direntry): def scan_file(self, path_or_direntry):
if not isinstance(path_or_direntry, (strtype, DirEntry)): if isinstance(path_or_direntry, strtype):
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:
path = path_or_direntry path = path_or_direntry
if not os.path.exists(path): if not os.path.exists(path):
@ -211,6 +202,10 @@ class Scanner(Thread):
basename = os.path.basename(path) basename = os.path.basename(path)
stat = os.stat(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) mtime = int(stat.st_mtime)
size = stat.st_size size = stat.st_size

View File

@ -72,10 +72,6 @@ class ScannerTestCase(unittest.TestCase):
@db_session @db_session
def test_scan_file(self): 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") self.scanner.scan_file("/some/inexistent/path")
commit() commit()
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)