1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Scanner: added a callback interface to report progress

This commit is contained in:
spl0k 2014-01-14 14:39:03 +01:00
parent faacf40008
commit 6f506243d7
2 changed files with 13 additions and 8 deletions

View File

@ -86,12 +86,12 @@ class FolderManager:
return FolderManager.delete(folder.id) return FolderManager.delete(folder.id)
@staticmethod @staticmethod
def scan(uid, scanner): def scan(uid, scanner, progress_callback = None):
status, folder = FolderManager.get(uid) status, folder = FolderManager.get(uid)
if status != FolderManager.SUCCESS: if status != FolderManager.SUCCESS:
return status return status
scanner.scan(folder) scanner.scan(folder, progress_callback)
scanner.prune(folder) scanner.prune(folder)
scanner.check_cover_art(folder) scanner.check_cover_art(folder)
return FolderManager.SUCCESS return FolderManager.SUCCESS

View File

@ -25,12 +25,17 @@ class Scanner:
extensions = config.get('base', 'scanner_extensions') extensions = config.get('base', 'scanner_extensions')
self.__extensions = map(str.lower, extensions.split()) if extensions else None self.__extensions = map(str.lower, extensions.split()) if extensions else None
def scan(self, folder): def scan(self, folder, progress_callback = None):
for root, subfolders, files in os.walk(folder.path): files = [ os.path.join(root, f) for root, _, fs in os.walk(folder.path) for f in fs if self.__is_valid_path(os.path.join(root, f)) ]
for f in files: total = len(files)
path = os.path.join(root, f) current = 0
if self.__is_valid_path(path):
self.__scan_file(path, folder) for path in files:
self.__scan_file(path, folder)
current += 1
if progress_callback:
progress_callback(current, total)
folder.last_scan = int(time.time()) folder.last_scan = int(time.time())
def prune(self, folder): def prune(self, folder):