CC-2279: Upgrade script for converting stor directory to new format
-refactoring...
This commit is contained in:
parent
29869c175a
commit
75e56034e4
3 changed files with 10 additions and 15 deletions
|
@ -64,7 +64,7 @@ try:
|
|||
|
||||
|
||||
wm = WatchManager()
|
||||
mmc = MediaMonitorCommon(config, wm)
|
||||
mmc = MediaMonitorCommon(config)
|
||||
pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm, mmc=mmc)
|
||||
|
||||
bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc)
|
||||
|
@ -80,7 +80,7 @@ try:
|
|||
processes.append(p)
|
||||
p.start()
|
||||
|
||||
wdd = mmc.watch_directory(storage_directory)
|
||||
wdd = notifier.watch_directory(storage_directory)
|
||||
logger.info("Added watch to %s", storage_directory)
|
||||
logger.info("wdd result %s", wdd[storage_directory])
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ class AirtimeNotifier(Notifier):
|
|||
self.import_processes = {}
|
||||
self.watched_folders = []
|
||||
self.mmc = mmc
|
||||
self.wm = watch_manager
|
||||
self.mask = pyinotify.ALL_EVENTS
|
||||
|
||||
|
||||
while not self.init_rabbit_mq():
|
||||
|
@ -69,7 +71,7 @@ class AirtimeNotifier(Notifier):
|
|||
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
||||
self.walk_newly_watched_directory(m['directory'])
|
||||
|
||||
self.mmc.watch_directory(m['directory'])
|
||||
self.watch_directory(m['directory'])
|
||||
|
||||
elif m['event_type'] == "remove_watch":
|
||||
watched_directory = m['directory'].encode('utf-8')
|
||||
|
@ -102,7 +104,7 @@ class AirtimeNotifier(Notifier):
|
|||
self.mmc.ensure_is_dir(self.config.imported_directory)
|
||||
self.mmc.ensure_is_dir(self.config.organize_directory)
|
||||
|
||||
self.mmc.watch_directory(new_storage_directory)
|
||||
self.watch_directory(new_storage_directory)
|
||||
elif m['event_type'] == "file_delete":
|
||||
self.logger.info("Deleting file: %s ", m['filepath'])
|
||||
mm = self.proc_fun()
|
||||
|
@ -158,6 +160,9 @@ class AirtimeNotifier(Notifier):
|
|||
elif (mode == self.config.MODE_DELETE):
|
||||
self.api_client.update_media_metadata(md, mode)
|
||||
|
||||
#define which directories the pyinotify WatchManager should watch.
|
||||
def watch_directory(self, directory):
|
||||
return self.wm.add_watch(directory, self.mask, rec=True, auto_add=True)
|
||||
|
||||
def walk_newly_watched_directory(self, directory):
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ import grp
|
|||
import pwd
|
||||
import logging
|
||||
|
||||
import pyinotify
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
from airtimemetadata import AirtimeMetadata
|
||||
|
||||
|
@ -12,18 +10,11 @@ class MediaMonitorCommon:
|
|||
|
||||
timestamp_file = "/var/tmp/airtime/last_index"
|
||||
|
||||
def __init__(self, airtime_config, watch_manager):
|
||||
def __init__(self, airtime_config):
|
||||
self.supported_file_formats = ['mp3', 'ogg']
|
||||
self.mask = pyinotify.ALL_EVENTS
|
||||
self.logger = logging.getLogger()
|
||||
self.config = airtime_config
|
||||
self.md_manager = AirtimeMetadata()
|
||||
self.wm = watch_manager
|
||||
|
||||
|
||||
#define which directories the pyinotify WatchManager should watch.
|
||||
def watch_directory(self, directory):
|
||||
return self.wm.add_watch(directory, self.mask, rec=True, auto_add=True)
|
||||
|
||||
def is_parent_directory(self, filepath, directory):
|
||||
filepath = os.path.normpath(filepath)
|
||||
|
@ -95,7 +86,6 @@ class MediaMonitorCommon:
|
|||
omask = os.umask(0)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory, 02777)
|
||||
#self.watch_directory(directory)
|
||||
elif not os.path.isdir(directory):
|
||||
#path exists but it is a file not a directory!
|
||||
self.logger.error("path %s exists, but it is not a directory!!!")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue