From 75e56034e48e61d862d0d69ab73c7d4fe1571802 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 14 Jul 2011 12:05:43 -0400 Subject: [PATCH] CC-2279: Upgrade script for converting stor directory to new format -refactoring... --- python_apps/media-monitor/MediaMonitor.py | 4 ++-- .../airtimefilemonitor/airtimenotifier.py | 9 +++++++-- .../airtimefilemonitor/mediamonitorcommon.py | 12 +----------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/python_apps/media-monitor/MediaMonitor.py b/python_apps/media-monitor/MediaMonitor.py index 1408bd009..6198bfe39 100644 --- a/python_apps/media-monitor/MediaMonitor.py +++ b/python_apps/media-monitor/MediaMonitor.py @@ -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]) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index 7f10be94b..4d18b86ca 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -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): diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index b6bd61585..c65508689 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -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!!!")