From 074a0dc026216e422b66147ed2947f2e74bd7d24 Mon Sep 17 00:00:00 2001 From: spl0k Date: Fri, 28 Oct 2016 22:03:32 +0200 Subject: [PATCH] CLI: Added a '--force' option to folder scan command --- bin/supysonic-cli | 5 +++-- supysonic/scanner.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/supysonic-cli b/bin/supysonic-cli index 5c2a704..2aba005 100755 --- a/bin/supysonic-cli +++ b/bin/supysonic-cli @@ -109,6 +109,7 @@ class CLI(cmd.Cmd): folder_del_parser.add_argument('name', help = 'Name of the folder to delete') folder_scan_parser = folder_subparsers.add_parser('scan', help = 'Run a scan on specified folders', add_help = False) folder_scan_parser.add_argument('folders', metavar = 'folder', nargs = '*', help = 'Folder(s) to be scanned. If ommitted, all folders are scanned') + folder_scan_parser.add_argument('-f', '--force', action = 'store_true', help = "Force scan of already know files even if they haven't changed") def folder_list(self): print 'Name\t\tPath\n----\t\t----' @@ -128,7 +129,7 @@ class CLI(cmd.Cmd): else: print "Deleted folder '{}'".format(name) - def folder_scan(self, folders): + def folder_scan(self, folders, force): class TimedProgressDisplay: def __init__(self, name, interval = 5): @@ -141,7 +142,7 @@ class CLI(cmd.Cmd): print "Scanning '{0}': {1}% ({2}/{3})".format(self.__name, (scanned * 100) / total, scanned, total) self.__last_display = time.time() - scanner = Scanner(self.__store) + scanner = Scanner(self.__store, force) if folders: folders = map(lambda n: self.__store.find(Folder, Folder.name == n, Folder.root == True).one() or n, folders) if any(map(lambda f: isinstance(f, basestring), folders)): diff --git a/supysonic/scanner.py b/supysonic/scanner.py index 30155e3..c184054 100644 --- a/supysonic/scanner.py +++ b/supysonic/scanner.py @@ -53,8 +53,9 @@ def compile_concat(compile, concat, state): return statement % (left, right) class Scanner: - def __init__(self, store): + def __init__(self, store, force = False): self.__store = store + self.__force = force self.__added_artists = 0 self.__added_albums = 0 @@ -131,7 +132,7 @@ class Scanner: tr = self.__store.find(Track, Track.path == path).one() add = False if tr: - if not int(os.path.getmtime(path)) > tr.last_modification: + if not self.__force and not int(os.path.getmtime(path)) > tr.last_modification: return tag = self.__try_load_tag(path)