From 4caba5bdeabb00441c162bc602d0bb904721a5e5 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 9 May 2012 00:02:02 -0400 Subject: [PATCH] CC-3789: Need to place rejected files into /problem_files directory -done --- .../airtimemediamonitorbootstrap.py | 9 ++++++--- .../airtimefilemonitor/airtimeprocessevent.py | 3 +++ .../airtimefilemonitor/workerprocess.py | 6 ++++++ python_apps/media-monitor/media_monitor.py | 16 +++++++++++----- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py b/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py index 02c78a582..5d738528c 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py @@ -15,12 +15,13 @@ class AirtimeMediaMonitorBootstrap(): pe -- reference to an instance of ProcessEvent api_clients -- reference of api_clients to communicate with airtime-server """ - def __init__(self, logger, pe, api_client, mmc, wm): + def __init__(self, logger, pe, api_client, mmc, wm, config): self.logger = logger self.pe = pe self.api_client = api_client self.mmc = mmc self.wm = wm + self.config = config # add /etc on watch list so we can detect mount self.mount_file = "/etc" self.curr_mtab_file = "/var/tmp/airtime/media-monitor/currMtab" @@ -91,7 +92,8 @@ class AirtimeMediaMonitorBootstrap(): all_files_set = set() for file_path in all_files: - if len(file_path.strip(" \n")) > 0: + file_path = file_path.strip(" \n") + if len(file_path) > 0 and self.config.problem_directory not in file_path: all_files_set.add(file_path[len(dir):]) # if dir doesn't exists, update db @@ -116,7 +118,8 @@ class AirtimeMediaMonitorBootstrap(): new_and_modified_files = set() for file_path in new_files: - if len(file_path.strip(" \n")) > 0: + file_path = file_path.strip(" \n") + if len(file_path) > 0 and self.config.problem_directory not in file_path: new_and_modified_files.add(file_path[len(dir):]) """ diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index fc7720692..b75b0eca2 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -235,6 +235,9 @@ class AirtimeProcessEvent(ProcessEvent): filename = self.mount_file_dir +"/mtab" if event.pathname in filename: self.handle_mount_change() + + if event.path in self.config.problem_directory: + return if not event.dir: if self.mmc.is_audio_file(event.name): diff --git a/python_apps/media-monitor/airtimefilemonitor/workerprocess.py b/python_apps/media-monitor/airtimefilemonitor/workerprocess.py index 5e8fddcb6..6201712a9 100644 --- a/python_apps/media-monitor/airtimefilemonitor/workerprocess.py +++ b/python_apps/media-monitor/airtimefilemonitor/workerprocess.py @@ -1,8 +1,13 @@ from mediaconfig import AirtimeMediaConfig import mediamonitorcommon import traceback +import os class MediaMonitorWorkerProcess: + + def __init__(self, config, mmc): + self.config = config + self.mmc = mmc #this function is run in its own process, and continuously #checks the queue for any new file events. @@ -17,6 +22,7 @@ class MediaMonitorWorkerProcess: notifier.update_airtime(event) else: notifier.logger.warn("Liquidsoap integrity check for file at %s failed. Not adding to media library.", filepath) + self.mmc.move_file(filepath, os.path.join(self.config.problem_directory, os.path.basename(filepath))) else: notifier.update_airtime(event) except Exception, e: diff --git a/python_apps/media-monitor/media_monitor.py b/python_apps/media-monitor/media_monitor.py index 7c39bba0a..e9b03d8e1 100644 --- a/python_apps/media-monitor/media_monitor.py +++ b/python_apps/media-monitor/media_monitor.py @@ -87,9 +87,15 @@ try: watched_dirs = apc.encode_to(response["watched_dirs"], 'utf-8') logger.info("Storage Directory is: %s", storage_directory) config.storage_directory = os.path.normpath(storage_directory) - config.imported_directory = os.path.normpath(storage_directory + '/imported') - config.organize_directory = os.path.normpath(storage_directory + '/organize') - config.recorded_directory = os.path.normpath(storage_directory + '/recorded') + config.imported_directory = os.path.normpath(os.path.join(storage_directory, 'imported')) + config.organize_directory = os.path.normpath(os.path.join(storage_directory, 'organize')) + config.recorded_directory = os.path.normpath(os.path.join(storage_directory, 'recorded')) + config.problem_directory = os.path.normpath(os.path.join(storage_directory, 'problem_files')) + + dirs = [config.imported_directory, config.organize_directory, config.recorded_directory, config.problem_directory] + for d in dirs: + if not os.path.exists(d): + os.makedirs(d, 02775) multi_queue = mpQueue() logger.info("Initializing event processor") @@ -98,14 +104,14 @@ try: mmc = MediaMonitorCommon(config, wm=wm) pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm, mmc=mmc, api_client=api_client) - bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc, wm) + bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc, wm, config) bootstrap.scan() notifier = AirtimeNotifier(wm, pe, read_freq=0, timeout=0, airtime_config=config, api_client=api_client, bootstrap=bootstrap, mmc=mmc) notifier.coalesce_events() #create 5 worker threads - wp = MediaMonitorWorkerProcess() + wp = MediaMonitorWorkerProcess(config, mmc) for i in range(5): threadName = "Thread #%d" % i t = Thread(target=wp.process_file_events, name=threadName, args=(multi_queue, notifier))