mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Added basic file move support
This commit is contained in:
parent
429fdcf954
commit
f61a3a7937
@ -62,18 +62,19 @@ class SupysonicWatcherEventHandler(PatternMatchingEventHandler):
|
|||||||
|
|
||||||
def on_moved(self, event):
|
def on_moved(self, event):
|
||||||
self.__logger.debug("File moved: '%s' -> '%s'", event.src_path, event.dest_path)
|
self.__logger.debug("File moved: '%s' -> '%s'", event.src_path, event.dest_path)
|
||||||
self.__queue.put(event.src_path, OP_MOVE)
|
self.__queue.put(event.src_path, OP_MOVE, event.dest_path)
|
||||||
|
|
||||||
class Event(object):
|
class Event(object):
|
||||||
def __init__(self, path, operation):
|
def __init__(self, path, operation, dst_path = None):
|
||||||
if operation & (OP_SCAN | OP_REMOVE) == (OP_SCAN | OP_REMOVE):
|
if operation & (OP_SCAN | OP_REMOVE) == (OP_SCAN | OP_REMOVE):
|
||||||
raise Exception("Flags SCAN and REMOVE both set")
|
raise Exception("Flags SCAN and REMOVE both set")
|
||||||
|
|
||||||
self.__path = path
|
self.__path = path
|
||||||
self.__time = time.time()
|
self.__time = time.time()
|
||||||
self.__op = operation
|
self.__op = operation
|
||||||
|
self.__dst = dst_path
|
||||||
|
|
||||||
def set(self, operation):
|
def set(self, operation, dst_path = None):
|
||||||
if operation & (OP_SCAN | OP_REMOVE) == (OP_SCAN | OP_REMOVE):
|
if operation & (OP_SCAN | OP_REMOVE) == (OP_SCAN | OP_REMOVE):
|
||||||
raise Exception("Flags SCAN and REMOVE both set")
|
raise Exception("Flags SCAN and REMOVE both set")
|
||||||
|
|
||||||
@ -84,6 +85,9 @@ class Event(object):
|
|||||||
self.__op &= ~OP_SCAN
|
self.__op &= ~OP_SCAN
|
||||||
self.__op |= operation
|
self.__op |= operation
|
||||||
|
|
||||||
|
if dst_path:
|
||||||
|
self.__dst = dst_path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
return self.__path
|
return self.__path
|
||||||
@ -96,6 +100,10 @@ class Event(object):
|
|||||||
def operation(self):
|
def operation(self):
|
||||||
return self.__op
|
return self.__op
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dst_path(self):
|
||||||
|
return self.__dst
|
||||||
|
|
||||||
class ScannerProcessingQueue(Thread):
|
class ScannerProcessingQueue(Thread):
|
||||||
def __init__(self, logger):
|
def __init__(self, logger):
|
||||||
super(ScannerProcessingQueue, self).__init__()
|
super(ScannerProcessingQueue, self).__init__()
|
||||||
@ -128,6 +136,9 @@ class ScannerProcessingQueue(Thread):
|
|||||||
|
|
||||||
item = self.__next_item()
|
item = self.__next_item()
|
||||||
while item:
|
while item:
|
||||||
|
if item.operation & OP_MOVE:
|
||||||
|
self.__logger.info("Moving: '%s' -> '%s'", item.path, item.dst_path)
|
||||||
|
scanner.move_file(item.path, item.dst_path)
|
||||||
if item.operation & OP_SCAN:
|
if item.operation & OP_SCAN:
|
||||||
self.__logger.info("Scanning: '%s'", item.path)
|
self.__logger.info("Scanning: '%s'", item.path)
|
||||||
scanner.scan_file(item.path)
|
scanner.scan_file(item.path)
|
||||||
@ -147,15 +158,15 @@ class ScannerProcessingQueue(Thread):
|
|||||||
with self.__cond:
|
with self.__cond:
|
||||||
self.__cond.notify()
|
self.__cond.notify()
|
||||||
|
|
||||||
def put(self, path, operation):
|
def put(self, path, operation, *args):
|
||||||
if not self.__running:
|
if not self.__running:
|
||||||
raise RuntimeError("Trying to put an item in a stopped queue")
|
raise RuntimeError("Trying to put an item in a stopped queue")
|
||||||
|
|
||||||
with self.__cond:
|
with self.__cond:
|
||||||
if path in self.__queue:
|
if path in self.__queue:
|
||||||
self.__queue[path].set(operation)
|
self.__queue[path].set(operation, *args)
|
||||||
else:
|
else:
|
||||||
self.__queue[path] = Event(path, operation)
|
self.__queue[path] = Event(path, operation, *args)
|
||||||
|
|
||||||
if self.__timer:
|
if self.__timer:
|
||||||
self.__timer.cancel()
|
self.__timer.cancel()
|
||||||
|
@ -159,6 +159,24 @@ class Scanner:
|
|||||||
self.__store.remove(tr)
|
self.__store.remove(tr)
|
||||||
self.__deleted_tracks += 1
|
self.__deleted_tracks += 1
|
||||||
|
|
||||||
|
def move_file(self, src_path, dst_path):
|
||||||
|
tr = self.__store.find(Track, Track.path == src_path).one()
|
||||||
|
if not tr:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.__folders_to_check.add(tr.folder)
|
||||||
|
tr_dst = self.__store.find(Track, Track.path == dst_path).one()
|
||||||
|
if tr_dst:
|
||||||
|
tr.root_folder = tr_dst.root_folder
|
||||||
|
tr.folder = tr_dst.folder
|
||||||
|
self.remove_file(dst_path)
|
||||||
|
else:
|
||||||
|
root = self.__find_root_folder(dst_path)
|
||||||
|
folder = self.__find_folder(dst_path)
|
||||||
|
tr.root_folder = root
|
||||||
|
tr.folder = folder
|
||||||
|
tr.path = dst_path
|
||||||
|
|
||||||
def __find_album(self, artist, album):
|
def __find_album(self, artist, album):
|
||||||
ar = self.__find_artist(artist)
|
ar = self.__find_artist(artist)
|
||||||
al = ar.albums.find(name = album).one()
|
al = ar.albums.find(name = album).one()
|
||||||
|
Loading…
Reference in New Issue
Block a user