1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Merge branch 'dependencies'

This commit is contained in:
Alban Féron 2019-07-13 17:09:56 +02:00
commit 8a3ea151cc
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
4 changed files with 9 additions and 18 deletions

View File

@ -20,7 +20,7 @@ reqs = [
"Pillow", "Pillow",
"requests>=1.0.0", "requests>=1.0.0",
"mutagen>=1.33", "mutagen>=1.33",
"scandir<2.0.0", "scandir<2.0.0; python_version <= '2.7'",
"watchdog>=0.8.0", "watchdog>=0.8.0",
"zipstream", "zipstream",
] ]

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)