mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
Properly close database connections when they're not in use
Watcher Closes #253
This commit is contained in:
parent
32a74706c2
commit
abe0b79968
@ -14,7 +14,7 @@ from watchdog.observers import Observer
|
|||||||
from watchdog.events import PatternMatchingEventHandler
|
from watchdog.events import PatternMatchingEventHandler
|
||||||
|
|
||||||
from . import covers
|
from . import covers
|
||||||
from .db import Folder
|
from .db import Folder, open_connection, close_connection
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
|
|
||||||
OP_SCAN = 1
|
OP_SCAN = 1
|
||||||
@ -45,17 +45,10 @@ class SupysonicWatcherEventHandler(PatternMatchingEventHandler):
|
|||||||
logger.debug("File created: '%s'", event.src_path)
|
logger.debug("File created: '%s'", event.src_path)
|
||||||
|
|
||||||
op = OP_SCAN | FLAG_CREATE
|
op = OP_SCAN | FLAG_CREATE
|
||||||
if not covers.is_valid_cover(event.src_path):
|
if covers.is_valid_cover(event.src_path):
|
||||||
|
op |= FLAG_COVER
|
||||||
self.queue.put(event.src_path, op)
|
self.queue.put(event.src_path, op)
|
||||||
|
|
||||||
dirname = os.path.dirname(event.src_path)
|
|
||||||
try:
|
|
||||||
Folder.get(path=dirname)
|
|
||||||
except Folder.DoesNotExist:
|
|
||||||
self.queue.put(dirname, op | FLAG_COVER)
|
|
||||||
else:
|
|
||||||
self.queue.put(event.src_path, op | FLAG_COVER)
|
|
||||||
|
|
||||||
def on_deleted(self, event):
|
def on_deleted(self, event):
|
||||||
logger.debug("File deleted: '%s'", event.src_path)
|
logger.debug("File deleted: '%s'", event.src_path)
|
||||||
|
|
||||||
@ -154,6 +147,7 @@ class ScannerProcessingQueue(Thread):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
logger.debug("Instantiating scanner")
|
logger.debug("Instantiating scanner")
|
||||||
|
open_connection()
|
||||||
scanner = Scanner()
|
scanner = Scanner()
|
||||||
|
|
||||||
item = self.__next_item()
|
item = self.__next_item()
|
||||||
@ -166,6 +160,7 @@ class ScannerProcessingQueue(Thread):
|
|||||||
item = self.__next_item()
|
item = self.__next_item()
|
||||||
|
|
||||||
scanner.prune()
|
scanner.prune()
|
||||||
|
close_connection()
|
||||||
logger.debug("Freeing scanner")
|
logger.debug("Freeing scanner")
|
||||||
|
|
||||||
def __process_regular_item(self, scanner, item):
|
def __process_regular_item(self, scanner, item):
|
||||||
|
Loading…
Reference in New Issue
Block a user