1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06: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)
@staticmethod
def scan(uid, scanner):
def scan(uid, scanner, progress_callback = None):
status, folder = FolderManager.get(uid)
if status != FolderManager.SUCCESS:
return status
scanner.scan(folder)
scanner.scan(folder, progress_callback)
scanner.prune(folder)
scanner.check_cover_art(folder)
return FolderManager.SUCCESS

View File

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