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

CLI: Added a '--force' option to folder scan command

This commit is contained in:
spl0k 2016-10-28 22:03:32 +02:00
parent 5fb98d96f5
commit 074a0dc026
2 changed files with 6 additions and 4 deletions

View File

@ -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)):

View File

@ -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)